Ejemplo n.º 1
0
 def test_uncompress_file(self):
     p = os.path.join('tests', 'fixtures', 'foobar', 'foo')
     prz = mkstemppath()
     pr2 = mkstemppath()
     xz.compress(p, prz)
     xz.uncompress(prz, pr2)
     
Ejemplo n.º 2
0
 def test_get_utc_mtime(self):
     apath = mkstemppath()
     with open(apath, 'a'):
         pass
     os.utime(apath, (978307200,  978307200)) # 1 Jan 2001, 00:00:00 UTC
     assert_equal(datetime(2001, 1, 1, 0, 0), Archive.get_mtime_as_utcdatetime(apath))
     os.unlink(apath)
Ejemplo n.º 3
0
 def test_has_version(self):
     foo = os.path.join('foobar', 'foo')
     apath = mkstemppath()
     a = Archive(apath, rzip)
     a.add_version([foo])
     assert_equal(0, a.has_version(foo))
     assert_equal(None, a.has_version(os.path.join('foobar', 'bar')))
Ejemplo n.º 4
0
 def test_add_100_versions(self):
     foo = os.path.join('foobar', 'foo')
     apath = mkstemppath()
     a = Archive(apath, rzip)
     for n in range(0, 100):
         a.add_version([foo])
     TestArchive.assert_ziprz_filenames(apath, [ "versions/%d/foobar/foo"%(n) for n in range(0, 100) ])
Ejemplo n.º 5
0
 def test_has_version(self):
     foo = os.path.join('foobar', 'foo')
     apath = mkstemppath()
     a = Archive(apath, rzip)
     a.add_version([foo])
     assert_equal(0, a.has_version(foo))
     assert_equal(None, a.has_version(os.path.join('foobar', 'bar')))
Ejemplo n.º 6
0
 def test_add_file(self):
     foo = os.path.join('foobar', 'foo')
     bar = os.path.join('foobar', 'bar')
     apath = mkstemppath()
     a = Archive(apath, rzip)
     a.add_version([foo])
     a.add_version([bar])
     TestArchive.assert_ziprz_filenames(apath, ["versions/0/foobar/foo", "versions/1/foobar/bar"])
Ejemplo n.º 7
0
 def test_get_utc_mtime(self):
     apath = mkstemppath()
     with open(apath, 'a'):
         pass
     os.utime(apath, (978307200, 978307200))  # 1 Jan 2001, 00:00:00 UTC
     assert_equal(datetime(2001, 1, 1, 0, 0),
                  Archive.get_mtime_as_utcdatetime(apath))
     os.unlink(apath)
Ejemplo n.º 8
0
 def test_add_100_versions(self):
     foo = os.path.join('foobar', 'foo')
     apath = mkstemppath()
     a = Archive(apath, rzip)
     for n in range(0, 100):
         a.add_version([foo])
     TestArchive.assert_ziprz_filenames(
         apath, ["versions/%d/foobar/foo" % (n) for n in range(0, 100)])
Ejemplo n.º 9
0
 def test_compress_file(self):
     p = os.path.join('tests', 'fixtures', 'foobar', 'foo')
     prz = mkstemppath()
     assert(os.path.exists(p))
     assert(not(os.path.exists(prz)))
     rzip.compress(p, prz)
     assert(os.path.exists(prz))
     assert_equal(hashlib.md5(open(prz).read()).hexdigest(), "dfa5ce71cda1c59f44eef332d4cb98cd")
     os.unlink(prz)
Ejemplo n.º 10
0
 def test_add_file(self):
     foo = os.path.join('foobar', 'foo')
     bar = os.path.join('foobar', 'bar')
     apath = mkstemppath()
     a = Archive(apath, rzip)
     a.add_version([foo])
     a.add_version([bar])
     TestArchive.assert_ziprz_filenames(
         apath, ["versions/0/foobar/foo", "versions/1/foobar/bar"])
