1
from job import Action, LoggedActions
9
def __init__(self, app_name, local_file, log):
10
self.local_file = local_file
12
self.app_name = app_name
13
self.extract_path = os.path.join(defs.get_path("tarballs"),
18
def rename_tarball(self):
19
if not self.local_file:
22
if self.local_file.endswith(".tar_1.gz"):
23
new_tarball = re.sub(".tar_1.gz", ".tar.gz", self.local_file)
24
if self.local_file.endswith(".tgz"):
25
new_tarball = re.sub(".tgz", ".tar.gz", self.local_file)
28
actions = LoggedActions()
29
actions.add(Action(["mv", self.local_file, new_tarball],
31
self.log.add(logged_actions=actions)
32
if not self.log.success:
33
self.log.add(error="Renaming '%s' to '%s' failed." % \
34
(self.local_file, new_tarball))
36
self.local_file = new_tarball
38
def extract(self, log):
39
if not self.local_file:
42
if os.path.exists(self.extract_path):
43
actions = LoggedActions()
44
actions.add(Action(["rm", "-r", self.extract_path],
46
os.makedirs(self.extract_path)
48
actions = LoggedActions()
49
if self.local_file.endswith(".tar.gz"):
50
cmd = ["tar", "xfz", self.files[0], "-C", self.extract_path]
51
elif self.local_file.endswith(".tar"):
52
cmd = ["tar", "xf", self.files[0], "-C", self.extract_path]
53
elif self.local_file.endswith(".zip"):
54
cmd = ["unzip", self.local_file, "-d", self.extract_path]
57
actions.add(Action(cmd, expected_retcode=0))
58
self.log.add(logged_actions=actions)
60
log.add(error="Unpacking of %s failed." % self.local_file)
62
def find_dsc_file(self):
63
for dirpath, dirnames, filenames in os.walk(self.extract_path):
64
dsc_files = filter(lambda a: a.endswith(".dsc"), filenames)
66
self.dsc_file = os.path.join(dirpath, dsc_files[0])