def do_autocompile(args): """autocompile [--gui] URI""" parser = OptionParser(usage="usage: %prog autocompile [options]") parser.add_option('', "--gui", help="graphical interface", action='store_true') (options, args2) = parser.parse_args(args) if len(args2) != 1: raise __main__.UsageError() if options.gui: h = GUIHandler() elif os.isatty(1): h = handler.ConsoleHandler() else: h = handler.Handler() config = load_config(handler=h) config._iface_cache = AutocompileCache() iface_uri = model.canonical_iface_uri(args2[0]) if options.gui: compiler = GTKAutoCompiler(config, iface_uri, options) else: compiler = AutoCompiler(config, iface_uri, options) compiler.build()
def handler(self): if not self._handler: from zeroinstall.injector import handler if os.isatty(1): self._handler = handler.ConsoleHandler() else: self._handler = handler.Handler() return self._handler
def get_selections(self, prompt = False): if self._selections: assert not prompt return self._selections selections_file = self.config.get('compile', 'selections') if selections_file: if prompt: raise SafeException("Selections are fixed by %s" % selections_file) stream = file(selections_file) try: self._selections = selections.Selections(qdom.parse(stream)) finally: stream.close() from zeroinstall.injector import handler from zeroinstall.injector.config import load_config if os.isatty(1): h = handler.ConsoleHandler() else: h = handler.Handler() config = load_config(h) blocker = self._selections.download_missing(config) if blocker: print "Waiting for selected implementations to be downloaded..." h.wait_for_blocker(blocker) else: command = install_prog + ['download', '--source', '--xml'] if prompt and '--console' not in install_prog: if os.name == 'nt': command[0] += '-win' command.append('--gui') command.append(self.interface) child = subprocess.Popen(command, stdout = subprocess.PIPE) try: self._selections = selections.Selections(qdom.parse(child.stdout)) finally: if child.wait(): raise SafeException(' '.join(repr(x) for x in command) + " failed (exit code %d)" % child.returncode) self.root_impl = self._selections.selections[self.interface] self.orig_srcdir = os.path.realpath(lookup(self.root_impl)) self.user_srcdir = None if os.path.isdir('src'): self.user_srcdir = os.path.realpath('src') if self.user_srcdir == self.orig_srcdir or \ self.user_srcdir.startswith(os.path.join(self.orig_srcdir, '')) or \ self.orig_srcdir.startswith(os.path.join(self.user_srcdir, '')): info("Ignoring 'src' directory because it coincides with %s", self.orig_srcdir) self.user_srcdir = None return self._selections
def _normal_mode(options, args): from zeroinstall.injector import handler if len(args) < 1: if options.gui: from zeroinstall import helpers return helpers.get_selections_gui(None, []) else: raise UsageError() iface_uri = model.canonical_iface_uri(args[0]) root_iface = iface_cache.get_interface(iface_uri) if os.isatty(1): h = handler.ConsoleHandler() else: h = handler.Handler() h.dry_run = bool(options.dry_run) policy = autopolicy.AutoPolicy(iface_uri, handler = h, download_only = bool(options.download_only), src = options.source) if options.before or options.not_before: policy.solver.extra_restrictions[root_iface] = [model.VersionRangeRestriction(model.parse_version(options.before), model.parse_version(options.not_before))] if options.os or options.cpu: from zeroinstall.injector import arch policy.target_arch = arch.get_architecture(options.os, options.cpu) if options.offline: policy.network_use = model.network_offline if options.get_selections: if len(args) > 1: raise SafeException(_("Can't use arguments with --get-selections")) if options.main: raise SafeException(_("Can't use --main with --get-selections")) # Note that need_download() triggers a solve if options.refresh or options.gui: # We could run immediately, but the user asked us not to can_run_immediately = False else: can_run_immediately = (not policy.need_download()) and policy.ready stale_feeds = [feed for feed in policy.solver.feeds_used if policy.is_stale(iface_cache.get_feed(feed))] if options.download_only and stale_feeds: can_run_immediately = False if can_run_immediately: if stale_feeds: if policy.network_use == model.network_offline: logging.debug(_("No doing background update because we are in off-line mode.")) else: # There are feeds we should update, but we can run without them. # Do the update in the background while the program is running. import background background.spawn_background_update(policy, options.verbose > 0) if options.get_selections: _get_selections(policy) else: if not options.download_only: from zeroinstall.injector import run run.execute(policy, args[1:], dry_run = options.dry_run, main = options.main, wrapper = options.wrapper) else: logging.info(_("Downloads done (download-only mode)")) assert options.dry_run or options.download_only return # If the user didn't say whether to use the GUI, choose for them. if options.gui is None and os.environ.get('DISPLAY', None): options.gui = True # If we need to download anything, we might as well # refresh all the interfaces first. Also, this triggers # the 'checking for updates' box, which is non-interactive # when there are no changes to the selection. options.refresh = True logging.info(_("Switching to GUI mode... (use --console to disable)")) prog_args = args[1:] try: from zeroinstall.injector import run if options.gui: gui_args = [] if options.download_only: # Just changes the button's label gui_args.append('--download-only') if options.refresh: gui_args.append('--refresh') if options.systray: gui_args.append('--systray') if options.not_before: gui_args.insert(0, options.not_before) gui_args.insert(0, '--not-before') if options.before: gui_args.insert(0, options.before) gui_args.insert(0, '--before') if options.source: gui_args.insert(0, '--source') if options.message: gui_args.insert(0, options.message) gui_args.insert(0, '--message') if options.verbose: gui_args.insert(0, '--verbose') if options.verbose > 1: gui_args.insert(0, '--verbose') if options.cpu: gui_args.insert(0, options.cpu) gui_args.insert(0, '--cpu') if options.os: gui_args.insert(0, options.os) gui_args.insert(0, '--os') if options.with_store: for x in options.with_store: gui_args += ['--with-store', x] sels = _fork_gui(iface_uri, gui_args, prog_args, options) if not sels: sys.exit(1) # Aborted else: #program_log('download_and_execute ' + iface_uri) downloaded = policy.solve_and_download_impls(refresh = bool(options.refresh)) if downloaded: policy.handler.wait_for_blocker(downloaded) sels = selections.Selections(policy) if options.get_selections: doc = sels.toDOM() doc.writexml(sys.stdout) sys.stdout.write('\n') elif not options.download_only: run.execute_selections(sels, prog_args, options.dry_run, options.main, options.wrapper) except NeedDownload, ex: # This only happens for dry runs print ex