Ejemplo n.º 1
0
 def test_zip_export_content_filter_tree(self):
     self.make_tree()
     export.export(self.filter_tree, 'out.zip')
     zipf = zipfile.ZipFile('out.zip', 'r')
     self.assertEquals(
         'HELLO WORLD',
         zipf.read('out/hello'))
Ejemplo n.º 2
0
    def test_files_same_timestamp(self):
        builder = self.make_branch_builder('source')
        builder.start_series()
        builder.build_snapshot(None, None, [
            ('add', ('', 'root-id', 'directory', '')),
            ('add', ('a', 'a-id', 'file', 'content\n'))])
        builder.build_snapshot(None, None, [
            ('add', ('b', 'b-id', 'file', 'content\n'))])
        builder.finish_series()
        b = builder.get_branch()
        b.lock_read()
        self.addCleanup(b.unlock)
        tree = b.basis_tree()
        orig_iter_files_bytes = tree.iter_files_bytes

        # Make iter_files_bytes slower, so we provoke mtime skew
        def iter_files_bytes(to_fetch):
            for thing in orig_iter_files_bytes(to_fetch):
                yield thing
                time.sleep(1)
        tree.iter_files_bytes = iter_files_bytes
        export.export(tree, 'target', format='dir')
        t = self.get_transport('target')
        st_a = t.stat('a')
        st_b = t.stat('b')
        # All files must be given the same mtime.
        self.assertEqual(st_a.st_mtime, st_b.st_mtime)
Ejemplo n.º 3
0
    def test_files_same_timestamp(self):
        builder = self.make_branch_builder('source')
        builder.start_series()
        builder.build_snapshot(None, None, [
            ('add', ('', 'root-id', 'directory', '')),
            ('add', ('a', 'a-id', 'file', 'content\n'))])
        builder.build_snapshot(None, None, [
            ('add', ('b', 'b-id', 'file', 'content\n'))])
        builder.finish_series()
        b = builder.get_branch()
        b.lock_read()
        self.addCleanup(b.unlock)
        tree = b.basis_tree()
        orig_iter_files_bytes = tree.iter_files_bytes

        # Make iter_files_bytes slower, so we provoke mtime skew
        def iter_files_bytes(to_fetch):
            for thing in orig_iter_files_bytes(to_fetch):
                yield thing
                time.sleep(1)
        tree.iter_files_bytes = iter_files_bytes
        export.export(tree, 'target', format='dir')
        t = self.get_transport('target')
        st_a = t.stat('a')
        st_b = t.stat('b')
        # All files must be given the same mtime.
        self.assertEqual(st_a.st_mtime, st_b.st_mtime)
Ejemplo n.º 4
0
 def test_symlink(self):
     self.requireFeature(features.SymlinkFeature)
     wt = self.make_branch_and_tree('.')
     os.symlink('source', 'link')
     wt.add(['link'])
     export.export(wt, 'target', format="dir")
     self.assertPathExists('target/link')
Ejemplo n.º 5
0
 def test_symlink(self):
     self.requireFeature(features.SymlinkFeature)
     wt = self.make_branch_and_tree('.')
     os.symlink('source', 'link')
     wt.add(['link'])
     export.export(wt, 'target', format="dir")
     self.assertPathExists('target/link')
Ejemplo n.º 6
0
 def test_tgz_ignores_dest_path(self):
     # The target path should not be a part of the target file.
     # (bug #102234)
     wt = self.make_branch_and_tree('.')
     self.build_tree(['a'])
     wt.add(["a"])
     wt.commit("1")
     os.mkdir("testdir1")
     os.mkdir("testdir2")
     export.export(wt, 'testdir1/target.tar.gz', format="tgz",
         per_file_timestamps=True)
     export.export(wt, 'testdir2/target.tar.gz', format="tgz",
         per_file_timestamps=True)
     file1 = open('testdir1/target.tar.gz', 'r')
     self.addCleanup(file1.close)
     file2 = open('testdir1/target.tar.gz', 'r')
     self.addCleanup(file2.close)
     content1 = file1.read()
     content2 = file2.read()
     self.assertEqualDiff(content1, content2)
     # the gzip module doesn't have a way to read back to the original
     # filename, but it's stored as-is in the tarfile.
     self.assertFalse("testdir1" in content1)
     self.assertFalse("target.tar.gz" in content1)
     self.assertTrue("target.tar" in content1)