Ejemplo n.º 11
0
 def test_compress_file(self):
     p = os.path.join('tests', 'fixtures', 'foobar', 'foo')
     prz = mkstemppath()
     assert(os.path.exists(p))
     assert(not(os.path.exists(prz)))
     xz.compress(p, prz)
     assert(os.path.exists(prz))
     assert_equal(hashlib.md5(open(prz, 'rb').read()).hexdigest(), "26fcf3231c59f1e991b9846b8e732452")
     os.unlink(prz)
Ejemplo n.º 12
0
 def test_add_dir(self):
     dir = 'foobar'
     apath = mkstemppath()
     a = Archive(apath, rzip)
     a.add_version([dir])
     TestArchive.assert_ziprz_filenames(apath, [
         "versions/0/foobar/", "versions/0/foobar/symlink",
         "versions/0/foobar/bar", "versions/0/foobar/foo"
     ])
Ejemplo n.º 13
0
 def test_external_attr(self):
     foo = os.path.join('foobar', 'foo')
     os.chmod(foo, 0o644)
     apath = mkstemppath()
     a = Archive(apath, rzip)
     a.add_version([foo])
     with rzip.TempUncompress(apath) as zippath:
         with ZipFile(zippath, mode='r', allowZip64=True) as myzip:
             info = myzip.infolist()[0]
             assert_equal(info.external_attr, 0o100644 << 16)
Ejemplo n.º 14
0
 def test_external_attr(self):
     foo = os.path.join('foobar', 'foo')
     os.chmod(foo, 0o644)
     apath = mkstemppath()
     a = Archive(apath, rzip)
     a.add_version([foo])
     with rzip.TempUncompress(apath) as zippath:
         with ZipFile(zippath, mode='r', allowZip64=True) as myzip:
             info = myzip.infolist()[0]
             assert_equal(info.external_attr, 0o100644 << 16)
Ejemplo n.º 15
0
 def test_add_unicode_file(self):
     i = "“Iñtërnâtiônàlizætiøn”"
     apath = mkstemppath()
     a = Archive(apath, rzip)
     a.add_version([i])
     TestArchive.assert_ziprz_filenames(apath, ["versions/0/“Iñtërnâtiônàlizætiøn”"])
     xdir = mkdtemp()
     a.extract(xdir, 0)
     versiondir = os.path.join(xdir, os.path.basename(apath))
     assert(os.path.exists(os.path.join(versiondir, '0', "“Iñtërnâtiônàlizætiøn”")))
     assert_equal(open(i, 'rb').read(), open(os.path.join(versiondir, '0', '“Iñtërnâtiônàlizætiøn”'), 'rb').read())
Ejemplo n.º 16
0
 def test_compress_file(self):
     p = os.path.join('tests', 'fixtures', 'foobar', 'foo')
     prz = mkstemppath()
     assert (os.path.exists(p))
     assert (not (os.path.exists(prz)))
     rzip.compress(p, prz)
     assert (os.path.exists(prz))
     assert_equal(
         hashlib.md5(open(prz, 'rb').read()).hexdigest(),
         "dfa5ce71cda1c59f44eef332d4cb98cd")
     os.unlink(prz)
Ejemplo n.º 17
0
 def test_compress_file(self):
     p = os.path.join('tests', 'fixtures', 'foobar', 'foo')
     prz = mkstemppath()
     assert (os.path.exists(p))
     assert (not (os.path.exists(prz)))
     xz.compress(p, prz)
     assert (os.path.exists(prz))
     assert_equal(
         hashlib.md5(open(prz, 'rb').read()).hexdigest(),
         "26fcf3231c59f1e991b9846b8e732452")
     os.unlink(prz)
Ejemplo n.º 18
0
 def test_zip_versions(self):
     foo = os.path.join('foobar', 'foo')
     bar = os.path.join('foobar', 'bar')
     apath = mkstemppath()
     a = Archive(apath, rzip)
     a.add_version([foo])
     a.add_version([bar])
     with rzip.TempUncompress(apath) as zippath:
         with ZipFile(zippath, mode='r', allowZip64=True) as myzip:
             assert_equal([[('foobar/foo', 4289425978)], [('foobar/bar', 1226766874)]],
                          Archive._zip_versions(myzip))
