def shell(pkg, **kwargs):
return Pakfire.shell(pkg, **kwargs)
-def dist(pkg, **kwargs):
- return Pakfire.dist(pkg, **kwargs)
+def dist(pkgs, **kwargs):
+ return Pakfire.dist(pkgs, **kwargs)
def provides(patterns, **pakfire_args):
# Create pakfire instance.
b.destroy()
@staticmethod
- def dist(pkg, resultdirs=None, **pakfire_args):
- b = builder.Builder(pkg, **pakfire_args)
+ def dist(pkgs, resultdirs=None, **pakfire_args):
+ # Create a builder with empty package.
+ b = builder.Builder(None, **pakfire_args)
p = b.pakfire
if not resultdirs:
try:
b.prepare()
- b.extract(build_deps=False)
- # Run the actual dist.
- b.dist()
+ for pkg in pkgs:
+ b.pkg = pkg
- # Copy-out all resultfiles
- for resultdir in resultdirs:
- if not resultdir:
- continue
+ b.extract(build_deps=False)
- b.copy_result(resultdir)
+ # Run the actual dist.
+ b.dist()
+
+ # Copy-out all resultfiles
+ for resultdir in resultdirs:
+ if not resultdir:
+ continue
+
+ b.copy_result(resultdir)
+
+ # Cleanup the stuff that the package left.
+ b.cleanup()
finally:
b.destroy()
# The version of the kernel this machine is running.
kernel_version = os.uname()[2]
- def __init__(self, pkg, distro_config=None, build_id=None, **pakfire_args):
+ def __init__(self, pkg=None, distro_config=None, build_id=None, **pakfire_args):
pakfire_args.update({
"builder" : True,
})
self.path = self.pakfire.path
# Open the package.
- if pkg:
- self.pkg = packages.open(self.pakfire, None, pkg)
-
- # Log the package information.
- if not isinstance(self.pkg, packages.Makefile):
- dump = self.pkg.dump(long=True)
- self.log.info(dump)
- else:
- # No package was given.
- self.pkg = None
+ self.pkg = pkg
# XXX need to make this configureable
self.settings = {
self.build_id = build_id
+ def get_pkg(self):
+ return getattr(self, "_pkg", None)
+
+ def set_pkg(self, pkg):
+ if pkg is None:
+ self.__pkg = None
+ return
+
+ self._pkg = packages.open(self.pakfire, None, pkg)
+
+ # Log the package information.
+ if not isinstance(self._pkg, packages.Makefile):
+ dump = self._pkg.dump(long=True)
+ self.log.info(dump)
+
+ assert self.pkg
+
+ pkg = property(get_pkg, set_pkg)
+
@property
def arch(self):
"""
else:
raise FileNotFoundError, pkg
- for pkg in pkgs:
- pakfire.dist(pkg, resultdirs=[self.args.resultdir,],
- **self.pakfire_args)
+ pakfire.dist(pkgs, resultdirs=[self.args.resultdir,],
+ **self.pakfire_args)
class CliRepo(Cli):
# Add sub-commands.
self.sub_commands = self.parser.add_subparsers()
- self.parse_command_build()
self.parse_command_update()
# Finally parse all arguments from the command line and save them.
self.master = server.master.Master()
self.action2func = {
- "build" : self.handle_build,
"update" : self.handle_update,
}
- def parse_command_build(self):
- # Implement the "build" command.
- sub_build = self.sub_commands.add_parser("build",
- help=_("Build one or more packages."))
- sub_build.add_argument("action", action="store_const", const="build")
-
def parse_command_update(self):
# Implement the "update" command.
sub_update = self.sub_commands.add_parser("update",
def handle_update(self):
self.master.update_sources()
- def handle_build(self):
- self.master.build()
-
class CliSlave(Cli):
def __init__(self):
def upload_log_file(self):
pass # XXX TO BE DONE
+
+ def package_add(self, source, pkg):
+ logging.info("Adding package: %s" % pkg.friendly_name)
+
+ # Collect data that is sent to the database...
+ info = {
+ "name" : pkg.name,
+ "epoch" : pkg.epoch,
+ "version" : pkg.version,
+ "release" : pkg.release,
+ "groups" : " ".join(pkg.groups),
+ "maintainer" : pkg.maintainer,
+ "license" : pkg.license,
+ "url" : pkg.url,
+ "summary" : pkg.summary,
+ "description" : pkg.description,
+ "supported_arches" : pkg.supported_arches,
+ "source_id" : source.id,
+ }
+
+ return self.conn.package_add(info)
+
+ def package_remove(self, source, pkg):
+ logging.info("Package '%s' has been removed." % pkg)
#!/usr/bin/python
import logging
+import hashlib
import os
import random
import shutil
from base import MasterSlave
class Source(object):
- def __init__(self, master, id, name, path, targetpath, revision, branch):
+ def __init__(self, master, id, name, url, path, targetpath, revision, branch):
self.master = master
self.id = id
self.name = name
- self.path = path
+ self.url = url
self.targetpath = targetpath
self.revision = revision
self.branch = branch
+ # If the repository is not yet checked out, we create a local clone
+ # from it to work with it.
+ if not os.path.exists(self.path):
+ dirname = os.path.dirname(self.path)
+ basename = os.path.basename(self.path)
+
+ if not os.path.exists(dirname):
+ os.makedirs(dirname)
+
+ self._git("clone %s %s" % (self.url, basename), path=dirname)
+
+ else:
+ # Always refresh the repository to have the recent commits.
+ self._git("fetch")
+
+ @property
+ def path(self):
+ h = hashlib.sha1(self.url)
+
+ # XXX path is to be changed
+ return "/var/cache/pakfire/sources/%s" % h.hexdigest()
+
@property
def pakfire(self):
return self.master.pakfire
- def _git(self, cmd):
- cmd = "cd %s; git %s" % (self.path, cmd)
+ def _git(self, cmd, path=None):
+ if not path:
+ path = self.path
+
+ cmd = "cd %s && git %s" % (path, cmd)
logging.debug("Running command: %s" % cmd)
**pakfire_args)
# Send update to the server.
- self.master.update_revision(self, revision)
+ #self.master.update_revision(self, revision)
def update_files(self, files, **pakfire_args):
rnd = random.randint(0, 1024**2)
return
# XXX This totally ignores the local configuration.
- for pkg in pkgs:
- pakfire.api.dist(pkg, resultdirs=[tmpdir,], **pakfire_args)
+ pakfire.api.dist(pkgs, resultdirs=[tmpdir,], **pakfire_args)
# Create a kind of dummy repository to link the packages against it.
repo = repository.LocalSourceRepository(self.pakfire,
util.rm(tmpdir)
def update(self):
- # Update files from server.
- self._git("fetch")
-
# If there has been no data, yet we need to import all packages
# that are currently checked out.
if not self.revision:
source.update()
- def build(self):
- build = self.conn.build_job(self.hostname)
-
- if not build:
- return
-
- print build
-
- source = Source(self, **build["source"])
-
- source.update_revision((build["revision"], False), build_id=build["id"])
-
def update_revision(self, source, revision):
self.conn.sources_update_revision(source.id, revision)
-
- def package_add(self, source, pkg):
- logging.info("Adding package: %s" % pkg.friendly_name)
-
- # Collect data that is sent to the database...
- info = {
- "name" : pkg.name,
- "epoch" : pkg.epoch,
- "version" : pkg.version,
- "release" : pkg.release,
- "groups" : " ".join(pkg.groups),
- "maintainer" : pkg.maintainer,
- "license" : pkg.license,
- "url" : pkg.url,
- "summary" : pkg.summary,
- "description" : pkg.description,
- "supported_arches" : pkg.supported_arches,
- "source_id" : source.id,
- }
-
- return self.conn.package_add(info)
-
- def package_remove(self, source, pkg):
- logging.info("Package '%s' has been removed." % pkg)
-
import logging
import os
import socket
+import tempfile
import xmlrpclib
import pakfire.api
from pakfire.constants import *
from base import MasterSlave
+from master import Source
class Slave(MasterSlave):
def __init__(self, **pakfire_args):
if not build:
return
- build_id = build["id"]
+ print build
+
+ job_types = {
+ "binary" : self.build_binary_job,
+ "source" : self.build_source_job,
+ }
+
+ build_id = build["id"]
+ build_type = build["type"]
+
+ try:
+ func = job_types[build_type]
+ except KeyError:
+ raise Exception, "Build type not supported: %s" % type
+
+ # Call the function that processes the build and try to catch general
+ # exceptions and report them to the server.
+ # If everything goes okay, we tell this the server, too.
+ try:
+ func(build_id, build)
+
+ except Exception, e:
+ message = "%s: %s" % (e.__class__.__name__, e)
+ self.update_build_status(build_id, "failed", message)
+ raise
+
+ else:
+ self.update_build_status(build_id, "finished")
+
+ def build_binary_job(self, build_id, build):
filename = build["name"]
- data = build["data"].data
+ download = build["download"]
hash1 = build["hash1"]
- # XXX need to find a better temp dir.
- tempfile = os.path.join("/var/tmp", filename)
- resultdir = os.path.join("/var/tmp", build_id)
+ # Create a temporary file and a directory for the resulting files.
+ tmpdir = tempfile.mkdtemp()
+ tmpfile = os.path.join(tmpdir, filename)
+
+ # Get a package grabber and add mirror download capabilities to it.
+ grabber = pakfire.downloader.PackageDownloader()
try:
+ # Download the source.
+ grabber.urlgrab(download, filename=tmpfile)
+
# Check if the download checksum matches.
- if pakfire.util.calc_hash1(data=data) == hash1:
+ if pakfire.util.calc_hash1(tmpfile) == hash1:
print "Checksum matches: %s" % hash1
else:
raise DownloadError, "Download was corrupted"
- # Save the data to a temporary directory.
- f = open(tempfile, "wb")
- f.write(data)
- f.close()
-
# Update the build status on the server.
self.update_build_status(build_id, "running")
# Run the build.
- pakfire.api.build(tempfile, build_id=build_id,
- resultdirs=[resultdir,])
+ pakfire.api.build(tmpfile, build_id=build_id,
+ resultdirs=[tmpdir,])
self.update_build_status(build_id, "uploading")
- for dir, subdirs, files in os.walk(resultdir):
+ for dir, subdirs, files in os.walk(tmpdir):
for file in files:
file = os.path.join(dir, file)
+ if file == tmpfile:
+ continue
pkg = pakfire.packages.open(self.pakfire, None, file)
message = "%s: %s" % (e.__class__.__name__, e)
self.update_build_status(build_id, "dependency_error", message)
- except Exception, e:
- message = "%s: %s" % (e.__class__.__name__, e)
- self.update_build_status(build_id, "failed", message)
- raise
+ finally:
+ # Cleanup the files we created.
+ pakfire.util.rm(tmpdir)
- else:
- self.update_build_status(build_id, "finished")
+ def build_source_job(self, build_id, build):
+ # Update the build status on the server.
+ self.update_build_status(build_id, "running")
- finally:
- #pakfire.util.rm(tempfile)
- pass
+ source = Source(self, **build["source"])
+
+ source.update_revision((build["revision"], False), build_id=build_id)
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2011-04-13 21:57+0200\n"
+"POT-Creation-Date: 2011-04-23 12:44+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
msgid "Is this okay?"
msgstr ""
-#: ../pakfire/builder.py:198
+#: ../pakfire/builder.py:208
#, python-format
msgid "Extracting: %s (source)"
msgstr ""
msgid "Give name(s) of a package(s)."
msgstr ""
-#: ../pakfire/cli.py:396
+#: ../pakfire/cli.py:395
msgid "Pakfire repo command line interface."
msgstr ""
-#: ../pakfire/cli.py:415
+#: ../pakfire/cli.py:414
msgid "Repository management commands."
msgstr ""
-#: ../pakfire/cli.py:423
+#: ../pakfire/cli.py:422
msgid "Create a new repository index."
msgstr ""
-#: ../pakfire/cli.py:424
+#: ../pakfire/cli.py:423
msgid "Path to the packages."
msgstr ""
-#: ../pakfire/cli.py:425
+#: ../pakfire/cli.py:424
msgid "Path to input packages."
msgstr ""
-#: ../pakfire/cli.py:437
+#: ../pakfire/cli.py:436
msgid "Pakfire master command line interface."
msgstr ""
-#: ../pakfire/cli.py:459
+#: ../pakfire/cli.py:458
msgid "Update the sources."
msgstr ""
-#: ../pakfire/cli.py:469
+#: ../pakfire/cli.py:468
msgid "Pakfire slave command line interface."
msgstr ""
-#: ../pakfire/cli.py:493
+#: ../pakfire/cli.py:492
msgid "Request a build job from the server."
msgstr ""
-#: ../pakfire/cli.py:499
+#: ../pakfire/cli.py:498
msgid "Send a keepalive to the server."
msgstr ""