예제 #1
0
파일: config.py 프로젝트: Nabellaleen/usine
    def load(self):
        path = expanduser('~/.usine')
        if lfs.is_file(path):
            return 'ERROR: %s is a file, remove it first' % path

        # Make the user configuration file if needed
        if not lfs.exists(path):
            print 'Making the configuration folder:', path
            lfs.make_folder(path)
            return 'Now add the INI files within the folder'

        # Read the user configuration file
        ini  = [ '%s/%s' % (path, x)
                 for x in lfs.get_names(path) if x[-4:] == '.ini' ]
        if len(ini) == 0:
            return 'ERROR: zero INI files found in %s/' % path

        # Read the ini file
        cfg = RawConfigParser()
        cfg.read(ini)

        # Get the data
        for section in cfg._sections:
            options = cfg._sections[section]
            type, name = section.split()
            module = modules[type]
            obj = module(options)

            # Keep the data unit
            self.by_type.setdefault(type, []).append(obj)
            self.by_type_and_name[(type, name)] = obj

        # Sort
        for type in self.by_type:
            self.by_type[type].sort(key=lambda x: x.name)
예제 #2
0
    def load(self):
        path = expanduser('~/.usine')
        if lfs.is_file(path):
            return 'ERROR: %s is a file, remove it first' % path

        # Make the user configuration file if needed
        if not lfs.exists(path):
            print 'Making the configuration folder:', path
            lfs.make_folder(path)
            return 'Now add the INI files within the folder'

        # Read the user configuration file
        ini = [
            '%s/%s' % (path, x) for x in lfs.get_names(path)
            if x[-4:] == '.ini'
        ]
        if len(ini) == 0:
            return 'ERROR: zero INI files found in %s/' % path

        # Read the ini file
        cfg = RawConfigParser()
        cfg.read(ini)

        # Get the data
        for section in cfg._sections:
            options = cfg._sections[section]
            type, name = section.split()
            module = modules[type]
            obj = module(options)

            # Keep the data unit
            self.by_type.setdefault(type, []).append(obj)
            self.by_type_and_name[(type, name)] = obj

        # Sort
        for type in self.by_type:
            self.by_type[type].sort(key=lambda x: x.name)
예제 #3
0
    options, args = parser.parse_args()

    # Filenames
    if args:
        filenames = set([])
        for arg in args:
            filenames = filenames.union(glob(arg))
        filenames = list(filenames)
    elif git.is_available():
        filenames = git.get_filenames()
        filenames = [ x for x in filenames if x.endswith('.py') ]
    else:
        filenames = []
        for path in lfs.traverse():
            if lfs.is_file(path) and basename(path).endswith('.py'):
                filenames.append(relpath(path))

    # Check options
    if len(filenames) == 0:
        parser.error(u'Please give at least one file to analyse.')
    if options.worse > 0 and options.show_lines is True:
        parser.error(
            u'Options --worse and --show-lines are mutually exclusive.')
    if options.show_lines == True and len(filenames) != 1:
        parser.error(
            u'The option --show-lines takes one file in parameter.')

    # (1) Export graph
    if options.graph:
        # Check if GIT is available
예제 #4
0
    options, args = parser.parse_args()

    # Filenames
    worktree = open_worktree('.', soft=True)
    if args:
        filenames = set([])
        for arg in args:
            filenames = filenames.union(glob(arg))
        filenames = list(filenames)
    elif worktree:
        filenames = worktree.get_filenames()
        filenames = [x for x in filenames if x.endswith('.py')]
    else:
        filenames = []
        for path in lfs.traverse():
            if lfs.is_file(path) and basename(path).endswith('.py'):
                filenames.append(relpath(path))

    # Check options
    if len(filenames) == 0:
        parser.error(u'Please give at least one file to analyse.')
    if options.worse > 0 and options.show_lines is True:
        parser.error(
            u'Options --worse and --show-lines are mutually exclusive.')
    if options.show_lines == True and len(filenames) != 1:
        parser.error(u'The option --show-lines takes one file in parameter.')

    # (1) Show Lines
    if options.show_lines:
        show_lines(filenames)