Ejemplo n.º 7
0
def bundle(dir):
    branch = Branch.open(dir)
    output_zip = '%s_%d.zip'%(dir, branch.revno())
    temp_dir = '/tmp/output_%d'%(branch.revno())

    #Empty the temp_dir
    shutil.rmtree(temp_dir, True)

    #export the bzr repository to temp_dir
    export(branch.basis_tree(), temp_dir)

    #Compile the source code in templocation
    compileall.compile_dir(temp_dir)

    #Remove the .py files from the exported directory.
    clean_path(temp_dir, [".py"])
    
    #create a HISTORY file in the temp_dir
    show_log(branch, ShortLogFormatter(open(temp_dir+os.sep+'HISTORY', 'w')))

    #create a VERSION file in temp_dir
    f = open(temp_dir+os.sep+'VERSION', 'w')
    f.write(str(branch.revno()))
    f.close()

    #write to zip
    z.toZip(temp_dir, output_zip)
Ejemplo n.º 8
0
 def test_tgz_ignores_dest_path(self):
     # The target path should not be a part of the target file.
     # (bug #102234)
     wt = self.make_branch_and_tree('.')
     self.build_tree(['a'])
     wt.add(["a"])
     wt.commit("1")
     os.mkdir("testdir1")
     os.mkdir("testdir2")
     export.export(wt, 'testdir1/target.tar.gz', format="tgz",
         per_file_timestamps=True)
     export.export(wt, 'testdir2/target.tar.gz', format="tgz",
         per_file_timestamps=True)
     file1 = open('testdir1/target.tar.gz', 'r')
     self.addCleanup(file1.close)
     file2 = open('testdir1/target.tar.gz', 'r')
     self.addCleanup(file2.close)
     content1 = file1.read()
     content2 = file2.read()
     self.assertEqualDiff(content1, content2)
     # the gzip module doesn't have a way to read back to the original
     # filename, but it's stored as-is in the tarfile.
     self.assertFalse("testdir1" in content1)
     self.assertFalse("target.tar.gz" in content1)
     self.assertTrue("target.tar" in content1)
Ejemplo n.º 9
0
 def test_tbz2(self):
     wt = self.make_branch_and_tree('.')
     self.build_tree(['a'])
     wt.add(["a"])
     wt.commit("1")
     export.export(wt, 'target.tar.bz2', format="tbz2")
     tf = tarfile.open('target.tar.bz2')
     self.assertEqual(["target/a"], tf.getnames())
Ejemplo n.º 10
0
 def test_missing_file(self):
     self.build_tree(['a/', 'a/b', 'a/c'])
     wt = self.make_branch_and_tree('.')
     wt.add(['a', 'a/b', 'a/c'])
     os.unlink('a/c')
     export.export(wt, 'target', format="dir")
     self.assertPathExists('target/a/b')
     self.assertPathDoesNotExist('target/a/c')
Ejemplo n.º 11
0
 def prepare_symlink_export(self):
     self.requireFeature(features.SymlinkFeature)
     work_a = self.make_branch_and_tree('wta')
     os.symlink('target', 'wta/link')
     work_a.add('link', 'link-id')
     work_a.commit('add link')
     tree_a = self.workingtree_to_test_tree(work_a)
     export(tree_a, 'output', self.exporter)
Ejemplo n.º 12
0
 def test_missing_file(self):
     self.build_tree(['a/', 'a/b', 'a/c'])
     wt = self.make_branch_and_tree('.')
     wt.add(['a', 'a/b', 'a/c'])
     os.unlink('a/c')
     export.export(wt, 'target', format="dir")
     self.assertPathExists('target/a/b')
     self.assertPathDoesNotExist('target/a/c')
Ejemplo n.º 13
0
 def test_tar_export_content_filter_tree(self):
     # TODO: this could usefully be run generically across all exporters.
     self.make_tree()
     export.export(self.filter_tree, "out.tgz")
     ball = tarfile.open("out.tgz", "r:gz")
     self.assertEquals(
         'HELLO WORLD',
         ball.extractfile('out/hello').read())
Ejemplo n.º 14
0
 def test_tbz2(self):
     wt = self.make_branch_and_tree('.')
     self.build_tree(['a'])
     wt.add(["a"])
     wt.commit("1")
     export.export(wt, 'target.tar.bz2', format="tbz2")
     tf = tarfile.open('target.tar.bz2')
     self.assertEquals(["target/a"], tf.getnames())
Ejemplo n.º 15
0
 def prepare_symlink_export(self):
     self.requireFeature(features.SymlinkFeature)
     work_a = self.make_branch_and_tree('wta')
     os.symlink('target', 'wta/link')
     work_a.add('link', 'link-id')
     work_a.commit('add link')
     tree_a = self.workingtree_to_test_tree(work_a)
     export(tree_a, 'output', self.exporter)
Ejemplo n.º 16
0
 def prepare_export(self):
     work_a = self.make_branch_and_tree('wta')
     self.build_tree_contents(
         [('wta/file', 'a\nb\nc\nd\n'), ('wta/dir', '')])
     work_a.add('file', 'file-id')
     work_a.add('dir', 'dir-id')
     work_a.commit('add file')
     tree_a = self.workingtree_to_test_tree(work_a)
     export(tree_a, 'output', self.exporter)
Ejemplo n.º 17
0
 def prepare_export(self):
     work_a = self.make_branch_and_tree('wta')
     self.build_tree_contents([('wta/file', 'a\nb\nc\nd\n'),
                               ('wta/dir', '')])
     work_a.add('file', 'file-id')
     work_a.add('dir', 'dir-id')
     work_a.commit('add file')
     tree_a = self.workingtree_to_test_tree(work_a)
     export(tree_a, 'output', self.exporter)
Ejemplo n.º 18
0
 def test_empty_subdir(self):
     self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c'])
     wt = self.make_branch_and_tree('source')
     wt.add(['a', 'b', 'b/c'])
     wt.commit('1')
     self.build_tree(['target/'])
     export.export(wt, 'target', format="dir", subdir='')
     self.assertPathExists('target/a')
     self.assertPathExists('target/b')
     self.assertPathExists('target/b/c')
Ejemplo n.º 19
0
 def test_lzma(self):
     self.requireFeature(features.lzma)
     import lzma
     wt = self.make_branch_and_tree('.')
     self.build_tree(['a'])
     wt.add(["a"])
     wt.commit("1")
     export.export(wt, 'target.tar.lzma', format="tlzma")
     tf = tarfile.open(fileobj=lzma.LZMAFile('target.tar.lzma'))
     self.assertEquals(["target/a"], tf.getnames())
Ejemplo n.º 20
0
 def test_existing_single_file(self):
     self.build_tree([
         'dir1/', 'dir1/dir2/', 'dir1/first', 'dir1/dir2/second'])
     wtree = self.make_branch_and_tree('dir1')
     wtree.add(['dir2', 'first', 'dir2/second'])
     wtree.commit('1')
     export.export(wtree, 'target1', format='dir', subdir='first')
     self.assertPathExists('target1/first')
     export.export(wtree, 'target2', format='dir', subdir='dir2/second')
     self.assertPathExists('target2/second')
Ejemplo n.º 21
0
    def write_tree(self, rev_tree, file_id_list):
        """
    Write the whole revision tree contents to our temporary directory. 
    The directory will be removed when the ScratchArea is deleted.
    """
        osutils.delete_any(self.path)
        export.export(rev_tree, self.path, format='dir')
        self._make_readonly()

        return
Ejemplo n.º 22
0
    def write_tree(self, rev_tree, file_id_list):
        """
    Write the whole revision tree contents to our temporary directory. 
    The directory will be removed when the ScratchArea is deleted.
    """
        osutils.delete_any(self.path)
        export.export(rev_tree, self.path, format="dir")
        self._make_readonly()

        return
Ejemplo n.º 23
0
 def test_empty_subdir(self):
     self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c'])
     wt = self.make_branch_and_tree('source')
     wt.add(['a', 'b', 'b/c'])
     wt.commit('1')
     self.build_tree(['target/'])
     export.export(wt, 'target', format="dir", subdir='')
     self.assertPathExists('target/a')
     self.assertPathExists('target/b')
     self.assertPathExists('target/b/c')
Ejemplo n.º 24
0
 def test_existing_single_file(self):
     self.build_tree([
         'dir1/', 'dir1/dir2/', 'dir1/first', 'dir1/dir2/second'])
     wtree = self.make_branch_and_tree('dir1')
     wtree.add(['dir2', 'first', 'dir2/second'])
     wtree.commit('1')
     export.export(wtree, 'target1', format='dir', subdir='first')
     self.assertPathExists('target1/first')
     export.export(wtree, 'target2', format='dir', subdir='dir2/second')
     self.assertPathExists('target2/second')
Ejemplo n.º 25
0
 def test_lzma(self):
     self.requireFeature(features.lzma)
     import lzma
     wt = self.make_branch_and_tree('.')
     self.build_tree(['a'])
     wt.add(["a"])
     wt.commit("1")
     export.export(wt, 'target.tar.lzma', format="tlzma")
     tf = tarfile.open(fileobj=lzma.LZMAFile('target.tar.lzma'))
     self.assertEqual(["target/a"], tf.getnames())
Ejemplo n.º 26
0
 def test_per_file_timestamps(self):
     tree = self.make_branch_and_tree('.')
     self.build_tree_contents([('har', 'foo')])
     tree.add('har')
     # Earliest allowable date on FAT32 filesystems is 1980-01-01
     timestamp = 347151600
     tree.commit('setup', timestamp=timestamp)
     export.export(tree.basis_tree(), 'test.zip', format='zip',
         per_file_timestamps=True)
     zfile = zipfile.ZipFile('test.zip')
     info = zfile.getinfo("test/har")
     self.assertEquals(time.localtime(timestamp)[:6], info.date_time)
Ejemplo n.º 27
0
 def test_per_file_timestamps(self):
     tree = self.make_branch_and_tree('.')
     self.build_tree_contents([('har', 'foo')])
     tree.add('har')
     # Earliest allowable date on FAT32 filesystems is 1980-01-01
     timestamp = 347151600
     tree.commit('setup', timestamp=timestamp)
     export.export(tree.basis_tree(), 'test.zip', format='zip',
         per_file_timestamps=True)
     zfile = zipfile.ZipFile('test.zip')
     info = zfile.getinfo("test/har")
     self.assertEqual(time.localtime(timestamp)[:6], info.date_time)
Ejemplo n.º 28
0
 def test_subdir_files_per_timestamps(self):
     builder = self.make_branch_builder('source')
     builder.start_series()
     foo_time = time.mktime((1999, 12, 12, 0, 0, 0, 0, 0, 0))
     builder.build_snapshot(None, None, [
         ('add', ('', 'root-id', 'directory', '')),
         ('add', ('subdir', 'subdir-id', 'directory', '')),
         ('add', ('subdir/foo.txt', 'foo-id', 'file', 'content\n'))],
         timestamp=foo_time)
     builder.finish_series()
     b = builder.get_branch()
     b.lock_read()
     self.addCleanup(b.unlock)
     tree = b.basis_tree()
     export.export(tree, 'target', format='dir', subdir='subdir',
         per_file_timestamps=True)
     t = self.get_transport('target')
     self.assertEquals(foo_time, t.stat('foo.txt').st_mtime)
