예제 #1
0
    def load_lib(self, force=False):
        """
        load_lib()

            code_lib{} will contain a list of parser instancied with the source code file
            found in the 'lib_source' config parameter

            return int, number of entries in code_lib{} or -1 if not re-run
        """
        # if not forced run only once
        if not force and len(self.code_lib) > 0:
            return -1

        config_location = self.config.get('lib_source')
        if not config_location:
            raise RuntimeError("load_lib(): 'lib_source' not found, no lib available")

        self.code_lib = {}
        n = 0
        for f in glob.glob(config_location):
            parser = self.parser_factory.get_parser(f)
            printerr("location=%s, type=%s" % (f, parser.name))
            parser.parse(f)
            self.code_lib[f] = parser
            n += 1

        return n
예제 #2
0
파일: libido.py 프로젝트: Sylvain303/libido
def main():
    # command line processing
    arguments = docopt(get_usage(), version='0.2')
    if arguments['-q']:
        quiet(True)

    printerr(arguments)

    l = libido(arguments)
    l.load_config()
    l.init_factory()

    # destination, default 'None'
    dest = arguments['-o']
    export = False

    if arguments['-e']:
        if dest != 'None':
            raise RuntimeError('-o not supported with -e')
        else:
            l.ensure_remote_access()
            export = True

    # process filename's agrument, only the first for now
    filename = arguments['SOURCE_FILE'][0]
    printerr('filename=%s' % filename)

    l.parse_input(filename)

    if export:
        l.process_export(filename)
    else:
        l.process_output(filename, dest)
예제 #3
0
파일: libido.py 프로젝트: Sylvain303/libido
    def load_config(self):
        look_for_config = [ '.', '.libido', '~/.libido', self.mydir ]
        for d in look_for_config:
            config_file = os.path.join(os.path.expanduser(d), self.config_base)
            if os.path.isfile(config_file):
                printerr('readconfig=%s' % config_file)
                self.conf = self.readconfig(config_file)
                break

        if self.conf == None:
            raise RuntimeError("no config found")
예제 #4
0
    def parse(self, filename):
        #open file in reading mode unicode
        f = open(filename, 'rU')
        # some counter
        self.d = {
                'line_count' : 0,
                'libido' : 0,
                }

        # reading file (line by line)
        n = 0
        for line in f:
            n += 1
            self.d['line_count'] += 1
            m = REMatcher(line.rstrip('\n'))
            self.lines.append(line)

            if m.match(self.open_marker):
                self.d['libido'] += 1

                p = self.tokenize(m)

                if p:
                    if p.action == 'assign':
                        self.assign(p.var, p.args)
                    elif p.action == 'expand':
                        self.add_expansion(n, p.args)
                    elif p.action == 'depend':
                        # in specific parser? ex: bash
                        printerr('parse:%d:dependencies found %s ??' % (n, line.rstrip()))
                        pass
                else:
                    printerr('parsre error:%d:%s' % (n, line.rstrip()))

        f.close()
        return self.d
예제 #5
0
파일: libido.py 프로젝트: Sylvain303/libido
    def readconfig(self, fname):
        f = open(fname)
        i = 0
        var, val = None, None
        config = {}

        keywords = """
            remote_location
            remote_project
            search_scan_offset
            libido_keyword
            git_auto_commit
            auto_inc_duplicate
            auto_quote_string
            disable_add_ref
            lib_source
        """
        allowed = [ k.strip() for k in keywords.strip().split('\n') if len(k) > 1 ]

        # parse config
        for l in f:
            i += 1
            if re.match(r'^#', l):
                continue

            l = l.rstrip()
            if l == '':
                continue

            try:
                var, val = re.split(r'\s*=\s*', l)
            except ValueError:
                printerr("config:error:%d:split on:'%s'" % (i, l))
                continue

            if var:
                printerr('config(%d):%s : %s' % (i, var, val))
                config[var] = val
            else:
                printerr('config:error:%d:no match: %s' % (i,l))

        return config
예제 #6
0
def test_printerr(capsys):
    assert quiet() == False
    printerr("pipo")
    out, err = capsys.readouterr()
    assert out == ''
    assert err == 'pipo\n'

    quiet(True)
    assert quiet() == True

    printerr("pipo2")
    out, err = capsys.readouterr()
    assert out == ''
    assert err == ''

    quiet(False)
    assert quiet() == False

    printerr("pipo3")
    out, err = capsys.readouterr()
    assert out == ''
    assert err == 'pipo3\n'