python类Log()的实例源码

importer.py 文件源码 项目:foreman-yml 作者: adfinis-sygroup 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def process_template_combination_attribute(self):
        ptlist = self.fm.provisioning_templates.index(per_page=99999)['results']
        envlist = self.fm.environments.index(per_page=99999)['results']
        for pt in self.get_config_section('provisioning-template'):

            msg = ""

            pt_id = False
            for ptc in ptlist:
                if (ptc['name'] == pt['name']):
                    pt_id = ptc['id']
            if not pt_id:
                log.log(log.LOG_WARN, "Cannot resolve Provisioning template '{0}' ".format(pt['name']) )
                continue

            if 'template_combination_attribute' not in pt or pt['template-combination-attribute'] is None:
                continue
            else:
                linklist = pt['template-combination-attribute']

            for item in linklist:
                env_id = False
                hg_id = False
                for envc in envlist:
                    try:
                        if (item['enviroment'] == envc['name']):
                            env_id = envc['id']
                    except KeyError:
                        env_id = False
                try:
                    hg_id = self.fm.hostgroups.show(item['hostgroup'])['id']
                except:
                    hg_id = False

                if hg_id is not False or env_id is not False:

                    pt_api_arr = {
                        "template_combinations_attributes": [ {} ]
                    }

                    if hg_id is not False:
                        pt_api_arr["template_combinations_attributes"][0]["hostgroup_id"] = hg_id

                    if env_id is not False:
                        pt_api_arr["template_combinations_attributes"][0]["environment_id"] = env_id

                    try:
                        self.fm.provisioning_templates.update(pt_api_arr, pt_id)
                    except ForemanException as e:
                        msg = self.get_api_error_msg(e)
                        log.log(log.LOG_WARN, "Cannot link provisioning template '{0}' api says: '{1}'".format(pt['name'], msg) )
                        continue
                else:
                    log.log(log.LOG_WARN, "Cannot link provisioning template '{0}', at least hostgroup needs to be valid".format(pt['name'], msg) )
repair.py 文件源码 项目:MusicNow 作者: kalbhor 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_details_letssingit(song_name):
    '''
    Gets the song details if song details not found through spotify
    '''

    song_name = improvename.songname(song_name)

    url = "http://search.letssingit.com/cgi-exe/am.cgi?a=search&artist_id=&l=archive&s=" + \
        quote(song_name.encode('utf-8'))
    html = urlopen(url).read()
    soup = BeautifulSoup(html, "html.parser")
    link = soup.find('a', {'class': 'high_profile'})
    try:
        link = link.get('href')
        link = urlopen(link).read()

        soup = BeautifulSoup(link, "html.parser")

        album_div = soup.find('div', {'id': 'albums'})
        title_div = soup.find('div', {'id': 'content_artist'}).find('h1')

        try:
            lyrics = soup.find('div', {'id': 'lyrics'}).text
            lyrics = lyrics[3:]
        except AttributeError:
            lyrics = ""
            log.log_error("* Couldn't find lyrics", indented=True)

        try:
            song_title = title_div.contents[0]
            song_title = song_title[1:-8]
        except AttributeError:
            log.log_error("* Couldn't reset song title", indented=True)
            song_title = song_name

        try:
            artist = title_div.contents[1].getText()
        except AttributeError:
            log.log_error("* Couldn't find artist name", indented=True)
            artist = "Unknown"

        try:
            album = album_div.find('a').contents[0]
            album = album[:-7]
        except AttributeError:
            log.log_error("* Couldn't find the album name", indented=True)
            album = artist

    except AttributeError:
        log.log_error("* Couldn't find song details", indented=True)

        album = song_name
        song_title = song_name
        artist = "Unknown"
        lyrics = ""

    match_bool, score = matching_details(song_name, song_title, artist)

    return artist, album, song_title, lyrics, match_bool, score
repair.py 文件源码 项目:MusicNow 作者: kalbhor 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def fix_music(file_name):
    '''
    Searches for '.mp3' files in directory (optionally recursive)
    and checks whether they already contain album art and album name tags or not.
    '''

    setup()

    if not Py3:
        file_name = file_name.encode('utf-8')

    tags = File(file_name)

    log.log(file_name)
    log.log('> Adding metadata')

    try:
        artist, album, song_name, lyrics, match_bool, score = get_details_spotify(
            file_name)  # Try finding details through spotify

    except Exception:
        artist, album, song_name, lyrics, match_bool, score = get_details_letssingit(
            file_name)  # Use bad scraping method as last resort

    try:
        log.log_indented('* Trying to extract album art from Google.com')
        albumart = albumsearch.img_search_google(artist+' '+album)
    except Exception:
        log.log_indented('* Trying to extract album art from Bing.com')
        albumart = albumsearch.img_search_bing(artist+' '+album)

    if match_bool:
        add_albumart(albumart, file_name)
        add_details(file_name, song_name, artist, album, lyrics)

        try:
            rename(file_name, artist+' - '+song_name+'.mp3')
        except Exception:
            log.log_error("Couldn't rename file")
            pass
    else:
        log.log_error(
            "* Couldn't find appropriate details of your song", indented=True)

    log.log("Match score: %s/10.0" % round(score * 10, 1))
    log.log(LOG_LINE_SEPERATOR)
    log.log_success()
