コード例 #1
0
ファイル: transformers.py プロジェクト: laetitiae/data-is-fun
    def __init__(self, config_file, nullable=False, match_count=0):

        self.nullable = nullable
        self.match_count = match_count
        self.last_type_size = []
        self.loaded = False
        self.config_file = config_file

        self.log = logging.getLogger('transformer')

        # Config options
        self.config = Config(self.config_file)

        self.name = self.config.get("transformer", "name", "string", "")
        self.regexp = self.config.get("transformer", "regexp", "string", "")
        self.formatter = self.config.get("transformer", "formatter", "string",
                                         "")
        self.output_type = self.config.get("transformer", "output_type",
                                           "string", "").upper()
        self.type_format = self.config.get("transformer", "type_format",
                                           "string", "")
        self.compatible_writers = map(
            lambda x: x.strip(),
            self.config.get("transformer", "compatible_writers", "string",
                            "").split(","))

        if not self.compatible_writers:
            self.compatible_writers = []
コード例 #2
0
    def __init__(self, config_file, nullable=False, match_count = 0):

        self.nullable = nullable
        self.match_count = match_count
        self.last_type_size = []
        self.loaded = False
        self.config_file = config_file

        self.log = logging.getLogger('transformer')

        # Config options
        self.config = Config(self.config_file)

        self.name = self.config.get("transformer", "name", "string", "")
        self.regexp = self.config.get("transformer", "regexp", "string", "")
        self.formatter = self.config.get("transformer", "formatter", "string", "")
        self.output_type = self.config.get("transformer", "output_type", "string", "").upper()
        self.type_format = self.config.get("transformer", "type_format", "string", "")
        self.compatible_writers = map(lambda x: x.strip(), self.config.get("transformer", "compatible_writers", "string", "").split(","))

        if not self.compatible_writers:
            self.compatible_writers = []
コード例 #3
0
class transformer:
    def __init__(self, config_file, nullable=False, match_count = 0):

        self.nullable = nullable
        self.match_count = match_count
        self.last_type_size = []
        self.loaded = False
        self.config_file = config_file

        self.log = logging.getLogger('transformer')

        # Config options
        self.config = Config(self.config_file)

        self.name = self.config.get("transformer", "name", "string", "")
        self.regexp = self.config.get("transformer", "regexp", "string", "")
        self.formatter = self.config.get("transformer", "formatter", "string", "")
        self.output_type = self.config.get("transformer", "output_type", "string", "").upper()
        self.type_format = self.config.get("transformer", "type_format", "string", "")
        self.compatible_writers = map(lambda x: x.strip(), self.config.get("transformer", "compatible_writers", "string", "").split(","))

        if not self.compatible_writers:
            self.compatible_writers = []

    def load(self):
        self._regexp = re.compile(self.regexp)

        try:
            functions = self.config.c.items('functions')
        except:
            functions = False
        
        if functions:
            try:
                # Get and compile pre-format lambda functions (groups{}) => str)
                pre_format_pairs = dict(filter(lambda x: x[0].startswith('preformat_'), functions))
                self.f_preformat = {}
                for name, f in pre_format_pairs.iteritems():
                    try:
                        self.f_preformat[name[10:]] = eval(compile(f, '<string>','eval'), {}, {})
                    except Exception, e:
                        self.log.error("Error compiling preformat function %s at %s(%s) [%s]" % (name, self.name, self.config_file, e))
                        raise
                         

                # Get and compile matcher lambda functions (groups{}) => True || False
                matcher_pairs = dict(filter(lambda x: x[0].startswith('matcher_'), functions))
                self.f_matchers = {}
                for name, f in matcher_pairs.iteritems():
                    try:
                        self.f_matchers[name[8:]] = eval(compile(f, '<string>','eval'), {}, {})
                    except Exception, e:
                        self.log.error("Error compiling matcher function %s at %s(%s) [%s]" % (name, self.name, self.config_file, e))
                        raise

                # Get and compile post-format lambda function (formated_str, values) => final_str
                post_format = self.config.get("functions", "postformat", "string", "")
                if post_format:
                    try:
                        self.f_postformat = eval(compile(post_format, '<string>','eval'), {}, {})
                    except Exception, e:
                        self.log.error("Error compiling postformat function at %s(%s) [%s]" % (self.name, self.config_file, e))
                        raise
                else:
