Esempio n. 1
0
 def test_atime(self):
     lfs.make_file('tests/file')
     atime = lfs.get_atime('tests/file')
     self.assertEqual(atime.year, datetime.now().year)
     self.assertEqual(atime.month, datetime.now().month)
     self.assertEqual(atime.day, datetime.now().day)
     lfs.remove('tests/file')
Esempio n. 2
0
 def test_atime(self):
     lfs.make_file('tests/file')
     atime = lfs.get_atime('tests/file')
     self.assertEqual(atime.year, datetime.now().year)
     self.assertEqual(atime.month, datetime.now().month)
     self.assertEqual(atime.day, datetime.now().day)
     lfs.remove('tests/file')
Esempio n. 3
0
 def test_remove_folder(self):
     # Create hierarchy
     lfs.make_folder('tests/folder')
     lfs.make_folder('tests/folder/a')
     lfs.make_file('tests/folder/a/hello.txt')
     # Remove and test
     lfs.remove('tests/folder')
     self.assertEqual(lfs.exists('tests/folder'), False)
Esempio n. 4
0
 def test_remove_folder(self):
     # Create hierarchy
     lfs.make_folder('tests/folder')
     lfs.make_folder('tests/folder/a')
     lfs.make_file('tests/folder/a/hello.txt')
     # Remove and test
     lfs.remove('tests/folder')
     self.assertEqual(lfs.exists('tests/folder'), False)
Esempio n. 5
0
    def _init_test(self, value):
        # Init data
        if not lfs.exists(self.config_path):
            lfs.make_file(self.config_path)

        # Write data
        config = rw_database.get_handler(self.config_path, ConfigFile)
        config.set_value("test", value)
        config.save_state()
Esempio n. 6
0
    def _init_test(self, value):
        # Init data
        if not lfs.exists(self.config_path):
            lfs.make_file(self.config_path)

        # Write data
        config = ConfigFile(self.config_path)
        config.set_value("test", value)
        config.save_state()
Esempio n. 7
0
 def extract_to_folder(self, dst):
     zip = self._open_zipfile()
     try:
         for filename in zip.namelist():
             path = join(dst, filename)
             with lfs.make_file(path) as file:
                 file.write(zip.read(filename))
     finally:
         zip.close()
Esempio n. 8
0
 def extract_to_folder(self, dst):
     zip = self._open_zipfile()
     try:
         for filename in zip.namelist():
             path = join(dst, filename)
             with lfs.make_file(path) as file:
                 file.write(zip.read(filename))
     finally:
         zip.close()
Esempio n. 9
0
 def setUp(self):
     database = RWDatabase(100, 100)
     self.database = database
     self.root = database.get_handler('.')
     file = lfs.make_file('tests/toto.txt')
     try:
         file.write('I am Toto\n')
     finally:
         file.close()
Esempio n. 10
0
 def setUp(self):
     database = RWDatabase(100, 100)
     self.database = database
     self.root = database.get_handler('.')
     file = lfs.make_file('tests/toto.txt')
     try:
         file.write('I am Toto\n')
     finally:
         file.close()
Esempio n. 11
0
 def test_write_and_truncate(self):
     # Initialize
     file = lfs.make_file('tests/toto.txt')
     try:
         file.write('hello\n')
     finally:
         file.close()
     # Test
     file = lfs.open('tests/toto.txt', WRITE)
     try:
         file.write('bye\n')
     finally:
         file.close()
     self.assertEqual(open('tests/toto.txt').read(), 'bye\n')
     # Remove temporary file
     lfs.remove('tests/toto.txt')
Esempio n. 12
0
 def test_append(self):
     # Initialize
     file = lfs.make_file('tests/toto.txt')
     try:
         file.write('hello\n')
     finally:
         file.close()
     # Test
     file = lfs.open('tests/toto.txt', APPEND)
     try:
         file.write('bye\n')
     finally:
         file.close()
     self.assertEqual(open('tests/toto.txt').read(), 'hello\nbye\n')
     # Remove temporary file
     lfs.remove('tests/toto.txt')
Esempio n. 13
0
 def test_write_and_truncate(self):
     # Initialize
     file = lfs.make_file('tests/toto.txt')
     try:
         file.write('hello\n')
     finally:
         file.close()
     # Test
     file = lfs.open('tests/toto.txt', WRITE)
     try:
         file.write('bye\n')
     finally:
         file.close()
     self.assertEqual(open('tests/toto.txt').read(), 'bye\n')
     # Remove temporary file
     lfs.remove('tests/toto.txt')
Esempio n. 14
0
 def test_append(self):
     # Initialize
     file = lfs.make_file('tests/toto.txt')
     try:
         file.write('hello\n')
     finally:
         file.close()
     # Test
     file = lfs.open('tests/toto.txt', APPEND)
     try:
         file.write('bye\n')
     finally:
         file.close()
     self.assertEqual(open('tests/toto.txt').read(), 'hello\nbye\n')
     # Remove temporary file
     lfs.remove('tests/toto.txt')
Esempio n. 15
0
            units = list(units)
        except Exception:
            print
            print '*'
            print '* Error:', path
            print '*'
            raise

        relative_path = Path('..').resolve2(path)
        for source, context, line in units:
            po.add_unit(relative_path, source, context, line)
    print

    # Update locale.pot
    if not lfs.exists('locale/locale.pot'):
        lfs.make_file('locale/locale.pot')

    write('* Update PO template ')
    data = po.to_str()
    file = lfs.open('locale/locale.pot', WRITE)
    try:
        file.write(data)
    finally:
        file.close()
    print

    # Update PO files
    folder = lfs.open('locale')
    filenames = set([ x for x in folder.get_names() if x[-3:] == '.po' ])
    filenames.add('%s.po' % src_language)
    for language in config.get_value('target_languages'):
Esempio n. 16
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
Esempio n. 17
0
 def test_remove_file(self):
     lfs.make_file('tests/file')
     lfs.remove('tests/file')
     self.assertEqual(lfs.exists('tests/file'), False)
Esempio n. 18
0
 def test_make_file(self):
     lfs.make_file('tests/file')
     self.assertEqual(lfs.is_file('tests/file'), True)
     lfs.remove('tests/file')
Esempio n. 19
0
 def test_make_file(self):
     lfs.make_file('tests/file')
     self.assertEqual(lfs.is_file('tests/file'), True)
     lfs.remove('tests/file')
Esempio n. 20
0
 def test_remove_file(self):
     lfs.make_file('tests/file')
     lfs.remove('tests/file')
     self.assertEqual(lfs.exists('tests/file'), False)