Ejemplo n.º 19
0
 def test_zip_versions(self):
     foo = os.path.join('foobar', 'foo')
     bar = os.path.join('foobar', 'bar')
     apath = mkstemppath()
     a = Archive(apath, rzip)
     a.add_version([foo])
     a.add_version([bar])
     with rzip.TempUncompress(apath) as zippath:
         with ZipFile(zippath, mode='r', allowZip64=True) as myzip:
             assert_equal([[('foobar/foo', 4289425978)],
                           [('foobar/bar', 1226766874)]],
                          Archive._zip_versions(myzip))
Ejemplo n.º 20
0
    def test_timestamps(self):
        foo = os.path.join('foobar', 'foo')
        os.utime(foo, (978307200, 978307200))

        apath = mkstemppath()
        a = Archive(apath, rzip)
        a.add_version([foo])
        with rzip.TempUncompress(apath) as zippath:
            with ZipFile(zippath, mode='r', allowZip64=True) as myzip:
                info = myzip.infolist()[0]
                assert_equal(info.date_time, (2001, 1, 1, 0, 0, 0))
                mtime = Archive.parse_extended_mtime(info)
                assert_equal(978307200, mtime)
Ejemplo n.º 21
0
 def test_timestamps(self):
     foo = os.path.join('foobar', 'foo')
     os.utime(foo, (978307200,  978307200))
     
     apath = mkstemppath()
     a = Archive(apath, rzip)
     a.add_version([foo])
     with rzip.TempUncompress(apath) as zippath:
         with ZipFile(zippath, mode='r', allowZip64=True) as myzip:
             info = myzip.infolist()[0]
             assert_equal(info.date_time, (2001, 1, 1, 0, 0, 0))
             mtime = Archive.parse_extended_mtime(info)
             assert_equal(978307200, mtime)
Ejemplo n.º 22
0
 def test_cli(self):
     a = mkstemppath()
     foo = os.path.join('foobar', 'foo')
     bar = os.path.join('foobar', 'bar')
     sparchive.cli.main(["addversion", a, foo])
     sparchive.cli.main(["addversion", a, bar])
     assert(os.path.exists(a))
     with rzip.TempUnrzip(a) as zippath:
         with ZipFile(zippath, 'r') as myzip:
             filenames = []
             for info in myzip.infolist():
                 filenames.append(info.filename)
             assert_equal(filenames, ["versions/0/foobar/foo", "versions/1/foobar/bar"])
     sparchive.cli.main(["list", a])
Ejemplo n.º 23
0
 def test_is_entries(self):
     foo = os.path.join('foobar')
     apath = mkstemppath()
     a = Archive(apath, rzip)
     a.add_version([foo])
     with rzip.TempUncompress(apath) as zippath:
         with ZipFile(zippath, mode='r', allowZip64=True) as myzip:
             for info in myzip.infolist():
                 if info.filename == "versions/0/foobar/symlink":
                     assert_true(Archive.islink_entry(info))
                 elif info.filename == "versions/0/foobar/":
                     assert_true(Archive.isdir_entry(info))
                 else:
                     assert_true(not(Archive.isdir_entry(info)) and not(Archive.islink_entry(info)))
Ejemplo n.º 24
0
 def test_is_entries(self):
     foo = os.path.join('foobar')
     apath = mkstemppath()
     a = Archive(apath, rzip)
     a.add_version([foo])
     with rzip.TempUncompress(apath) as zippath:
         with ZipFile(zippath, mode='r', allowZip64=True) as myzip:
             for info in myzip.infolist():
                 if info.filename == "versions/0/foobar/symlink":
                     assert_true(Archive.islink_entry(info))
                 elif info.filename == "versions/0/foobar/":
                     assert_true(Archive.isdir_entry(info))
                 else:
                     assert_true(not (Archive.isdir_entry(info))
                                 and not (Archive.islink_entry(info)))
