Commit 50f19248 authored by Seblu's avatar Seblu
Browse files

Improve build function

- Takes config object
- Display build and commit duration
- Improve error reporting
parent d1b94015
Loading
Loading
Loading
Loading
+39 −23
Original line number Diff line number Diff line
@@ -133,38 +133,54 @@ class LocalPackage(dict):
	lastmodified = property(lambda x: LocalPackage.getlastX(x, "lastmodified"),
						 lambda x, y: LocalPackage.setlastX(x, "lastmodified", y))

def build(build_cmd, commit_cmd, localpkg, aurpkg):
	info("Getting last AUR version")
def build(config, localpkg, aurpkg):
	'''
	Build and commit a package
	Notify if succeeded
	'''
	# find build dir
	build_dir = TemporaryDirectory()
	debug("Build dir is %s" % build_dir.name)
	# extract tarball
	debug("Extracting aur tarball")
	aurpkg.extract(build_dir.name)
	# timestamping
	now = time()
	# log files
	fp = join(localpkg.logdir, strftime("build-%Y-%m-%d-%H-%M-%S.log", localtime(time())))
	debug("Build log file path: %s" % fp)
	fd = open(fp, "w")
	cwd = getcwd()
	with open(fp, "w") as fd:
		try:
			cwd = getcwd()
			chdir("%s/%s" % (build_dir.name, aurpkg.name))

			# build
			info("Starting build command")
		check_call(build_cmd, stdin=DEVNULL, stdout=fd, stderr=fd, shell=True, close_fds=True)
			start_time = time()
			try:
				check_call(config["build_cmd"], stdin=DEVNULL, stdout=fd,
					stderr=fd, shell=True, close_fds=True)
			except Exception as exp:
				error("Build command failure: %s" % exp)
				raise
			info("Build duration: %ss" % (time() - start_time))

		if commit_cmd is not None:
			# commit
			if "commit_cmd" in config:
				info("Starting commit command")
			check_call(commit_cmd, stdin=DEVNULL, stdout=fd, stderr=fd, shell=True, close_fds=True)
				start_time = time()
				try:
					check_call(config["commit_cmd"], stdin=DEVNULL, stdout=fd,
						stderr=fd, shell=True, close_fds=True)
				except Exception as exp:
					error("Commit command failure: %s" % exp)
					raise
				info("Commit duration: %ss" % (time() - start_time))

		localpkg.lastbuild = now
			# register success
			localpkg.lastbuild = time()
			localpkg.lastmodified = aurpkg.lastmodified
	except Exception as exp:
		error("Build failure: %s" % exp)
		finally:
			chdir(cwd)
		fd.close()


def event_loop(packages, timeout):
	'''
@@ -176,7 +192,7 @@ def event_loop(packages, timeout):
				continue
			info("[%s]" % name)
			if "build_cmd" not in config:
				error("Build_cmd is missing in config file")
				error("build_cmd is missing in config file")
				continue
			try:
				aur = AURPackage(name)
@@ -198,7 +214,7 @@ def event_loop(packages, timeout):
			# build new aur version
			if aur.lastmodified > local.lastmodified:
				info("New version available: %s" % aur.version)
				build(config["build_cmd"], config.get("commit_cmd"), local, aur)
				build(config, local, aur)
			# re-build package when force time is passed
			elif "force" in config:
				if config["force"].isdigit() is False:
@@ -211,7 +227,7 @@ def event_loop(packages, timeout):
				debug("Force at: %ss, currently: %ss" % (force, now - local.lastbuild))
				if local.lastbuild + force <= now:
					info("Forced update")
					build(config["build_cmd"], config.get("commit_cmd"), local, aur)
					build(config, local, aur)
			else:
				info("Nothing to do")
		# night is coming, save cache
+4 −3
Original line number Diff line number Diff line
[DEFAULT]
build_cmd = makepkg
notify = seblu@seblu.net

[python-sjrpc]
maintainer = seblu

[virtualbox-ext-oracle]
maintainer = seblu
@@ -7,6 +11,3 @@ maintainer = seblu
[python-i3-git]
maintainer = Alad
force = 2592000 #30days

[python-sjrpc]
maintainer = seblu