fuzzbunch.py 文件源码 项目:isf 作者: w3h 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self, 
                 configfile,
                 base_dir, 
                 log_dir, 
                 stdin=None,
                 stdout=None,
                 stderr=None):
        """@brief   Initialize the Fuzzbunch object

        @param      configfile      The main Fuzzbunch configuration file (an XML file)
        @param      base_dir        
        @param      log_dir         Location for Fuzzbunch log files
        @param      stdin           
        @param      stdout          
        @param      stderr          
        """

        # Initialize the command interpreter, which creates a CmdCtx
        self.configvars = {}                    # Stores global config info (not setg globals)
        self.readconfig(configfile)             # Read in variables set for Fuzzbunch

        # Fix bug #2910 - Color breaks in some terminals that don't support ansi encoding.  Added
        # option to disable color
        enablecolor = eval(self.configvars['globals']['Color'])
        FbCmd.__init__(self, stdin=stdin, stdout=stdout, stderr=stderr, enablecolor=enablecolor )

        # Set the info function to Fuzzbunch's print_info function
        self.defaultcontext.print_info = self.print_info
        self.preconfig()

        self.fbglobalvars   = util.iDict()      # Our Fuzzbunch global variables
        self.pluginmanagers = util.iDict()      # A list of PluginManagers, each
                                                # of which contains a list of Plugins.

        # Create our Session manager, which has a list of the plugins we've run
        self.session  = session.Session(self.name)
        self.session.set_dirs(base_dir, log_dir)

        # Set the logdir from the Fuzzbunch.xml file, which will be overridden
        # later when retarget is executed
        self.default_logdir = os.path.normpath(log_dir)
        self.set_logdir(log_dir)

        # Create a Redirection object to keep track of the status of redirection, and to
        # perform transforms on the parameters prior to and after executing plugins
        self.redirection = redirection.RedirectionManager(self.io)

        self.fontdir = os.path.join(base_dir, "fonts")
        self.storage = os.path.join(base_dir, "storage")
        self.setbanner()
        self.postconfig()
        self.pwnies = False

        self.conv_tools = util.iDict([('MultiLine', self.toolpaste_ep),
                                 ('MD5',       self.toolpaste_md5),
                                 ('SHA1',      self.toolpaste_sha1),
                                 ('Base64',    self.toolpaste_base64),
                               ])

        self.log = log(self.name, self.version, dict(debugging=True, enabled=True, verbose=False))
fuzzbunch.py 文件源码 项目:shadowbroker-auto 作者: wrfly 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def __init__(self, 
                 configfile,
                 base_dir, 
                 log_dir, 
                 stdin=None,
                 stdout=None,
                 stderr=None):
        """@brief   Initialize the Fuzzbunch object

        @param      configfile      The main Fuzzbunch configuration file (an XML file)
        @param      base_dir        
        @param      log_dir         Location for Fuzzbunch log files
        @param      stdin           
        @param      stdout          
        @param      stderr          
        """

        # Initialize the command interpreter, which creates a CmdCtx
        self.configvars = {}                    # Stores global config info (not setg globals)
        self.readconfig(configfile)             # Read in variables set for Fuzzbunch

        # Fix bug #2910 - Color breaks in some terminals that don't support ansi encoding.  Added
        # option to disable color
        enablecolor = eval(self.configvars['globals']['Color'])
        FbCmd.__init__(self, stdin=stdin, stdout=stdout, stderr=stderr, enablecolor=enablecolor )

        # Set the info function to Fuzzbunch's print_info function
        self.defaultcontext.print_info = self.print_info
        self.preconfig()

        self.fbglobalvars   = util.iDict()      # Our Fuzzbunch global variables
        self.pluginmanagers = util.iDict()      # A list of PluginManagers, each
                                                # of which contains a list of Plugins.

        # Create our Session manager, which has a list of the plugins we've run
        self.session  = session.Session(self.name)
        self.session.set_dirs(base_dir, log_dir)

        # Set the logdir from the Fuzzbunch.xml file, which will be overridden
        # later when retarget is executed
        self.default_logdir = os.path.normpath(log_dir)
        self.set_logdir(log_dir)

        # Create a Redirection object to keep track of the status of redirection, and to
        # perform transforms on the parameters prior to and after executing plugins
        self.redirection = redirection.RedirectionManager(self.io)

        self.fontdir = os.path.join(base_dir, "fonts")
        self.storage = os.path.join(base_dir, "storage")
        self.setbanner()
        self.postconfig()
        self.pwnies = False

        self.conv_tools = util.iDict([('MultiLine', self.toolpaste_ep),
                                 ('MD5',       self.toolpaste_md5),
                                 ('SHA1',      self.toolpaste_sha1),
                                 ('Base64',    self.toolpaste_base64),
                               ])

        self.log = log(self.name, self.version, dict(debugging=True, enabled=True, verbose=False))


问题


面经


文章

微信
公众号

扫码关注公众号