Ejemplo n.º 1
0
    def test_corrupted_create(self):

        tmpdir = tempfile.mkdtemp()

        LibArchive.extract(self.testcontainer,
                           container(self.corruptedarchivepath).archive,
                           tmpdir)

        fs = FileSystem()
        path1 = tmpdir

        checked = DirectoryTree(tmpdir, fs)
        checked.add(path1, True)

        corrupted2archivepath = os.path.join(tmpdir, 'corrupted2.tar')

        LibArchive.create(fs, corrupted2archivepath, checked)

        self.assertTrue(os.path.exists(corrupted2archivepath))

        corrupted2archive = LibArchive(corrupted2archivepath)
        self.assertEqual(len(corrupted2archive.tree.root.children), 0)

        # clean up
        for root, dirs, files in os.walk(tmpdir, topdown=False):
            for name in files:
                os.remove(os.path.join(root, name))
            for name in dirs:
                os.rmdir(os.path.join(root, name))
        os.rmdir(tmpdir)
Ejemplo n.º 2
0
    def test_create_utf8(self):

        tmpdir = tempfile.mkdtemp()

        testarchivepath = os.path.join(self.testdirectory, 'testdata',
                                       'tešt.tar')

        LibArchive.extract(self.testcontainer,
                           container(testarchivepath).archive, tmpdir)

        path1 = os.path.join(tmpdir, 'tarmanš.log')
        fs = FileSystem()

        checked = DirectoryTree(tmpdir, fs)
        checked.add(path1, False)

        testdata2archivepath = os.path.join(tmpdir, 'tešt2.tar')

        LibArchive.create(fs, testdata2archivepath, checked)

        self.assertTrue(os.path.exists(testdata2archivepath))

        testdata2archive = LibArchive(testdata2archivepath)
        apath1 = os.path.join(testdata2archivepath, 'tarmanš.log')
        self.assertIn(apath1, testdata2archive.tree)

        # clean up
        for root, dirs, files in os.walk(tmpdir, topdown=False):
            for name in files:
                os.remove(os.path.join(root, name))
            for name in dirs:
                os.rmdir(os.path.join(root, name))
        os.rmdir(tmpdir)
Ejemplo n.º 3
0
    def test_create(self):
        testdatadirectory = os.path.join(self.testdirectory, 'testdata',
                                         'testdata')
        path1 = os.path.join(testdatadirectory, 'a', 'aa', 'aaa')
        path2 = os.path.join(testdatadirectory, 'c')
        path3 = os.path.join(testdatadirectory, 'a', 'ab')
        fs = FileSystem()

        checked = DirectoryTree(testdatadirectory, fs)
        checked.add(path1, False)
        checked.add(path2, False)
        checked.add(path3, True)

        tmpdir = tempfile.mkdtemp()

        testdata2archivepath = os.path.join(tmpdir, 'testdata2.tar.gz')

        LibArchive.create(fs, testdata2archivepath, checked)

        self.assertTrue(os.path.exists(testdata2archivepath))

        testdata2archive = LibArchive(testdata2archivepath)
        apath1 = os.path.join(testdata2archivepath, 'a', 'aa', 'aaa')
        apath2 = os.path.join(testdata2archivepath, 'c')
        apath3 = os.path.join(testdata2archivepath, 'a', 'ab')
        self.assertIn(apath1, testdata2archive.tree)
        self.assertIn(apath2, testdata2archive.tree)
        self.assertIn(apath3, testdata2archive.tree)

        os.remove(testdata2archivepath)
        os.rmdir(tmpdir)
Ejemplo n.º 4
0
    def __init__(self, mainscr, stdscr, directory, encoding, show_hiddens):
        self.encoding = encoding
        self.header_lns = HEADER_LNS
        self.mainscr = mainscr
        self.stdscr = stdscr
        self.color = curses.has_colors()
        if self.color:
            # set file type attributes (color and bold)
            curses.init_pair(1, curses.COLOR_BLUE, -1)
            self.attr_folder = curses.color_pair(1) | curses.A_BOLD
            curses.init_pair(2, 7, -1)
            self.attr_norm = curses.color_pair(2)

            # set wright / wrong attributes (color and bold)
            curses.init_pair(3, curses.COLOR_GREEN, -1)
            self.attr_wright = curses.color_pair(3) | curses.A_BOLD

            curses.init_pair(4, curses.COLOR_RED, -1)
            self.attr_wrong = curses.color_pair(4) | curses.A_BOLD

        self.kill = False
        self.ch = -1
        self.visited = {}
        self.area = None
        self.container = FileSystem()
        self.directory = self.container.abspath(directory)
        self.checked = DirectoryTree(self.directory, self.container)
        self.show_hiddens = show_hiddens
        self.chdir(self.directory)
Ejemplo n.º 5
0
 def setUp(self):
     self.testfilepath = tarman.tests.test_containers.__file__
     self.testdirectory = os.path.dirname(self.testfilepath)
     self.testdatapath = os.path.join(
         self.testdirectory, 'testdata', 'testdata'
     )
     self.fs = FileSystem()
Ejemplo n.º 6
0
            if d is None:
                return None
            if d.data == path_array[i]:
                continue

        return d

    def __delitem__(self, path):
        self[path].del_self()


if __name__ == "__main__":
    from tarman.containers import FileSystem

    tree = DirectoryTree("/home/matej/workarea/matejc.myportal/src",
                         FileSystem())

    a1 = tree.add("/home/matej/workarea/matejc.myportal/src")
    a2 = tree.add(
        "/home/matej/workarea/matejc.myportal/src/matejc/myportal/profiles",
        True)
    a3 = tree.add(
        "/home/matej/workarea/matejc.myportal/src/matejc/__init__.py")

    assert a2
    assert a3

    for n in tree:
        print n.get_path()
    print len(tree.root.children)