當前位置: 首頁>>代碼示例>>Python>>正文


Python logger.Logger類代碼示例

本文整理匯總了Python中zanatalib.logger.Logger的典型用法代碼示例。如果您正苦於以下問題:Python Logger類的具體用法?Python Logger怎麽用?Python Logger使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Logger類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

class CSVConverter:
    def __init__(self):
        self.log = Logger()
    
    def read_data(self, csv_file):
        data = []
        try:
            reader = csv.reader(open(csv_file, 'rb'))
            header = reader.next()
            size = len(header)
            for line in reader:
                items = {}
                entry_size = len(line)                
                for x in range(size):  
                    if x < entry_size:  
                        item = {header[x]: line[x]}
                    else:
                        item = {header[x]: ""}
                    items.update(item)
            
                data.append(items)
        except IOError:
            self.log.error("Can not find csv file: %s"%csv_file)
        
        return data

    def convert_to_json(self, filepath, locale_map, comments_header):
        data = self.read_data(filepath)
        srclocales = []
        srclocales.append('en-US')
        entries = []
        targetlocales = []
        for item in data:
            comments = []
            terms = []

            for header in comments_header:
                if item.has_key(header):                
                    comments.append(item.pop(header))
            
            for key in item.keys():
                if key == 'en':
                    term = {'locale':'en-US', 'content':item[key], 'comments':comments}
                else:
                    if key in locale_map:
                        locale = locale_map[key]
                    else:
                        locale = key
                    term = {'locale':locale, 'content':item[key], 'comments':[]}
                    if key not in targetlocales:
                        targetlocales.append(key)
                terms.append(term)

            entry = {'srcLang': 'en-US', 'glossaryTerms': terms, 'sourcereference': ''}
            entries.append(entry)

        glossary = {'sourceLocales':srclocales, 'glossaryEntries':entries, 'targetLocales':targetlocales}

        return json.dumps(glossary)
開發者ID:candlepin,項目名稱:zanata-python-client,代碼行數:59,代碼來源:csvconverter.py

示例2: read_project_config

    def read_project_config(self, filename):
        log = Logger()

        if os.path.getsize(filename) == 0:
            log.info('The project config file is empty, need command line options')
            return project_config

        xmldoc = minidom.parse(filename)

        # Read the project url
        if xmldoc.getElementsByTagName("url"):
            node = xmldoc.getElementsByTagName("url")[0]
            project_config['url'] = getCombinedTextChildren(node)

        # Read the project id
        if xmldoc.getElementsByTagName("project"):
            node = xmldoc.getElementsByTagName("project")[0]
            project_config['project_id'] = getCombinedTextChildren(node)

        # Read the project-version
        if xmldoc.getElementsByTagName("project-version"):
            node = xmldoc.getElementsByTagName("project-version")[0]
            project_config['project_version'] = getCombinedTextChildren(node)

        # Read the project-type
        if xmldoc.getElementsByTagName("project-type"):
            node = xmldoc.getElementsByTagName("project-type")[0]
            project_config['project_type'] = getCombinedTextChildren(node)

        # Read the locale map
        if xmldoc.getElementsByTagName("locales"):
            locales = xmldoc.getElementsByTagName("locales")[0]
            localelist = locales.getElementsByTagName("locale")
            project_config['locale_map'] = {}

            for locale in localelist:
                for node in locale.childNodes:
                    if node.nodeType == node.TEXT_NODE:
                        if locale.getAttribute("map-from"):
                            locale_map = {str(locale.getAttribute("map-from")): str(node.data)}
                        else:
                            locale_map = {str(node.data): str(node.data)}
                        project_config['locale_map'].update(locale_map)

        # Read <src-dir> and <trans-dir>
        if xmldoc.getElementsByTagName("src-dir"):
            node = xmldoc.getElementsByTagName("src-dir")[0]
            project_config['srcdir'] = getCombinedTextChildren(node)
        if xmldoc.getElementsByTagName("trans-dir"):
            node = xmldoc.getElementsByTagName("trans-dir")[0]
            project_config['transdir'] = getCombinedTextChildren(node)

        return dict((node, value.strip() if isinstance(value, str) else value)
                    for node, value in project_config.items() if value)