コード例 #4
0
ファイル: dataisfun.py プロジェクト: laetitiae/data-is-fun
            try:
                files_by_reader[optlist[2:]] += [ x.strip(' ') for x in arglist.split(' ') ]
            except:
                files_by_reader[optlist[2:]] = [ x.strip(' ') for x in arglist.split(' ') ]

    if files_to_read:
        files_by_reader['_all'] = files_to_read


    if not config_file:
        usage()

    #
    # Load config from file
    #
    c = Config(config_file)

    # 
    # Start logger
    #
    if verbose_level == None:
        verbose_level = c.get("main", "verbose", "int", 2)
    progress = True
    if verbose_level == 0: # TOTALY QUIET
        verbose_level = logging.CRITICAL
        progress = False
    elif verbose_level == 1:
        verbose_level = logging.ERROR
    elif verbose_level == 2:
        verbose_level = logging.INFO
    else:
コード例 #5
0
ファイル: transformers.py プロジェクト: laetitiae/data-is-fun
class transformer:
    def __init__(self, config_file, nullable=False, match_count=0):

        self.nullable = nullable
        self.match_count = match_count
        self.last_type_size = []
        self.loaded = False
        self.config_file = config_file

        self.log = logging.getLogger('transformer')

        # Config options
        self.config = Config(self.config_file)

        self.name = self.config.get("transformer", "name", "string", "")
        self.regexp = self.config.get("transformer", "regexp", "string", "")
        self.formatter = self.config.get("transformer", "formatter", "string",
                                         "")
        self.output_type = self.config.get("transformer", "output_type",
                                           "string", "").upper()
        self.type_format = self.config.get("transformer", "type_format",
                                           "string", "")
        self.compatible_writers = map(
            lambda x: x.strip(),
            self.config.get("transformer", "compatible_writers", "string",
                            "").split(","))

        if not self.compatible_writers:
            self.compatible_writers = []

    def load(self):
        self._regexp = re.compile(self.regexp)

        try:
            functions = self.config.c.items('functions')
        except:
            functions = False

        if functions:
            try:
                # Get and compile pre-format lambda functions (groups{}) => str)
                pre_format_pairs = dict(
                    filter(lambda x: x[0].startswith('preformat_'), functions))
                self.f_preformat = {}
                for name, f in pre_format_pairs.iteritems():
                    try:
                        self.f_preformat[name[10:]] = eval(
                            compile(f, '<string>', 'eval'), {}, {})
                    except Exception, e:
                        self.log.error(
                            "Error compiling preformat function %s at %s(%s) [%s]"
                            % (name, self.name, self.config_file, e))
                        raise

                # Get and compile matcher lambda functions (groups{}) => True || False
                matcher_pairs = dict(
                    filter(lambda x: x[0].startswith('matcher_'), functions))
                self.f_matchers = {}
                for name, f in matcher_pairs.iteritems():
                    try:
                        self.f_matchers[name[8:]] = eval(
                            compile(f, '<string>', 'eval'), {}, {})
                    except Exception, e:
                        self.log.error(
                            "Error compiling matcher function %s at %s(%s) [%s]"
                            % (name, self.name, self.config_file, e))
                        raise

                # Get and compile post-format lambda function (formated_str, values) => final_str
                post_format = self.config.get("functions", "postformat",
                                              "string", "")
                if post_format:
                    try:
                        self.f_postformat = eval(
                            compile(post_format, '<string>', 'eval'), {}, {})
                    except Exception, e:
                        self.log.error(
                            "Error compiling postformat function at %s(%s) [%s]"
                            % (self.name, self.config_file, e))
                        raise
                else: