示例#1
0
    def copy_dir(self, path, ex_dir):
        """ Copies directory tree and adds command to
            prep macro """

        prep = Command("cp -rf " + path + " " + ex_dir)
        prep.execute()
        self.prep.append(str(prep))
示例#2
0
文件: __init__.py 项目: FLuptak/rpg
 def create_archive(self):
     """ Creates archive (archvie_path) from Source folder """
     self.spec.Source = self.spec.Name + "-" + self.spec.Version + ".tar.gz"
     _tar = Command("tar zcf " + str(self.archive_path) +
                    " -C " + str(self.extracted_dir) +
                    " . --transform='s/^\./" +
                    self.spec.Name + "-" + self.spec.Version + "/g'")
     _tar.execute()
     logging.debug(str(_tar))
示例#3
0
 def create_archive(self):
     """ Creates archive (archvie_path) from Source folder """
     self.spec.Source = self.spec.Name + "-" + self.spec.Version + ".tar.gz"
     _tar = Command("tar zcf " + path_to_str(self.archive_path) + " -C " +
                    path_to_str(self.extracted_dir) +
                    " . --transform='s/^\./" + self.spec.Name + "-" +
                    self.spec.Version + "/g'")
     _tar.execute()
     logging.debug(str(_tar))
示例#4
0
    def test_command_execute_from(self):
        cmd = Command("pwd\ncd c 2>/dev/null\npwd")
        output = cmd.execute(self.test_project_dir)
        path = path_to_str(self.test_project_dir.resolve())
        expected = "%s\n%s/c\n" % (path, path)
        self.assertEqual(expected, output)

        # doesn't add 'cd work_dir' during execute to command lines
        cur_dir = Path('.')
        with self.assertRaises(subprocess.CalledProcessError) as ctx:
            cmd.execute(cur_dir)
        expected = "Command '['/bin/sh', '-c', 'cd %s "\
                   "&& pwd && cd c 2>/dev/null && pwd']' "\
                   "returned non-zero exit status 1"\
                   % path_to_str(cur_dir.resolve())
        self.assertEqual(expected, str(ctx.exception))
示例#5
0
    def test_command_execute_from(self):
        cmd = Command("pwd\ncd c 2>/dev/null\npwd")
        output = cmd.execute(self.test_project_dir)
        path = path_to_str(self.test_project_dir.resolve())
        expected = "%s\n%s/c\n" % (path, path)
        self.assertEqual(expected, output)

        # doesn't add 'cd work_dir' during execute to command lines
        cur_dir = Path('.')
        with self.assertRaises(subprocess.CalledProcessError) as ctx:
            cmd.execute(cur_dir)
        expected = "Command '['/bin/sh', '-c', 'cd %s "\
                   "&& pwd && cd c 2>/dev/null && pwd']' "\
                   "returned non-zero exit status 1"\
                   % path_to_str(cur_dir.resolve())
        self.assertEqual(expected, str(ctx.exception))
示例#6
0
    def extract(self, arch, extract, compr):
        """ Extracts files from archive """

        prep = Command()
        if compr[0] == "tar":
            tar_compr = ""
            if compr[1] == "xz":
                tar_compr = "J"
            elif compr[1] == "gz":
                tar_compr = "z"
            elif compr[1] == "bz2":
                tar_compr = "j"
            elif compr[1] == "lz":
                tar_compr = "--lzip "
            elif compr[1] == "xz":
                tar_compr = "z"
            elif compr[1] == "lzma":
                tar_compr = "--lzma "
            else:
                raise SystemExit("Internal error: Unknown compression \
                    method: " + compr)
            prep.append("tar " + tar_compr + "xf " +
                        arch + " -C " + extract)
        elif compr[0] == "tgz":
            prep.append("tar xzf " + arch + " -C " + extract)
        elif compr[0] == "tbz2":
            prep.append("tar xjf " + arch + " -C " + extract)
        elif compr[0] == "zip":
            prep.append("unzip " + arch + " -d " + extract)
        elif compr[0] == "rar":
            prep.append("unrar x " + arch + " " + extract)
        elif compr[0] == "7z":
            prep.append("7z x " + arch + " -o " + extract)
        else:
            raise SystemExit("Internal error: Unknown compression \
                method: " + compr[0] + "." + compr[1])
        prep.execute()
        self.prep.append(str(prep))
示例#7
0
 def test_execute(self):
     cmd = Command("echo bla")
     output = cmd.execute()
     self.assertEqual("bla\n", output)
示例#8
0
 def test_execute(self):
     cmd = Command("echo bla")
     output = cmd.execute()
     self.assertEqual("bla\n", output)