Ejemplo n.º 29
0
 def test_subdir_files_per_timestamps(self):
     builder = self.make_branch_builder('source')
     builder.start_series()
     foo_time = time.mktime((1999, 12, 12, 0, 0, 0, 0, 0, 0))
     builder.build_snapshot(None, None, [
         ('add', ('', 'root-id', 'directory', '')),
         ('add', ('subdir', 'subdir-id', 'directory', '')),
         ('add', ('subdir/foo.txt', 'foo-id', 'file', 'content\n'))],
         timestamp=foo_time)
     builder.finish_series()
     b = builder.get_branch()
     b.lock_read()
     self.addCleanup(b.unlock)
     tree = b.basis_tree()
     export.export(tree, 'target', format='dir', subdir='subdir',
         per_file_timestamps=True)
     t = self.get_transport('target')
     self.assertEqual(foo_time, t.stat('foo.txt').st_mtime)
Ejemplo n.º 30
0
 def test_files_per_file_timestamps(self):
     builder = self.make_branch_builder('source')
     builder.start_series()
     # Earliest allowable date on FAT32 filesystems is 1980-01-01
     a_time = time.mktime((1999, 12, 12, 0, 0, 0, 0, 0, 0))
     b_time = time.mktime((1980, 01, 01, 0, 0, 0, 0, 0, 0))
     builder.build_snapshot(None, None, [
         ('add', ('', 'root-id', 'directory', '')),
         ('add', ('a', 'a-id', 'file', 'content\n'))],
         timestamp=a_time)
     builder.build_snapshot(None, None, [
         ('add', ('b', 'b-id', 'file', 'content\n'))],
         timestamp=b_time)
     builder.finish_series()
     b = builder.get_branch()
     b.lock_read()
     self.addCleanup(b.unlock)
     tree = b.basis_tree()
     export.export(tree, 'target', format='dir', per_file_timestamps=True)
     t = self.get_transport('target')
     self.assertEqual(a_time, t.stat('a').st_mtime)
     self.assertEqual(b_time, t.stat('b').st_mtime)
Ejemplo n.º 31
0
 def test_files_per_file_timestamps(self):
     builder = self.make_branch_builder('source')
     builder.start_series()
     # Earliest allowable date on FAT32 filesystems is 1980-01-01
     a_time = time.mktime((1999, 12, 12, 0, 0, 0, 0, 0, 0))
     b_time = time.mktime((1980, 01, 01, 0, 0, 0, 0, 0, 0))
     builder.build_snapshot(None, None, [
         ('add', ('', 'root-id', 'directory', '')),
         ('add', ('a', 'a-id', 'file', 'content\n'))],
         timestamp=a_time)
     builder.build_snapshot(None, None, [
         ('add', ('b', 'b-id', 'file', 'content\n'))],
         timestamp=b_time)
     builder.finish_series()
     b = builder.get_branch()
     b.lock_read()
     self.addCleanup(b.unlock)
     tree = b.basis_tree()
     export.export(tree, 'target', format='dir', per_file_timestamps=True)
     t = self.get_transport('target')
     self.assertEqual(a_time, t.stat('a').st_mtime)
     self.assertEqual(b_time, t.stat('b').st_mtime)
Ejemplo n.º 32
0
 def test_empty(self):
     wt = self.make_branch_and_tree('.')
     export.export(wt, 'target', format="dir")
     self.assertEquals([], os.listdir("target"))