Ejemplo n.º 25
0
 def add_version(self, pathlist):
     """Add a version to this archive."""
     if not(os.path.isdir(os.path.dirname(self.archive_path))):
         os.makedirs(os.path.dirname(self.archive_path))
     for path in pathlist:
         if not(os.path.exists(path)):
             raise Exception()
     with rzip.TempUnrzip(self.archive_path) as zippath:
         new_version = self.get_version_count(zippath)
         with ZipFile(zippath, mode='a', allowZip64=True) as myzip:
             for path in pathlist:
                 self._add_path(path, new_version, myzip)
         tmprzip = mkstemppath()
         rzip.compress(zippath, tmprzip)
     # perform sanity checks here
     os.rename(tmprzip, self.archive_path)
Ejemplo n.º 26
0
 def test_cli_extract(self):
     a = mkstemppath()
     foo = os.path.join('foobar', 'foo')
     bar = os.path.join('foobar', 'bar')
     sparchive.cli.main(["addversion", a, foo])
     sparchive.cli.main(["addversion", a, bar])
     xdir = mkdtemp()
     olddir = os.getcwd()
     os.chdir(os.path.join(xdir))
     sparchive.cli.main(["extract", a])
     os.chdir(olddir)
     xdir = os.path.join(xdir, os.path.basename(a))
     assert(os.path.exists(os.path.join(xdir, '0', 'foobar', 'foo')))
     assert_equal(open(foo).read(), open(os.path.join(xdir, '0', 'foobar', 'foo')).read())
     assert(os.path.exists(os.path.join(xdir,'1', 'foobar', 'bar')))
     assert_equal(open(bar).read(), open(os.path.join(xdir, '1', 'foobar', 'bar')).read())
Ejemplo n.º 27
0
 def test_add_unicode_file(self):
     i = "“Iñtërnâtiônàlizætiøn”"
     apath = mkstemppath()
     a = Archive(apath, rzip)
     a.add_version([i])
     TestArchive.assert_ziprz_filenames(
         apath, ["versions/0/“Iñtërnâtiônàlizætiøn”"])
     xdir = mkdtemp()
     a.extract(xdir, 0)
     versiondir = os.path.join(xdir, os.path.basename(apath))
     assert (os.path.exists(
         os.path.join(versiondir, '0', "“Iñtërnâtiônàlizætiøn”")))
     assert_equal(
         open(i, 'rb').read(),
         open(os.path.join(versiondir, '0', '“Iñtërnâtiônàlizætiøn”'),
              'rb').read())
Ejemplo n.º 28
0
 def test_cli(self):
     a = mkstemppath()
     foo = os.path.join('foobar', 'foo')
     bar = os.path.join('foobar', 'bar')
     sparchive.cli.main(["addversion", a, foo])
     sparchive.cli.main(["addversion", a, bar])
     assert (os.path.exists(a))
     with rzip.TempUncompress(a) as zippath:
         with ZipFile(zippath, 'r') as myzip:
             filenames = []
             for info in myzip.infolist():
                 filenames.append(info.filename)
             assert_equal(
                 filenames,
                 ["versions/0/foobar/foo", "versions/1/foobar/bar"])
     sparchive.cli.main(["list", a])
Ejemplo n.º 29
0
 def add_version(self, pathlist):
     """Add a version to this archive."""
     if not (os.path.isdir(
             os.path.dirname(os.path.abspath(self.archive_path)))):
         os.makedirs(os.path.dirname(os.path.abspath(self.archive_path)))
     for path in pathlist:
         if not (os.path.exists(path)):
             raise Exception()
     with self.compress_module.TempUncompress(self.archive_path) as zippath:
         new_version = self.get_version_count(zippath)
         with ZipFile(zippath, mode='a', allowZip64=True) as myzip:
             for path in pathlist:
                 self._add_path(path, new_version, myzip)
         tmprzip = mkstemppath()
         self.compress_module.compress(zippath, tmprzip)
     # perform sanity checks here
     shutil.move(tmprzip, self.archive_path)