開發者ID:pkulev,項目名稱:zanata-python-client,代碼行數:54,代碼來源:parseconfig.py

示例3: __init__

class ZanataCommand:
    def __init__(self):
        self.log = Logger()

    ##############################################
    ##
    ## Commands for interaction with zanata server 
    ##
    ############################################## 
    def check_project(self, zanataclient, command_options, project_config):
        project_id = ''
        iteration_id = ''
        if command_options.has_key('project_id'):
            project_id =  command_options['project_id'][0]['value'] 
        else:
            if project_config.has_key('project_id'):
                project_id = project_config['project_id']
        
        if command_options.has_key('project_version'):
            iteration_id = command_options['project_version'][0]['value'] 
        else:
            if project_config.has_key('project_version'):
                iteration_id = project_config['project_version']
        
        if not project_id:
            self.log.error("Please specify a valid project id in zanata.xml or with '--project-id' option")
            sys.exit(1)
        
        if not iteration_id:
            self.log.error("Please specify a valid version id in zanata.xml or with '--project-version' option")
            sys.exit(1)
        
        self.log.info("Project: %s"%project_id)
        self.log.info("Version: %s"%iteration_id)

        try:
            zanataclient.projects.get(project_id)
        except NoSuchProjectException, e:
            self.log.error(e.msg)
            sys.exit(1)
   
        try:
            zanataclient.projects.iterations.get(project_id, iteration_id)
            return project_id, iteration_id
        except NoSuchProjectException, e:
            self.log.error(e.msg)
            sys.exit(1)
開發者ID:seanf,項目名稱:zanata-python-client,代碼行數:47,代碼來源:zanatacmd.py

示例4: read_project_config

    def read_project_config(self, filename):
        log = Logger()

        if os.path.getsize(filename) == 0:
            log.info('The project config file is empty, need command line options')
            return project_config

        xmldoc = minidom.parse(filename)

        # Read the project url
        if xmldoc.getElementsByTagName("url"):
            node = xmldoc.getElementsByTagName("url")[0]
            project_config['project_url'] = getCombinedTextChildren(node)

        # Read the project id
        if xmldoc.getElementsByTagName("project"):
            node = xmldoc.getElementsByTagName("project")[0]
            project_config['project_id'] = getCombinedTextChildren(node)

        # Read the project-version
        if xmldoc.getElementsByTagName("project-version"):
            node = xmldoc.getElementsByTagName("project-version")[0]
            project_config['project_version'] = getCombinedTextChildren(node)

        # Read the project-type
        if xmldoc.getElementsByTagName("project-type"):
            node = xmldoc.getElementsByTagName("project-type")[0]
            project_config['project_type'] = getCombinedTextChildren(node)

        # Read the locale map
        if xmldoc.getElementsByTagName("locales"):
            locales = xmldoc.getElementsByTagName("locales")[0]
            localelist = locales.getElementsByTagName("locale")

            for locale in localelist:
                for node in locale.childNodes:
                    if node.nodeType == node.TEXT_NODE:
                        if locale.getAttribute("map-from"):
                            locale_map = {str(locale.getAttribute("map-from")): str(node.data)}
                        else:
                            locale_map = {str(node.data): str(node.data)}
                        project_config['locale_map'].update(locale_map)

        return project_config
開發者ID:lcabral37,項目名稱:zanata-python-client,代碼行數:44,代碼來源:parseconfig.py

示例5: Logger