Ejemplo n.º 33
0
    def run(self, command, target, source, proposal):
        try:
            self.verify_command = target.config.verify_command
        except AttributeError:
            # This can be killed two versions after 0.4, whatever version that
            # is.
            try:
                self.verify_command = target.config.test_command
                self.logger.warn(
                    'test_command config setting is deprecated. '
                    'Please use verify_command instead.')
            except AttributeError:
                return

        self.proposal = proposal

        self.logger.debug('Running test command: %s' % self.verify_command)
        cwd = os.getcwd()
        # Export the changes to a temporary directory, and run the command
        # there, to prevent possible abuse of running commands in the tree.
        temp_path = '/tmp/tarmac'
        if not os.path.exists(temp_path):
            os.makedirs(temp_path)
        export_dest = tempfile.mkdtemp(prefix=temp_path + '/branch.')
        export(target.tree, export_dest, None, None, None, filtered=False,
               per_file_timestamps=False)
        os.chdir(export_dest)

        proc = subprocess.Popen(self.verify_command,
                                shell=True,
                                stdin=subprocess.PIPE,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        proc.stdin.close()
        stdout = tempfile.TemporaryFile()
        stderr = tempfile.TemporaryFile()

        # Do proc.communicate(), but timeout if there's no activity on stdout or
        # stderr for too long.
        open_readers = set([proc.stdout, proc.stderr])

        while open_readers:
            rlist, wlist, xlist = select.select(open_readers, [], [], TIMEOUT)

            if len(rlist) == 0:
                if proc.poll() is not None:
                    break

                self.logger.debug(
                    "Command appears to be hung. There has been no output for"
                    " %d seconds. Sending SIGTERM." % TIMEOUT)
                killem(proc.pid, signal.SIGTERM)
                time.sleep(5)

                if proc.poll() is not None:
                    self.logger.debug("SIGTERM did not work. Sending SIGKILL.")
                    killem(proc.pid, signal.SIGKILL)

                # Drain the subprocess's stdout and stderr.
                out_rest = proc.stdout.read()
                if command.config.debug:
                    sys.stdout.write(out_rest)
                stdout.write(out_rest)

                err_rest = proc.stderr.read()
                if command.config.debug:
                    sys.stderr.write(err_rest)
                stderr.write(err_rest)
                break

            if proc.stdout in rlist:
                chunk = os.read(proc.stdout.fileno(), 1024)
                if chunk == "":
                    open_readers.remove(proc.stdout)
                else:
                    if command.config.debug:
                        sys.stdout.write(chunk)
                    stdout.write(chunk)
                    
            if proc.stderr in rlist:
                chunk = os.read(proc.stderr.fileno(), 1024)
                if chunk == "":
                    open_readers.remove(proc.stderr)
                else:
                    if command.config.debug:
                        sys.stderr.write(chunk)
                    stderr.write(chunk)

        return_code = proc.wait()

        os.chdir(cwd)
        shutil.rmtree(export_dest)
        self.logger.debug('Completed test command: %s' % self.verify_command)

        stdout.seek(0)
        stderr.seek(0)

        if return_code != 0:
            self.do_failed(stdout.read(), stderr.read())
Ejemplo n.º 34
0
 def test_empty(self):
     wt = self.make_branch_and_tree('.')
     export.export(wt, 'target', format="dir")
     self.assertEqual([], os.listdir("target"))
Ejemplo n.º 35
0
 def test_tar_export_content_filter_tree(self):
     # TODO: this could usefully be run generically across all exporters.
     self.make_tree()
     export.export(self.filter_tree, "out.tgz")
     ball = tarfile.open("out.tgz", "r:gz")
     self.assertEqual('HELLO WORLD', ball.extractfile('out/hello').read())
Ejemplo n.º 36
0
 def test_zip_export_content_filter_tree(self):
     self.make_tree()
     export.export(self.filter_tree, 'out.zip')
     zipf = zipfile.ZipFile('out.zip', 'r')
     self.assertEqual('HELLO WORLD', zipf.read('out/hello'))