else:
return datetime.datetime.utcnow() - self.started_at
- @lazy_property
- def logfiles(self):
- logfiles = []
-
- for log in self.db.query("SELECT id FROM logfiles WHERE job_id = %s", self.id):
- log = logs.LogFile(self.backend, log.id)
- log._job = self
-
- logfiles.append(log)
-
- return logfiles
-
def add_file(self, filename):
"""
Add the specified file to this job.
"""
assert os.path.exists(filename)
- if filename.endswith(".log"):
- self._add_file_log(filename)
-
elif filename.endswith(".%s" % PACKAGE_EXTENSION):
# It is not allowed to upload packages on test builds.
if self.test:
return
- self._add_file_package(filename)
+ # Open package (creates entry in the database)
+ pkg = self.backend.packages.create(filename)
- def _add_file_log(self, filename):
- """
- Attach a log file to this job.
- """
- target_dirname = os.path.join(self.build.path, "logs")
+ # Move package to the build directory.
+ pkg.move(os.path.join(self.build.path, self.arch))
- if self.test:
- i = 1
- while True:
- target_filename = os.path.join(target_dirname,
- "test.%s.%s.%s.log" % (self.arch, i, self.uuid))
-
- if os.path.exists(target_filename):
- i += 1
- else:
- break
- else:
- target_filename = os.path.join(target_dirname,
- "build.%s.%s.log" % (self.arch, self.uuid))
-
- # Make sure the target directory exists.
- if not os.path.exists(target_dirname):
- os.makedirs(target_dirname)
-
- # Calculate a SHA512 hash from that file.
- f = open(filename, "rb")
- h = hashlib.sha512()
- while True:
- buf = f.read(BUFFER_SIZE)
- if not buf:
- break
-
- h.update(buf)
- f.close()
-
- # Copy the file to the final location.
- shutil.copy2(filename, target_filename)
-
- # Create an entry in the database.
- self.db.execute("INSERT INTO logfiles(job_id, path, filesize, hash_sha512) \
- VALUES(%s, %s, %s, %s)", self.id, os.path.relpath(target_filename, PACKAGES_DIR),
- os.path.getsize(target_filename), h.hexdigest())
-
- def _add_file_package(self, filename):
- # Open package (creates entry in the database)
- pkg = self.backend.packages.create(filename)
-
- # Move package to the build directory.
- pkg.move(os.path.join(self.build.path, self.arch))
-
- # Attach the package to this job.
- self.db.execute("INSERT INTO jobs_packages(job_id, pkg_id) VALUES(%s, %s)",
- self.id, pkg.id)
+ # Attach the package to this job.
+ self.db.execute("INSERT INTO jobs_packages(job_id, pkg_id) VALUES(%s, %s)",
+ self.id, pkg.id)
@property
def message_recipients(self):