#!/usr/bin/python import sys # Use tornado's logging options import tornado.options tornado.options.parse_command_line() import pakfire.buildservice class Cli(object): def __init__(self, *args, **kwargs): # Initialise backend self.backend = pakfire.buildservice.Backend(*args, **kwargs) self._commands = { # Check build dependencies "check-build-dependencies" : self.backend.jobqueue.check_build_dependencies, # Run mirror check "check-mirrors" : self.backend.mirrors.check, # Cleanup files "cleanup-files" : self.backend.cleanup_files, # Cleanup repositories "cleanup-repositories" : self.backend.repos.cleanup, # Cleanup sessions "cleanup-sessions" : self.backend.sessions.cleanup, # Cleanup uploads "cleanup-uploads" : self.backend.uploads.cleanup, # Create test jobs "create-test-jobs" : self.backend.jobqueue.create_test_jobs, # Dist "dist" : self.backend.sources.dist, # List repository "list-repository" : self._list_repository, # Sends all queued messages "process-message-queue" : self.backend.messages.process_queue, # Pull sources "pull-sources" : self.backend.sources.pull, # Remaster Repositories "remaster-repositories" : self.backend.repos.remaster, # Restart failed jobs "restart-failed-jobs" : self.backend.jobs.restart_failed, # Send bug updates to Bugzilla "send-bug-updates" : self.backend.bugzilla.send_all, } def __call__(self, *args): # Parse tornado settings args = tornado.options.parse_command_line(args) if not len(args) >= 1: print >>sys.stderr, "Insufficient number of arguments" return 2 args = list(args) command = args.pop(0) # Get called command try: command = self._commands[command] except KeyError: print >>sys.stderr, "Command not found: %s" % command return 2 # Execute command r = command(*args) # Exit with error code sys.exit(r or 0) def _list_repository(self, distro_name, repo_name, arch): # Get distribution distro = self.backend.distros.get_by_name(distro_name) if not distro: print >>sys.stderr, "Could not find distribution: %s" % distro_name return 2 # Get repository repo = distro.get_repo(repo_name) if not repo: print >>sys.stderr, "Could not find repository: %s" % repo_name return 2 # Iterate through all of it for build in repo: for job in build: # Skip all test jobs if job.test: continue if not job.arch in (arch, "noarch"): continue for pkg in job: print pkg # main cli = Cli() cli(*sys.argv)