Ejemplo n.º 30
0
    def test_extract(self):
        foo = os.path.join('foobar', 'foo')
        bar = os.path.join('foobar', 'bar')
        os.utime(foo, (978307200,  978307200))
        os.utime(bar, (978307200,  978307200))
        os.chmod(foo, 0o644)
        os.chmod(bar, 0o7755)
        apath = mkstemppath()
        a = Archive(apath, rzip)
        a.add_version([foo])
        a.add_version([bar])
        a.add_version(['foobar'])
        xdir = mkdtemp()
        a.extract(xdir, 0)
        versiondir = os.path.join(xdir, os.path.basename(apath))
        assert(os.path.exists(os.path.join(versiondir, '0', 'foobar', 'foo')))
        assert_equal(open(foo, 'rb').read(), open(os.path.join(versiondir, '0', 'foobar', 'foo'), 'rb').read())

        a.extract(xdir, 1)
        assert(os.path.exists(os.path.join(versiondir, '1', 'foobar', 'bar')))
        assert_equal(open(bar, 'rb').read(), open(os.path.join(versiondir, '1', 'foobar', 'bar'), 'rb').read())
        shutil.rmtree(xdir)

        # now extract all versions
        xdir = mkdtemp()
        versiondir = os.path.join(xdir, os.path.basename(apath))
        a.extract(xdir)
        assert(os.path.exists(os.path.join(versiondir, '0', 'foobar', 'foo')))
        assert_equal(open(foo, 'rb').read(), open(os.path.join(versiondir, '0', 'foobar', 'foo'), 'rb').read())
        assert_equal(978307200.0, os.path.getmtime(os.path.join(versiondir, '0', 'foobar', 'foo')))
        assert_equal(0o644, os.stat(os.path.join(versiondir, '0', 'foobar', 'foo')).st_mode & 0o000777)

        assert(os.path.exists(os.path.join(versiondir, '1', 'foobar', 'bar')))
        assert_equal(978307200.0, os.path.getmtime(os.path.join(versiondir, '1', 'foobar', 'bar')))
        assert_equal(open(bar, 'rb').read(), open(os.path.join(versiondir, '1', 'foobar', 'bar'), 'rb').read())
        assert_equal(0o7755, os.stat(os.path.join(versiondir, '1', 'foobar', 'bar')).st_mode & 0o007777)

        #check symlink
        assert(os.path.exists(os.path.join(versiondir, '2', 'foobar', 'symlink')))
        assert_equal('foo', os.readlink(os.path.join(versiondir, '2', 'foobar', 'symlink')))

        shutil.rmtree(xdir)
Ejemplo n.º 31
0
 def test_cli_extract(self):
     a = mkstemppath()
     foo = os.path.join('foobar', 'foo')
     bar = os.path.join('foobar', 'bar')
     sparchive.cli.main(["addversion", a, foo])
     sparchive.cli.main(["addversion", a, bar])
     xdir = mkdtemp()
     olddir = os.getcwd()
     try:
         os.chdir(os.path.join(xdir))
         sparchive.cli.main(["extract", a])
     finally:
         os.chdir(olddir)
     xdir = os.path.join(xdir, os.path.basename(a))
     assert (os.path.exists(os.path.join(xdir, '0', 'foobar', 'foo')))
     assert_equal(
         open(foo, 'rb').read(),
         open(os.path.join(xdir, '0', 'foobar', 'foo'), 'rb').read())
     assert (os.path.exists(os.path.join(xdir, '1', 'foobar', 'bar')))
     assert_equal(
         open(bar, 'rb').read(),
         open(os.path.join(xdir, '1', 'foobar', 'bar'), 'rb').read())
Ejemplo n.º 32
0
 def test_add_dir(self):
     dir = 'foobar'
     apath = mkstemppath()
     a = Archive(apath, rzip)
     a.add_version([dir])
     TestArchive.assert_ziprz_filenames(apath, ["versions/0/foobar/", "versions/0/foobar/symlink", "versions/0/foobar/bar", "versions/0/foobar/foo"])
Ejemplo n.º 33
0
 def test_mkstemppath(self):
     n = mkstemppath()
     assert_false(path.exists(n))
Ejemplo n.º 34
0
 def test_uncompress_file(self):
     p = os.path.join('tests', 'fixtures', 'foobar', 'foo')
     prz = mkstemppath()
     pr2 = mkstemppath()
     xz.compress(p, prz)
     xz.uncompress(prz, pr2)