예제 #5
0
def get_test_filenames(test_path, force_download):
    """Return the test file names
    If the test files does'nt exists, we download it
    """

    uris = {'http://download.wikimedia.org/qualitywiki/latest':
            [('qualitywiki-latest-stub-articles.xml', '.gz'),      #~  3.1 KB
             ('qualitywiki-latest-stub-meta-current.xml', '.gz'),  #~ 11.0 KB
             ('qualitywiki-latest-stub-meta-history.xml', '.gz')], #~ 28.9 KB
            'http://download.wikimedia.org/tawiki/latest':
            [('tawiki-latest-stub-articles.xml', '.gz'),           #~ 1.2 MB
             ('tawiki-latest-stub-meta-history.xml', '.gz')],      #~ 7.3 MB
            'http://www.w3.org/XML/Test/': [('xmlts20080205', '.tar.gz')]
            }
    compressed_dir_path = join(test_path, 'compressed_files')

    if force_download is True:
        if lfs.exists(compressed_dir_path):
            print 'Remove compressed directory ', compressed_dir_path
            lfs.remove(compressed_dir_path)
            for names in uris.itervalues():
                for (name, ext) in names:
                    path = join(test_path, name)
                    if lfs.exists(path):
                        print 'Remove %s file' % path
                        lfs.remove(path)

    # test directory
    if lfs.exists(test_path) is False:
        lfs.make_folder(test_path)

    # compressed directory
    if lfs.exists(compressed_dir_path) is False:
        lfs.make_folder(compressed_dir_path)
    else:
        lfs.open(compressed_dir_path)

    test_dir_filenames = lfs.get_names(test_path)
    for base_uri, names in uris.iteritems():
        for (name, ext) in names:
            if test_dir_filenames.count(name):
                continue
            compressed_dest = join(compressed_dir_path, '%s%s' % (name, ext))
            # check if tarball already exists
            if lfs.exists(compressed_dest) is False:
                src = join(base_uri, '%s%s' % (name, ext))
                print 'GET %s file' % src
                dest = join(test_path, name)
                if vfs.exists(src) is False:
                    print "%s uri does not exists" % src
                    continue
                src_file = vfs.open(src)
                # save Gzip file
                compressed_dest_file = lfs.make_file(compressed_dest)
                compressed_dest_file.write(src_file.read())
                compressed_dest_file.close()
                src_file.close()
            print 'Extract file %s' % compressed_dest
            # Uncompressed File Path
            if name == 'xmlts20080205':
                # uncompress only xmlconf.xml file
                tar = open_tar(compressed_dest)
                xmlconf_file = tar.extractfile('xmlconf/xmlconf.xml')
                ucf_path = join(test_path, name)
                ucf_file = lfs.make_file(ucf_path)
                ucf_file.write(xmlconf_file.read())
                ucf_file.close()
            else:
                # untar Gzip file
                compressed_dest_file = lfs.open(compressed_dest)
                gzip_file = GzipFile(compressed_dest)
                ucf_path = join(test_path, name)
                ucf_file = lfs.make_file(ucf_path)
                ucf_file.write(gzip_file.read())
                compressed_dest_file.close()
                gzip_file.close()
                ucf_file.close()

    tests = []
    # update test dir name
    test_dir_filenames = lfs.get_names(test_path)
    for filename in test_dir_filenames:
        real_path = join(test_path, filename)
        if lfs.is_file(real_path):
            bytes = lfs.get_size(real_path)
            tests.append((real_path, filename, bytes,
                          get_string_size(bytes)))
    tests.sort(key=lambda x: x[2])
    return tests
예제 #6
0
파일: test_fs.py 프로젝트: kennym/itools
 def test_make_file(self):
     lfs.make_file('tests/file')
     self.assertEqual(lfs.is_file('tests/file'), True)
     lfs.remove('tests/file')
예제 #7
0
파일: test_fs.py 프로젝트: kennym/itools
 def test_is_not_folder(self):
     is_folder = lfs.is_file('tests/index.html.en')
     self.assertEqual(is_folder, True)
예제 #8
0
파일: test_fs.py 프로젝트: kennym/itools
 def test_is_not_file(self):
     is_file = lfs.is_file('tests')
     self.assertEqual(is_file, False)
예제 #9
0
파일: test_fs.py 프로젝트: kennym/itools
 def test_is_file(self):
     is_file = lfs.is_file('tests/index.html.en')
     self.assertEqual(is_file, True)
예제 #10
0
 def test_make_file(self):
     lfs.make_file('tests/file')
     self.assertEqual(lfs.is_file('tests/file'), True)
     lfs.remove('tests/file')
예제 #11
0
 def test_is_not_folder(self):
     is_folder = lfs.is_file('tests/index.html.en')
     self.assertEqual(is_folder, True)
예제 #12
0
 def test_is_not_file(self):
     is_file = lfs.is_file('tests')
     self.assertEqual(is_file, False)
예제 #13
0
 def test_is_file(self):
     is_file = lfs.is_file('tests/index.html.en')
     self.assertEqual(is_file, True)