Python log.log() Examples
The following are 30
code examples of log.log().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
log
, or try the search function
.
Example #1
Source File: cleanup.py From foreman-yml with GNU General Public License v3.0 | 6 votes |
def process_cleanup_ptable(self): log.log(log.LOG_INFO, "Processing Cleanup of Partition Tables") for ptable in self.get_config_section('cleanup-partition-table'): try: self.validator.cleanup_ptable(ptable) except MultipleInvalid as e: log.log(log.LOG_WARN, "Cannot delete Partition Table '{0}': YAML validation Error: {1}".format(ptable['name'], e)) continue try: self.fm.ptables.show(ptable['name'])['id'] log.log(log.LOG_INFO, "Delete Partition Table '{0}'".format(ptable['name'])) self.fm.ptables.destroy( ptable['name'] ) except: log.log(log.LOG_WARN, "Partition Table '{0}' already absent.".format(ptable['name']))
Example #2
Source File: PTT.py From PyPtt with GNU Lesser General Public License v3.0 | 6 votes |
def _get_user(self, user_id) -> data_type.UserInfo: check_value.check(self.config, str, 'UserID', user_id) if len(user_id) < 2: raise ValueError(log.merge( self.config, [ 'UserID', i18n.ErrorParameter, user_id ])) try: from . import _api_get_user except ModuleNotFoundError: import _api_get_user return _api_get_user.get_user(self, user_id)
Example #3
Source File: importer.py From foreman-yml with GNU General Public License v3.0 | 6 votes |
def process_config_model(self): log.log(log.LOG_INFO, "Processing Models") for model in self.get_config_section('model'): try: self.validator.model(model) except MultipleInvalid as e: log.log(log.LOG_WARN, "Cannot create Model '{0}': YAML validation Error: {1}".format(model['name'], e)) continue try: model_id = self.fm.models.show(model['name'])['id'] log.log(log.LOG_DEBUG, "Model '{0}' (id={1}) already present.".format(model['name'], model_id)) except: log.log(log.LOG_INFO, "Create Model '{0}'".format(model['name'])) model_tpl = { 'name': model['name'], 'info': model['info'], 'vendor_class': model['vendor-class'], 'hardware_model': model['hardware-model'] } self.fm.models.create( model = model_tpl )
Example #4
Source File: importer.py From foreman-yml with GNU General Public License v3.0 | 6 votes |
def process_config_medium(self): log.log(log.LOG_INFO, "Processing Media") medialist = self.fm.media.index(per_page=99999)['results'] for medium in self.get_config_section('medium'): try: self.validator.medium(medium) except MultipleInvalid as e: log.log(log.LOG_WARN, "Cannot create Media '{0}': YAML validation Error: {1}".format(medium['name'], e)) continue medium_id = False # fm.media.show(name) does not work, we need to iterate over fm.media.index() for mediac in medialist: if (mediac['name'] == medium['name']): medium_id = mediac['id'] log.log(log.LOG_DEBUG, "Medium '{0}' (id={1}) already present.".format(medium['name'], medium_id)) if not medium_id: log.log(log.LOG_INFO, "Create Medium '{0}'".format(medium['name'])) medium_tpl = { 'name': medium['name'], 'path': medium['path'], 'os_family': medium['os-family'] } self.fm.media.create( medium = medium_tpl )
Example #5
Source File: importer.py From foreman-yml with GNU General Public License v3.0 | 6 votes |
def process_config_settings(self): log.log(log.LOG_INFO, "Processing Foreman Settings") for setting in self.get_config_section('setting'): try: self.validator.setting(setting) except MultipleInvalid as e: log.log(log.LOG_WARN, "Cannot update Setting '{0}': YAML validation Error: {1}".format(setting['name'], e)) continue setting_id = False try: setting_id = self.fm.settings.show(setting['name'])['id'] except: log.log(log.LOG_WARN, "Cannot get ID of Setting '{0}', skipping".format(setting['name'])) setting_tpl = { 'value': setting['value'] } if setting_id: log.log(log.LOG_INFO, "Update Setting '{0}'".format(setting['name'])) self.fm.settings.update(setting_tpl, setting_id)
Example #6
Source File: importer.py From foreman-yml with GNU General Public License v3.0 | 6 votes |
def process_config_smartproxy(self): log.log(log.LOG_INFO, "Processing Smart Proxies") for proxy in self.get_config_section('smart-proxy'): try: proxy_id = self.fm.smart_proxies.show(proxy['name'])['id'] log.log(log.LOG_DEBUG, "Proxy '{0}' (id={1}) already present.".format(proxy['name'], proxy_id)) except: log.log(log.LOG_INFO, "Create Smart Proxy '{0}'".format(proxy['name'])) proxy_tpl = { 'name': proxy['name'], 'url': proxy['url'], } try: self.fm.smart_proxies.create( smart_proxy = proxy_tpl ) except: log.log(log.LOG_WARN, "Cannot create Smart Proxy '{0}'. Is the Proxy online? ".format(proxy['name']))
Example #7
Source File: importer.py From foreman-yml with GNU General Public License v3.0 | 6 votes |
def process_config_ptable(self): log.log(log.LOG_INFO, "Processing Partition Tables") for ptable in self.get_config_section('partition-table'): try: self.validator.ptable(ptable) except MultipleInvalid as e: log.log(log.LOG_WARN, "Cannot create Partition Table '{0}': YAML validation Error: {1}".format(ptable['name'], e)) continue try: ptable_id = self.fm.ptables.show(ptable['name'])['id'] log.log(log.LOG_DEBUG, "Partition Table '{0}' (id={1}) already present.".format(ptable['name'], ptable_id)) except: log.log(log.LOG_INFO, "Create Partition Table '{0}'".format(ptable['name'])) ptable_tpl = { 'name': ptable['name'], 'layout': ptable['layout'], 'snippet': ptable['snippet'], 'audit_comment': ptable['audit-comment'], 'locked': ptable['locked'], 'os_family': ptable['os-family'] } self.fm.ptables.create( ptable = ptable_tpl )
Example #8
Source File: cleanup.py From foreman-yml with GNU General Public License v3.0 | 6 votes |
def process_cleanup_medium(self): log.log(log.LOG_INFO, "Processing Cleanup of Media") medialist = self.fm.media.index(per_page=99999)['results'] for medium in self.get_config_section('cleanup-medium'): try: self.validator.cleanup_medium(medium) except MultipleInvalid as e: log.log(log.LOG_WARN, "Cannot delete Medium '{0}': YAML validation Error: {1}".format(medium['name'], e)) continue medium_deleted = False # fm.media.show(name) does not work, we need to iterate over fm.media.index() for mediac in medialist: if (mediac['name'] == medium['name']): medium_deleted = True log.log(log.LOG_INFO, "Delete Medium '{0}'".format(medium['name'])) self.fm.media.destroy( medium['name'] ) continue if not medium_deleted: log.log(log.LOG_WARN, "Medium '{0}' already absent.".format(medium['name']))
Example #9
Source File: cleanup.py From foreman-yml with GNU General Public License v3.0 | 6 votes |
def process_cleanup_arch(self): log.log(log.LOG_INFO, "Processing Cleanup of Architectures") for arch in self.get_config_section('cleanup-architecture'): try: self.validator.cleanup_arch(arch) except MultipleInvalid as e: log.log(log.LOG_WARN, "Cannot delete Architecture '{0}': YAML validation Error: {1}".format(arch['name'], e)) continue try: self.fm.architectures.show(arch['name'])['id'] log.log(log.LOG_INFO, "Delete Architecture '{0}'".format(arch['name'])) self.fm.architectures.destroy( arch['name'] ) except: log.log(log.LOG_WARN, "Architecture '{0}' already absent.".format(arch['name']))
Example #10
Source File: importer.py From foreman-yml with GNU General Public License v3.0 | 6 votes |
def process_auth_sources_ldap(self): log.log(log.LOG_INFO, "Processing LDAP auth sources") for auth in self.get_config_section('auth-source-ldap'): # validate yaml try: self.validator.auth_source_ldaps(auth) except MultipleInvalid as e: log.log(log.LOG_WARN, "Cannot create LDAP source '{0}': YAML validation Error: {1}".format(auth['name'], e)) continue try: as_id = self.fm.auth_source_ldaps.show(auth['name'])['id'] log.log(log.LOG_WARN, "LDAP source {0} allready exists".format(auth['name'])) continue except TypeError: pass ldap_auth_obj = self.dict_underscore(auth) try: self.fm.auth_source_ldaps.create( auth_source_ldap=ldap_auth_obj ) except: log.log(log.LOG_ERROR, "Something went wrong creating LDAP source {0}".format(auth['name']))
Example #11
Source File: PTT.py From PyPtt with GNU Lesser General Public License v3.0 | 6 votes |
def _one_thread(self) -> None: current_thread_id = threading.get_ident() if current_thread_id == self._ThreadID: return log.show_value( self.config, log.level.DEBUG, 'ThreadID', self._ThreadID ) log.show_value( self.config, log.level.DEBUG, 'Current thread id', current_thread_id ) raise exceptions.MultiThreadOperated()
Example #12
Source File: process.py From happymac with MIT License | 5 votes |
def cpu(pid=-1): if pid == 0: return 0 if pid in cpu_cache: return cpu_cache[pid] try: total_time = get_total_time(pid) now = time.time() if not pid in total_times: total_times[pid] = (now, total_time) last_when, last_time = total_times[pid] result = (total_time - last_time) / (now - last_when + 0.00001) total_times[pid] = (now, total_time) cpu_cache[pid] = result return result except psutil.AccessDenied as e: cmd = ps_output = "???" try: cmd = "ps -p %s -o %%cpu | grep -v CPU" % pid ps_output = os.popen(cmd).read() or "0" return float(ps_output) / 100 except: error.error("Cannot parse '%s' => '%s' into a float in process.cpu" % (cmd, ps_output)) return 0 except (psutil.NoSuchProcess, psutil.ZombieProcess) as e: return 0 except Exception as e: log.log("Unhandled Error in process.cpu", e) return 0
Example #13
Source File: repair.py From MusicNow with MIT License | 5 votes |
def add_albumart(albumart, song_title): ''' Adds the album art to the song ''' try: img = urlopen(albumart) # Gets album art from url except Exception: log.log_error("* Could not add album art", indented=True) return None audio = EasyMP3(song_title, ID3=ID3) try: audio.add_tags() except _util.error: pass audio.tags.add( APIC( encoding=3, # UTF-8 mime='image/png', type=3, # 3 is for album art desc='Cover', data=img.read() # Reads and adds album art ) ) audio.save() log.log("> Added album art")
Example #14
Source File: main.py From happymac with MIT License | 5 votes |
def handle_action(self, menuItem=None): return if menuItem: log.log("Handled menu item %s" % menuItem) self.update(force_update=True)
Example #15
Source File: main.py From happymac with MIT License | 5 votes |
def quit(self, menuItem=None): try: log.log("Quit - Ran for %d seconds" % int(time.time() - self.start)) suspender.exit() if self.quit_callback: self.quit_callback() except: error.error("Could not quit") finally: rumps.quit_application()
Example #16
Source File: main.py From happymac with MIT License | 5 votes |
def __init__(self, quit_callback=None): super(HappyMacStatusBarApp, self).__init__("", quit_button=None) self.quit_button = None self.quit_callback = quit_callback self.menu = [ ] self.loading() self.menu._menu.setDelegate_(self) self.start = time.time() self.need_menu = False utils.set_menu_open(False) utils.Timer(1.0, self.update).start() log.log("Started HappyMac %s" % version_manager.last_version())
Example #17
Source File: preferences.py From happymac with MIT License | 5 votes |
def set(key, value): preferences[key] = value with open(get_preferences_path(), "wb") as file: pickle.dump(preferences, file, 2) log.log("Set preference %s to %s" % (key, repr(value)))
Example #18
Source File: ow.py From Off-White-Monitor with MIT License | 5 votes |
def read_from_txt(path): # Initialize variables raw_lines = [] lines = [] # Load data from the txt file try: f = open(path, "r") raw_lines = f.readlines() f.close() # Raise an error if the file couldn't be found except: log('e', "Couldn't locate: " + path) raise FileNotFound() if(len(raw_lines) == 0): log('w', "No data found in: " + path) raise NoDataLoaded() # Parse the data for line in raw_lines: lines.append(line.strip("\n")) # Return the data return lines
Example #19
Source File: version_manager.py From happymac with MIT License | 5 votes |
def save_contents(latest): version = latest["version"] path = os.path.join(downloads_dir, '%s' % version) if os.path.exists(path): log.log("Download: version %s already installed" % version) else: with open(path, "wb") as file: pickle.dump(latest, file, 2) log.log("Download: extracted version %s to %s" % (version, path)) rumps.notification("HappyMac Update", "A new version was downloaded", "Running %s" % version, sound=False) log.log("Download: available versions: %s" % get_versions())
Example #20
Source File: error.py From happymac with MIT License | 5 votes |
def error(message): stack = "HappyMac Execution Stack at Error Time:\n%s\n" % "".join(traceback.format_stack()[:-1]) exception = "HappyMac Exception:\n %s\n" % traceback.format_exc() error = "HappyMac Error:\n %s\n%s%s%s%s%s\n%s%sHappyMac Error:\n %s\n" % ( message, get_system_info(), get_home_dir_info(), get_preferences(), get_versions(), log.get_log(), stack, exception, message ) path = get_error_file_path() try: with open(path, "w") as output: output.write("HappyMac Error Report - %s\n\n" % datetime.datetime.utcnow()) os.system("system_profiler SPHardwareDataType >> %s" % path) with open(path, "a") as output: output.write(error) with open(path) as input: print(input.read()) except: pass log.log(error) rumps.notification("HappyMac", "Error: %s. For details see:" % message, path, sound=True)
Example #21
Source File: license.py From happymac with MIT License | 5 votes |
def get_license(): try: return preferences.get("license") or download_license() except: log.log("Cannot find license")
Example #22
Source File: license.py From happymac with MIT License | 5 votes |
def download_license(): url = "https://www.happymac.app/_functions/agree/?token=%s" % uuid.get_hardware_uuid() log.log("Getting license from: %s" % url) license = requests.get(url).content key = json.loads(license)["key"] log.log("Received license key: %s" % key) preferences.set("license", key)
Example #23
Source File: test_log.py From happymac with MIT License | 5 votes |
def test_get_log_path(self, mock_exists, mock_join): mock_exists.return_value = True mock_join.return_value = '/Users/chris/HappyMacApp/downloads/v00001' self.assertEqual( log.get_log_path(), '/Users/chris/HappyMacApp/happymac_log.txt' )
Example #24
Source File: test_log.py From happymac with MIT License | 5 votes |
def test_log(self): self.assertEqual( log.log(message='Google process 44784 ()',error=None), None )
Example #25
Source File: version_manager.py From happymac with MIT License | 5 votes |
def load_version(version, quit_callback=None): try: mod = find_version(version) except Exception as e: log.log("Could not find version %s due to %s" % (version, e)) mod = find_version(last_version()) if mod: main_mod = getattr(mod, "main") log.log("Calling run on %s" % main_mod) main_mod.run(quit_callback) else: log.log("Cannot load version %s" % version)
Example #26
Source File: version_manager.py From happymac with MIT License | 5 votes |
def find_version(version): log.log("Find version %s" % version) return getattr(versions, version, find_downloaded_version(version))
Example #27
Source File: version_manager.py From happymac with MIT License | 5 votes |
def find_downloaded_version(version): version_path = os.path.join(downloads_dir, '%s' % version) if not os.path.exists(version_path): log.log("Downloads: Could not find version %s in %s" % (version, version_path)) return None try: with open(version_path, "rb") as file: package = pickle.load(file) mod = load_module_from_source(version, package["contents"]) mod.main = mod return mod except Exception as e: error.error("Download: Problem with version %s: %s" % (version, e))
Example #28
Source File: version_manager.py From happymac with MIT License | 5 votes |
def download_latest(): try: hardware_uuid = uuid.get_hardware_uuid() latest_url = 'https://happymac.app/_functions/latest?version=%s&uuid=%s' % (last_version(), hardware_uuid) log.log("Download: getting the latest version at %s" % latest_url) latest = json.loads(requests.get(latest_url).content) latest['contents'] = latest['contents'].replace("@@@", "\n") save_contents(latest) except: error.error("Download: cannot get latest version")
Example #29
Source File: base.py From foreman-yml with GNU General Public License v3.0 | 5 votes |
def __init__(self, config, loglevel=logging.INFO): logging.basicConfig(level=loglevel) log.LOGLEVEL = loglevel self.config = config['foreman'] self.loglevel = loglevel self.validator = Validator()
Example #30
Source File: repair.py From MusicNow with MIT License | 5 votes |
def get_details_spotify(song_name): ''' Tries finding metadata through Spotify ''' song_name = improvename.songname(song_name) spotify = spotipy.Spotify() results = spotify.search(song_name, limit=1) # Find top result log.log_indented('* Finding metadata from Spotify.') try: album = (results['tracks']['items'][0]['album'] ['name']) # Parse json dictionary artist = (results['tracks']['items'][0]['album']['artists'][0]['name']) song_title = (results['tracks']['items'][0]['name']) try: log_indented("* Finding lyrics from Genius.com") lyrics = get_lyrics_genius(song_title) except: log_error("* Could not find lyrics from Genius.com, trying something else") lyrics = get_lyrics_letssingit(song_title) match_bool, score = matching_details(song_name, song_title, artist) if match_bool: return artist, album, song_title, lyrics, match_bool, score else: return None except IndexError: log.log_error( '* Could not find metadata from spotify, trying something else.', indented=True) return None