from zanatalib.client import ZanataResource
from zanatalib.error import UnAvaliableResourceException
from zanatalib.error import NoSuchFileException
from zanatalib.error import UnavailableServiceError
from zanatalib.logger import Logger
from zanatacmd import ZanataCommand
from parseconfig import ZanataConfig
from publicanutil import PublicanUtility
from optionsutil import OptionsUtil

from command import makeHandler
from command import strip_docstring
from command import parse_command_line
from command import handle_program

log = Logger()

option_sets = {
    'url': [
        dict(
            type='command',
            long=['--url'],
            metavar='URL',
        ),
    ],
    'user_name': [
        dict(
            type='command',
            long=['--username'],
            metavar='USERNAME',
        ),
開發者ID:joycec,項目名稱:zanata-python-client,代碼行數:31,代碼來源:zanata.py

示例6: __init__

 def __init__(self):
     self.log = Logger()
開發者ID:pkulev,項目名稱:zanata-python-client,代碼行數:2,代碼來源:publicanutil.py

示例7: Logger

# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA  02110-1301, USA.

import os
import sys
import string

from zanatalib.error import UnAvaliableResourceException
from zanatalib.error import NoSuchFileException
from zanatalib.error import UnavailableServiceError
from zanatacmd import ZanataCommand
from parseconfig import ZanataConfig
from publicanutil import PublicanUtility
from zanatalib.logger import Logger

log = Logger()

class Push:
    def read_project_config(self, command_options):
        project_config = {}
        config = ZanataConfig()
        #Read the project configuration file using --project-config option
        config_file = [os.path.join(os.getcwd(), filename) for filename\
                        in ['zanata.xml', 'flies.xml']]

        if command_options.has_key('project_config'):
            config_file.append(command_options['project_config'][0]['value'])

        for path in config_file:
            if os.path.exists(path):
                log.info("Loading zanata project config from: %s" % path)
開發者ID:candlepin,項目名稱:zanata-python-client,代碼行數:31,代碼來源:pushcmd.py

示例8: __init__

 def __init__(self, options):
     self.command_options = options
     self.project_config = {}
     self.log = Logger()
     self.config = ZanataConfig()
開發者ID:joycec,項目名稱:zanata-python-client,代碼行數:5,代碼來源:optionsutil.py

示例9: Logger

from zanatalib.logger import Logger
from zanatacmd import ZanataCommand
from parseconfig import ZanataConfig
from publicanutil import PublicanUtility
from optionsutil import OptionsUtil

from command import makeHandler
from command import strip_docstring
from command import parse_command_line
from command import handle_program
from pushcmd import PoPush
from pushcmd import PublicanPush
from pushcmd import GenericPush
from pullcmd import GenericPull

log = Logger()

option_sets = {
    'url': [
        dict(
            type='command',
            long=['--url'],
            metavar='URL',
        ),
    ],
    'user_name': [
        dict(
            type='command',
            long=['--username'],
            metavar='USERNAME',
        ),
開發者ID:jobava-zanata,項目名稱:zanata-python-client,代碼行數:31,代碼來源:zanata.py

示例10: __init__

class CSVConverter:
    def __init__(self):
        self.log = Logger()

    def read_data(self, csv_file):
        data = []
        try:
            reader = csv.reader(open(csv_file, 'rb'))
            header = reader.next()
            size = len(header)
            for line in reader:
                items = {}
                entry_size = len(line)
                for x in range(size):
                    if x < entry_size:
                        item = {header[x]: line[x]}
                    else:
                        item = {header[x]: ""}
                    items.update(item)

            data.append(items)
        except IOError:
            self.log.error("Can not find csv file: %s" % csv_file)

        return data

    def read_csv_file(self, csv_file):
        data = []
        try:
            reader = csv.reader(open(csv_file, 'rb'))
            data = [line for line in reader]
        except IOError:
            self.log.error("Can not find csv file: %s" % csv_file)
        return data

    def convert_to_json(self, filepath, locale_map, comments_header):
        data = self.read_csv_file(expanduser(filepath))
        srclocales = []
        # srclocales.append('en-US')
        entries = []
        targetlocales = []
        csv_locales = []
        comments = []
        for index, item in enumerate(data):
            terms = []
            if index == 0:
                # Assuming last two names refers to column names,for example consider following csv file
                # en-US,es,ko,ru,pos,description
                # Hello,Hola,test,111,noun,Greeting
                # first line always contains locales and last two specifies column names
                comments = [comm for comm in item[-2:]]
                csv_locales = [lc for lc in item[:-2]]
                continue
            else:
                glossary_len = len(item)
                csv_locales_len = len(csv_locales)
                comments_len = len(comments)
                if glossary_len != csv_locales_len + comments_len:
                    print "Wrong entries in csv file, please check your csv file"
                    print "Entry in csv file", item
                    sys.exit(1)
                glossary_comments = item[-2:]
                for j in range(csv_locales_len):
                    if j == 0:
                        term = {'locale': csv_locales[j], 'content': item[j], 'comments': glossary_comments}
                    else:
                        term = {'locale': csv_locales[j], 'content': item[j], 'comments': []}
                    terms.append(term)
            entry = {'srcLang': 'en-US', 'glossaryTerms': terms}
            entries.append(entry)

        glossary = {'sourceLocales': srclocales, 'glossaryEntries': entries, 'targetLocales': targetlocales}
        # glossary = {'source-locales':srclocales, 'glossary-entries':entries, 'target-locales':targetlocales}
        return json.dumps(glossary)
開發者ID:pkulev,項目名稱:zanata-python-client,代碼行數:74,代碼來源:csvconverter.py

示例11: Logger

# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA  02110-1301, USA.

import os
import sys
import string

from zanatalib.error import UnAvaliableResourceException
from zanatalib.error import NoSuchFileException
from zanatalib.error import UnavailableServiceError
from zanatacmd import ZanataCommand
from parseconfig import ZanataConfig
from publicanutil import PublicanUtility
from zanatalib.logger import Logger

log = Logger()


class Push(object):
    _fields = ["command_options", "args", "project_type", "http_headers"]

    def __init__(self, *args, **kargs):
        for name, val in zip(self._fields, args):
            setattr(self, name, val)
        for key, value in kargs.iteritems():
            setattr(self, key, value)
        url, self.project_id, self.version_id, self.project_config = self.get_projectinfo(self.command_options)
        self.zanatacmd, username, client_version, server_version = self.create_zanatacmd(
            url, self.command_options, self.http_headers
        )
        self.plural_support = self.check_plural_support(server_version)
開發者ID:jobava-zanata,項目名稱:zanata-python-client,代碼行數:31,代碼來源:pushcmd.py

示例12: __init__

 def __init__(self, url, http_headers):
     self.log = Logger()
     self.zanata_resource = ZanataResource(url, http_headers)
開發者ID:pkulev,項目名稱:zanata-python-client,代碼行數:3,代碼來源:zanatacmd.py

示例13: Logger

#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA  02110-1301, USA.

import os
import sys
import string

from zanatalib.error import NoSuchFileException
from zanatacmd import ZanataCommand
from publicanutil import PublicanUtility
from zanatalib.logger import Logger

log = Logger()


class CommandsBase(object):
    """
    This is base class for all zpc commands
    """

    _fields = ["args", "context_data"]

    def __init__(self, *args, **kargs):
        for name, val in zip(self._fields, args):
            setattr(self, name, val)
        for key, value in kargs.iteritems():
            setattr(self, key, value)
        self.zanatacmd = self.create_zanatacmd()
開發者ID:pkulev,項目名稱:zanata-python-client,代碼行數:31,代碼來源:cmdbase.py

示例14: __init__

class PublicanUtility:
    def __init__(self):
        self.log = Logger()

    def create_txtflow(self, pofile):
        """
        Convert the content of the pot file to a list of text flow.
        @return: the dictionary object of textflow
        """
        textflows = []
        for entry in pofile:
            reflist = []
            if entry.msgctxt:
                self.log.warn("encountered msgctxt; not currently supported")
            m = hashlib.md5()
            m.update(entry.msgid.encode('utf-8'))
            textflowId = m.hexdigest()
            """
            "extensions":[{"object-type":"pot-entry-header","context":"context",
            "references":["fff"],"extractedComment":"extractedComment",
            "flags":["java-format"]}]
            """
            extracted_comment = entry.comment
            references = entry.occurrences
            for ref in references:
                node = ref[0]+":"+ref[1]
                reflist.append(node)
            flags = entry.flags
            
            #extensions_single_comment = [{'object-type':'comment','value':'test','space':'preserve'}]
            #extensions_pot_entry_header = [{"object-type":"pot-entry-header","context":"context","references":["fff"],"extractedComment":"extractedComment","flags":["java-format"]}]

            extensions=[{'object-type':'comment','value':extracted_comment,'space':'preserve'}, {"object-type":"pot-entry-header","context":"","references":reflist,"extractedComment":'',"flags":flags}]

            textflow = {'id': textflowId, 'lang':'en-US', 'content':entry.msgid, 'extensions':extensions, 'revision':1}
            textflows.append(textflow)
        return textflows
    
    def create_txtflowtarget(self, pofile):
        """
        Convert the content of the po file to a list of textflowtarget.
        @return: the dictionary object of textflow
        """
        obs_list=pofile.obsolete_entries()
        textflowtargets = []
        
        for entry in pofile:
            if entry in obs_list:
                continue
            m = hashlib.md5()
            m.update(entry.msgid.encode('utf-8'))
            textflowId = m.hexdigest()
            comment = entry.comment
            
            if entry.msgstr:
                state = "Approved"
            else:
                state = "New"
            #need judge for fuzzy state
            
            #create extensions
            extensions = [{"object-type":"comment","value":comment,"space":"preserve"}]
            
            # {"resId":"782f49c4e93c32403ba0b51821b38b90","state":"Approved","translator":{"email":"id","name":"name"},"content":"title:
            # ttff","extensions":[{"object-type":"comment","value":"testcomment","space":"preserve"}]}
            # Diable the translator to avoid issues on server side
            textflowtarget = {'resId': textflowId, 'state': state, 'content':entry.msgstr,'extensions':extensions}
            
            #Temporary fill in the admin info for translator to pass the validation, waiting for server side change
            textflowtargets.append(textflowtarget)
        
        return textflowtargets

    def create_extensions(self, pofile, object_type):
        """
        "extensions":[{"object-type":"po-header","comment":"comment_value", "entries":[{"key":"h1","value":"v1"}]}]
        "extensions":[{"object-type":"po-target-header", "comment":"comment_value", "entries":[{"key":"ht","value":"vt1"}]}]
        """
        entries = []
        metadatas = pofile.ordered_metadata()
        for item in metadatas:
            entry = {"key":item[0], "value":item[1]}
            entries.append(entry)
       
        extensions = [{"object-type":object_type,"comment":pofile.header, "entries":entries}]
        return extensions

    def create_pofile(self, path):
        """
        Convert the po file to a pofile object in polib.
        @return: pofile object
        """
        try:
            po = polib.pofile(path)
        except Exception:
            self.log.error("Can not processing the po file")
            sys.exit()

        return po

#.........這裏部分代碼省略.........
開發者ID:seanf,項目名稱:zanata-python-client,代碼行數:101,代碼來源:publicanutil.py

示例15: __init__

 def __init__(self, url, username = None, apikey = None,http_headers=None):
     self.log = Logger()
     self.zanata_resource = ZanataResource(url, username, apikey,http_headers)
開發者ID:gnuman,項目名稱:zanata-python-client,代碼行數:3,代碼來源:zanatacmd.py


注:本文中的zanatalib.logger.Logger類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。