Ejemplo n.º 35
0
    def test_extract(self):
        foo = os.path.join('foobar', 'foo')
        bar = os.path.join('foobar', 'bar')
        os.utime(foo, (978307200, 978307200))
        os.utime(bar, (978307200, 978307200))
        os.chmod(foo, 0o644)
        os.chmod(bar, 0o7755)
        apath = mkstemppath()
        a = Archive(apath, rzip)
        a.add_version([foo])
        a.add_version([bar])
        a.add_version(['foobar'])
        xdir = mkdtemp()
        a.extract(xdir, 0)
        versiondir = os.path.join(xdir, os.path.basename(apath))
        assert (os.path.exists(os.path.join(versiondir, '0', 'foobar', 'foo')))
        assert_equal(
            open(foo, 'rb').read(),
            open(os.path.join(versiondir, '0', 'foobar', 'foo'), 'rb').read())

        a.extract(xdir, 1)
        assert (os.path.exists(os.path.join(versiondir, '1', 'foobar', 'bar')))
        assert_equal(
            open(bar, 'rb').read(),
            open(os.path.join(versiondir, '1', 'foobar', 'bar'), 'rb').read())
        shutil.rmtree(xdir)

        # now extract all versions
        xdir = mkdtemp()
        versiondir = os.path.join(xdir, os.path.basename(apath))
        a.extract(xdir)
        assert (os.path.exists(os.path.join(versiondir, '0', 'foobar', 'foo')))
        assert_equal(
            open(foo, 'rb').read(),
            open(os.path.join(versiondir, '0', 'foobar', 'foo'), 'rb').read())
        assert_equal(
            978307200.0,
            os.path.getmtime(os.path.join(versiondir, '0', 'foobar', 'foo')))
        assert_equal(
            0o644,
            os.stat(os.path.join(versiondir, '0', 'foobar', 'foo')).st_mode
            & 0o000777)

        assert (os.path.exists(os.path.join(versiondir, '1', 'foobar', 'bar')))
        assert_equal(
            978307200.0,
            os.path.getmtime(os.path.join(versiondir, '1', 'foobar', 'bar')))
        assert_equal(
            open(bar, 'rb').read(),
            open(os.path.join(versiondir, '1', 'foobar', 'bar'), 'rb').read())
        assert_equal(
            0o7755,
            os.stat(os.path.join(versiondir, '1', 'foobar', 'bar')).st_mode
            & 0o007777)

        #check symlink
        assert (os.path.exists(
            os.path.join(versiondir, '2', 'foobar', 'symlink')))
        assert_equal(
            'foo',
            os.readlink(os.path.join(versiondir, '2', 'foobar', 'symlink')))

        shutil.rmtree(xdir)
Ejemplo n.º 36
0
 def test_mkstemppath(self):
     n = mkstemppath()
     assert_false(path.exists(n))
Ejemplo n.º 37
0
 def test_cli_addversion(self):
     a = mkstemppath()
     os.chdir('foobar')
     sparchive.cli.main(['addversion', a, 'foo', 'bar'])
     CliTest.assert_ziprz_filenames(a, ['versions/0/foo', 'versions/0/bar'])
Ejemplo n.º 38
0
 def __enter__(self):
     self.uncomp_path = mkstemppath()
     if (os.path.exists(self.xz_path)):
         uncompress(self.xz_path, self.uncomp_path)
     return self.uncomp_path
Ejemplo n.º 39
0
 def __enter__(self):
     self.uncomp_path = mkstemppath()
     if (os.path.exists(self.xz_path)):
         uncompress(self.xz_path, self.uncomp_path)
     return self.uncomp_path
Ejemplo n.º 40
0
 def test_cli_addversion(self):
     a = mkstemppath()
     os.chdir('foobar')
     sparchive.cli.main(['addversion', a, 'foo', 'bar'])
     CliTest.assert_ziprz_filenames(a, ['versions/0/foo', 'versions/0/bar'])