def __init__(self, image_directory, application_path): global_settings.client_name = gui_misc.get_um_name() self.api_lock = nrlock.NRLock() self.image_dir_arg = image_directory if self.image_dir_arg == None: self.image_dir_arg = gui_misc.get_image_path() self.application_path = application_path self.gconf = pmgconf.PMGConf() try: self.application_dir = os.environ["PACKAGE_MANAGER_ROOT"] except KeyError: self.application_dir = "/" misc.setlocale(locale.LC_ALL, "") for module in (gettext, gtk.glade): module.bindtextdomain("pkg", os.path.join( self.application_dir, "usr/share/locale")) module.textdomain("pkg") gui_misc.init_for_help(self.application_dir) self.icon_theme = gtk.icon_theme_get_default() pkg_icon_location = os.path.join(self.application_dir, PKG_ICON_LOCATION) self.icon_theme.append_search_path(pkg_icon_location) icon_location = os.path.join(self.application_dir, ICON_LOCATION) self.icon_theme.append_search_path(icon_location) self.progress_tracker = progress.NullProgressTracker() self.api_obj = None self.installupdate = None self.return_status = enumerations.UPDATES_UNDETERMINED self.pylintstub = None gui_misc.setup_logging() gobject.idle_add(self.__do_image_update)
def __init__(self, image_directory, application_path, nice, check_all, check_cache): global_settings.client_name = nongui_misc.get_um_name() self.api_lock = nrlock.NRLock() self.image_dir_arg = image_directory if self.image_dir_arg == None: self.image_dir_arg = nongui_misc.get_image_path() self.application_path = application_path self.nice = nice self.check_all = check_all self.check_cache_only = check_cache try: self.application_dir = os.environ["PACKAGE_MANAGER_ROOT"] except KeyError: self.application_dir = "/" misc.setlocale(locale.LC_ALL, "") self.progress_tracker = progress.NullProgressTracker() self.api_obj = None self.return_status = enumerations.UPDATES_UNDETERMINED self.pylintstub = None # Check Updates - by default check all if self.check_all: self.api_obj = self.__get_api_obj() self.__check_for_updates() elif self.check_cache_only: self.api_obj = self.__get_api_obj() ret = self.__check_for_updates_cache_only() if ret == enumerations.UPDATES_UNDETERMINED: self.__send_return(enumerations.UPDATES_UNDETERMINED)
def __init__(self): os.nice(20) try: self.application_dir = os.environ["UPDATE_MANAGER_NOTIFIER_ROOT"] except KeyError: self.application_dir = "/" misc.setlocale(locale.LC_ALL, "") gettext.bindtextdomain("pkg", os.path.join( self.application_dir, "usr/share/locale")) gettext.textdomain("pkg") self.pr = None self.last_check_filename = None self.time_until_next_check = 0 self.status_icon = None self.n_updates = 0 self.n_installs = 0 self.n_removes = 0 self.notify = None self.host = None self.last_check_time = 0 self.refresh_period = 0 self.timeout_id = 0 self.terminate_after_activate = False self.client = gconf.client_get_default() self.start_delay = self.get_start_delay() # Allow gtk.main loop to start as quickly as possible gobject.timeout_add(self.start_delay * 1000, self.check_and_start)
def parse_argv(): misc.setlocale(locale.LC_ALL, "", None) gettext.install("pkg", "/usr/share/locale") gofast = False opts, argv = getopt.getopt(sys.argv[1:], "f") for (opt, arg) in opts: if opt == '-f': gofast = True else: sys.exit(2) trackers = { "null": progress.NullProgressTracker, "func": progress.FunctionProgressTracker, "fancy": progress.FancyUNIXProgressTracker, "cli": progress.CommandLineProgressTracker, "dot": progress.DotProgressTracker, "quiet": progress.QuietProgressTracker, "default": progress.FancyUNIXProgressTracker, } pts = [] first = True while first or len(argv) > 0: first = False outputdevname = "/dev/stdout" if len(argv) >= 2 and argv[1] != "-": outputdevname = argv[1] tname = "default" if len(argv) >= 1 and argv[0] != "-": tname = argv[0] outputdev = open(outputdevname, "w") # Get a reference to the tracker class try: trackerclass = trackers[tname] except KeyError: print "unknown tracker %s" % argv[0] sys.exit(2) try: st = trackerclass(output_file=outputdev) except TypeError: st = trackerclass() pts.append(st) print "Created %s progress tracker on %s" % \ (trackerclass.__name__, outputdevname) argv = argv[2:] if len(pts) > 1: t = MultiProgressTracker(pts) else: t = pts[0] return (t, gofast)
def parse_argv(): misc.setlocale(locale.LC_ALL, "", None) gettext.install("pkg", "/usr/share/locale") gofast = False opts, argv = getopt.getopt(sys.argv[1:], "f") for (opt, arg) in opts: if opt == '-f': gofast = True else: sys.exit(2) trackers = { "null": progress.NullProgressTracker, "func": progress.FunctionProgressTracker, "fancy": progress.FancyUNIXProgressTracker, "cli": progress.CommandLineProgressTracker, "dot": progress.DotProgressTracker, "quiet": progress.QuietProgressTracker, "default": progress.FancyUNIXProgressTracker, } pts = [] first = True while first or len(argv) > 0: first = False outputdevname = "/dev/stdout" if len(argv) >= 2 and argv[1] != "-": outputdevname = argv[1] tname = "default" if len(argv) >= 1 and argv[0] != "-": tname = argv[0] outputdev = open(outputdevname, "w") # Get a reference to the tracker class try: trackerclass = trackers[tname] except KeyError: print("unknown tracker {0}".format(argv[0])) sys.exit(2) try: st = trackerclass(output_file=outputdev) except TypeError: st = trackerclass() pts.append(st) print("Created {0} progress tracker on {1}".format( trackerclass.__name__, outputdevname)) argv = argv[2:] if len(pts) > 1: t = progress.MultiProgressTracker(pts) else: t = pts[0] return (t, gofast)
def main_func(): misc.setlocale(locale.LC_ALL, "", error) gettext.install("pkg", "/usr/share/locale", codeset=locale.getpreferredencoding()) try: opts, pargs = getopt.getopt(sys.argv[1:], "R:?", ["help"]) except getopt.GetoptError, e: usage(_("illegal global option -- %s") % e.opt)
def main_func(): misc.setlocale(locale.LC_ALL, "", error) gettext.install("pkg", "/usr/share/locale", codeset=locale.getpreferredencoding()) global_settings.client_name = "pkgsign" try: opts, pargs = getopt.getopt(sys.argv[1:], "a:c:i:k:ns:", ["help", "no-index", "no-catalog"]) except getopt.GetoptError, e: usage(_("illegal global option -- %s") % e.opt)
def __init__(self, image_directory, application_path, check_all, check_cache): global_settings.client_name = nongui_misc.get_um_name() self.api_lock = nrlock.NRLock() self.image_dir_arg = image_directory self.exact_match = True if self.image_dir_arg == None: self.image_dir_arg, self.exact_match = \ api.get_default_image_root() if not self.exact_match: logger.debug("Unable to get image directory") sys.exit(enumerations.UPDATES_UNDETERMINED) self.application_path = application_path self.check_all = check_all self.check_cache_only = check_cache self.application_dir = \ os.environ.get("PACKAGE_MANAGER_ROOT", "/") misc.setlocale(locale.LC_ALL, "") if global_settings.verbose: pe = printengine.LoggingPrintEngine( logger, logging.DEBUG) self.progress_tracker = \ progress.CommandLineProgressTracker(print_engine=pe) else: self.progress_tracker = progress.NullProgressTracker() self.api_obj = None self.return_status = enumerations.UPDATES_UNDETERMINED self.pylintstub = None # Check Updates - by default check all self.api_obj = self.__get_api_obj() if self.api_obj == None: self.return_status = enumerations.UPDATES_UNDETERMINED return if self.check_all: self.__check_for_updates() elif self.check_cache_only: self.__check_for_updates_cache_only()
def main_func(): misc.setlocale(locale.LC_ALL, "", error) gettext.install("pkg", "/usr/share/locale", codeset=locale.getpreferredencoding()) try: opts, pargs = getopt.getopt(sys.argv[1:], "R:?", ["help"]) except getopt.GetoptError as e: usage(_("illegal global option -- {0}").format(e.opt)) show_usage = False img_dir = None for opt, arg in opts: if opt == "-R": img_dir = arg elif opt in ("--help", "-?"): show_usage = True subcommand = None if pargs: subcommand = pargs.pop(0) if subcommand == "help": show_usage = True if show_usage: usage(retcode=0) elif not subcommand: usage() if subcommand == "generate": if img_dir: usage(_("generate subcommand doesn't use -R")) return generate(pargs) elif subcommand == "resolve": return resolve(pargs, img_dir) else: usage(_("unknown subcommand '{0}'").format(subcommand))
def __init__(self, image_directory, application_path): global_settings.client_name = gui_misc.get_um_name() self.api_lock = nrlock.NRLock() self.image_dir_arg = image_directory self.exact_match = True if self.image_dir_arg == None: self.image_dir_arg, self.exact_match = api.get_default_image_root() if not self.exact_match: if debug: print >>sys.stderr, ("Unable to get the image directory") sys.exit(enumerations.UPDATES_UNDETERMINED) self.application_path = application_path self.gconf = pmgconf.PMGConf() try: self.application_dir = os.environ["PACKAGE_MANAGER_ROOT"] except KeyError: self.application_dir = "/" misc.setlocale(locale.LC_ALL, "") for module in (gettext, gtk.glade): module.bindtextdomain("pkg", os.path.join(self.application_dir, "usr/share/locale")) module.textdomain("pkg") gui_misc.init_for_help(self.application_dir) self.icon_theme = gtk.icon_theme_get_default() pkg_icon_location = os.path.join(self.application_dir, PKG_ICON_LOCATION) self.icon_theme.append_search_path(pkg_icon_location) icon_location = os.path.join(self.application_dir, ICON_LOCATION) self.icon_theme.append_search_path(icon_location) self.progress_tracker = progress.NullProgressTracker() self.api_obj = None self.installupdate = None self.return_status = enumerations.UPDATES_UNDETERMINED self.pylintstub = None gui_misc.setup_logging() gobject.idle_add(self.__do_image_update)
except apx.VersionException, __e: logger.error("The pmcheckforupdates command appears out of " "sync with the libraries provided\nby pkg:/package/pkg. " "The client version is %(client)s while the library\n" "API version is %(api)s." % \ {'client': __e.received_version, 'api': __e.expected_version}) __ret = EXIT_OOPS except: traceback.print_exc() logger.error(traceback_str) __ret = 99 return __ret if __name__ == "__main__": misc.setlocale(locale.LC_ALL, "") gettext.install("pkg", "/usr/share/locale", codeset=locale.getpreferredencoding()) # Make all warnings be errors. warnings.simplefilter('error') __retval = handle_errors(main_func) try: logging.shutdown() except IOError: # Ignore python's spurious pipe problems. pass sys.exit(__retval)
def __init__(self, image_dir): global_settings.client_name = gui_misc.get_wi_name() self.image_dir = image_dir try: self.application_dir = os.environ["PACKAGE_MANAGER_ROOT"] except KeyError: self.application_dir = "/" misc.setlocale(locale.LC_ALL, "") for module in (gettext, gtk.glade): module.bindtextdomain("pkg", os.path.join( self.application_dir, "usr/share/locale")) module.textdomain("pkg") gui_misc.init_for_help(self.application_dir) self.pub_pkg_list = None self.pr = progress.NullProgressTracker() self.pub_new_tasks = [] self.pkg_install_tasks = [] self.icon_theme = gtk.icon_theme_get_default() icon_location = os.path.join(self.application_dir, ICON_LOCATION) self.icon_theme.append_search_path(icon_location) self.param = None self.disabled_pubs = {} self.repo_gui = None self.first_run = True # Webinstall Dialog builder = gtk.Builder() self.gladefile = os.path.join(self.application_dir, "usr/share/package-manager/packagemanager.ui") builder.add_from_file(self.gladefile) self.w_webinstall_dialog = \ builder.get_object("webinstalldialog") self.w_webinstall_proceed = \ builder.get_object("proceed_button") self.w_webinstall_cancel = \ builder.get_object("cancel_button") self.w_webinstall_help = \ builder.get_object("help_button") self.w_webinstall_close = \ builder.get_object("close_button") self.w_webinstall_proceed_label = \ builder.get_object("proceed_new_repo_label") self.w_webinstall_toplabel = \ builder.get_object("webinstall_toplabel") self.w_webinstall_frame = \ builder.get_object("webinstall_frame") self.w_webinstall_image = \ builder.get_object("pkgimage") self.window_icon = gui_misc.get_icon(self.icon_theme, 'packagemanager', 48) self.w_webinstall_image.set_from_pixbuf(self.window_icon) self.w_webinstall_info_label = \ builder.get_object("label19") self.w_webinstall_textview = \ builder.get_object("webinstall_textview") infobuffer = self.w_webinstall_textview.get_buffer() infobuffer.create_tag("bold", weight=pango.WEIGHT_BOLD) infobuffer.create_tag("disabled", foreground="#757575") #Close to DimGrey self.__setup_signals() self.w_webinstall_dialog.set_icon(self.window_icon) self.api_o = gui_misc.get_api_object(self.image_dir, self.pr, self.w_webinstall_dialog) gui_misc.setup_logging()
--writable-root The path to a directory to which the program has write access. Used with --readonly to allow server to create needed files, such as search indices, without needing write access to the package information. """ sys.exit(2) class OptionError(Exception): """Option exception. """ def __init__(self, *args): Exception.__init__(self, *args) if __name__ == "__main__": setlocale(locale.LC_ALL, "") gettext.install("pkg", "/usr/share/locale") debug_features = { "headers": False, } port = PORT_DEFAULT port_provided = False threads = THREADS_DEFAULT socket_timeout = SOCKET_TIMEOUT_DEFAULT readonly = READONLY_DEFAULT rebuild = REBUILD_DEFAULT reindex = REINDEX_DEFAULT proxy_base = None mirror = MIRROR_DEFAULT nasty = False
e.opt, script_path)) except ValueError as e: return error( _("invalid option argument: {0} in file: {1}").format( str(e), script_path)) if len(pargs) < 1: return error(_("missing argument in file: {0}").format(script_path)) return entry.rad_pkg(pargs[0], pargs_json=pargs_json, opts_json=opts_json, pkg_image=pkg_image, prog_delay=prog_delay) if __name__ == "__main__": misc.setlocale(locale.LC_ALL, "") gettext.install("pkg", "/usr/share/locale", codeset=locale.getpreferredencoding()) __init_log() ret_json = main_func() ips_logger.info(json.dumps(ret_json)) try: logging.shutdown() except IOError: # Ignore python's spurious pipe problems. pass sys.exit(ret_json["status"]) # Vim hints # vim:ts=8:sw=8:et:fdm=marker
except apx.VersionException, __e: error(_("The sysrepo command appears out of sync with the " "libraries provided\nby pkg:/package/pkg. The client " "version is %(client)s while the library\nAPI version is " "%(api)s.") % {'client': __e.received_version, 'api': __e.expected_version }) __ret = EXIT_OOPS except: traceback.print_exc() error(traceback_str) __ret = 99 return __ret if __name__ == "__main__": misc.setlocale(locale.LC_ALL, "", error) gettext.install("pkg", "/usr/share/locale", codeset=locale.getpreferredencoding()) # Make all warnings be errors. warnings.simplefilter('error') __retval = handle_errors(main_func) try: logging.shutdown() except IOError: # Ignore python's spurious pipe problems. pass sys.exit(__retval)
else: c = 100 print("bytes left {0:d}; retrieving {1:d} files".format(total, c)) rc.dump() # get 100 files r = s[0] for n in range(c): req = r[1].request(rc) total -= req[1] rc.dump() misc.setlocale(locale.LC_ALL) gettext.install("pkg", "/usr/share/locale") total_mb = 1000 # Scenario 1. A single origin. single = Scenario("single origin") single.add_origin_uri("origin", depot.SPEED_FAST, depot.CSPEED_LAN) single.set_megabytes(total_mb) single.run() # Scenario 2a. An origin and mirror, mirror faster.
def main_func(): global temp_root, repo_modified, repo_finished, repo_uri, tracker global dry_run misc.setlocale(locale.LC_ALL, "", error) gettext.install("pkg", "/usr/share/locale", codeset=locale.getpreferredencoding()) global_settings.client_name = PKG_CLIENT_NAME try: opts, pargs = getopt.getopt(sys.argv[1:], "?c:i:np:r:s:", ["help"]) except getopt.GetoptError as e: usage(_("illegal option -- {0}").format(e.opt)) dry_run = False ref_repo_uri = None repo_uri = os.getenv("PKG_REPO", None) changes = set() ignores = set() publishers = set() processed_pubs = 0 for opt, arg in opts: if opt == "-c": changes.add(arg) elif opt == "-i": ignores.add(arg) elif opt == "-n": dry_run = True elif opt == "-p": publishers.add(arg) elif opt == "-r": ref_repo_uri = misc.parse_uri(arg) elif opt == "-s": repo_uri = misc.parse_uri(arg) elif opt == "-?" or opt == "--help": usage(retcode=pkgdefs.EXIT_OK) if pargs: usage(_("Unexpected argument(s): {0}").format(" ".join(pargs))) if not repo_uri: usage(_("A target repository must be provided.")) if not ref_repo_uri: usage(_("A reference repository must be provided.")) t = misc.config_temp_root() temp_root = tempfile.mkdtemp(dir=t, prefix=global_settings.client_name + "-") ref_incoming_dir = tempfile.mkdtemp(dir=temp_root) ref_pkg_root = tempfile.mkdtemp(dir=temp_root) ref_xport, ref_xport_cfg = transport.setup_transport() ref_xport_cfg.incoming_root = ref_incoming_dir ref_xport_cfg.pkg_root = ref_pkg_root transport.setup_publisher(ref_repo_uri, "ref", ref_xport, ref_xport_cfg, remote_prefix=True) target = publisher.RepositoryURI(misc.parse_uri(repo_uri)) if target.scheme != "file": abort(err=_("Target repository must be filesystem-based.")) try: target_repo = sr.Repository(read_only=dry_run, root=target.get_pathname()) except sr.RepositoryError as e: abort(str(e)) tracker = get_tracker() for pub in target_repo.publishers: if publishers and pub not in publishers \ and '*' not in publishers: continue msg(_("Processing packages for publisher {0} ...").format(pub)) # Find the matching pub in the ref repo. for ref_pub in ref_xport_cfg.gen_publishers(): if ref_pub.prefix == pub: found = True break else: txt = _("Publisher {0} not found in reference " "repository.").format(pub) if publishers: abort(err=txt) else: txt += _(" Skipping.") msg(txt) continue processed_pubs += 1 rev = do_reversion(pub, ref_pub, target_repo, ref_xport, changes, ignores) # Only rebuild catalog if anything got actually reversioned. if rev and not dry_run: msg(_("Rebuilding repository catalog.")) target_repo.rebuild(pub=pub) repo_finished = True ret = pkgdefs.EXIT_OK if processed_pubs == 0: msg(_("No matching publishers could be found.")) ret = pkgdefs.EXIT_OOPS cleanup() return ret
# Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. # from __future__ import print_function import getopt import locale import gettext import os import sys import traceback import pkg.client.printengine as printengine import pkg.misc as misc if __name__ == "__main__": misc.setlocale(locale.LC_ALL, "", None) gettext.install("pkg", "/usr/share/locale") test_ttymode = test_nottymode = test_logging = False opts, argv = getopt.getopt(sys.argv[1:], "tTl") for (opt, arg) in opts: if opt == '-t': test_ttymode = True elif opt == '-T': test_nottymode = True elif opt == '-l': test_logging = True else: print("bad option {0}".format(opt), file=sys.stderr) sys.exit(2)
# # Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. # import getopt import locale import gettext import os import sys import traceback import pkg.client.printengine as printengine import pkg.misc as misc if __name__ == "__main__": misc.setlocale(locale.LC_ALL, "", None) gettext.install("pkg", "/usr/share/locale") test_ttymode = test_nottymode = test_logging = False opts, argv = getopt.getopt(sys.argv[1:], "tTl") for (opt, arg) in opts: if opt == '-t': test_ttymode = True elif opt == '-T': test_nottymode = True elif opt == '-l': test_logging = True else: print >> sys.stderr, "bad option %s" % opt sys.exit(2)
def __init__(self, image_dir): global_settings.client_name = gui_misc.get_wi_name() self.image_dir = image_dir try: self.application_dir = os.environ["PACKAGE_MANAGER_ROOT"] except KeyError: self.application_dir = "/" misc.setlocale(locale.LC_ALL, "") for module in (gettext, gtk.glade): module.bindtextdomain( "pkg", os.path.join(self.application_dir, "usr/share/locale")) module.textdomain("pkg") gui_misc.init_for_help(self.application_dir) self.pub_pkg_list = None self.pr = progress.NullProgressTracker() self.pub_new_tasks = [] self.pkg_install_tasks = [] self.icon_theme = gtk.icon_theme_get_default() icon_location = os.path.join(self.application_dir, ICON_LOCATION) self.icon_theme.append_search_path(icon_location) self.param = None self.disabled_pubs = {} self.repo_gui = None self.first_run = True # Webinstall Dialog builder = gtk.Builder() self.gladefile = os.path.join( self.application_dir, "usr/share/package-manager/packagemanager.ui") builder.add_from_file(self.gladefile) self.w_webinstall_dialog = \ builder.get_object("webinstalldialog") self.w_webinstall_proceed = \ builder.get_object("proceed_button") self.w_webinstall_cancel = \ builder.get_object("cancel_button") self.w_webinstall_help = \ builder.get_object("help_button") self.w_webinstall_close = \ builder.get_object("close_button") self.w_webinstall_proceed_label = \ builder.get_object("proceed_new_repo_label") self.w_webinstall_toplabel = \ builder.get_object("webinstall_toplabel") self.w_webinstall_frame = \ builder.get_object("webinstall_frame") self.w_webinstall_image = \ builder.get_object("pkgimage") self.window_icon = gui_misc.get_icon(self.icon_theme, 'packagemanager', 48) self.w_webinstall_image.set_from_pixbuf(self.window_icon) self.w_webinstall_info_label = \ builder.get_object("label19") self.w_webinstall_textview = \ builder.get_object("webinstall_textview") infobuffer = self.w_webinstall_textview.get_buffer() infobuffer.create_tag("bold", weight=pango.WEIGHT_BOLD) infobuffer.create_tag("disabled", foreground="#757575") #Close to DimGrey self.__setup_signals() self.w_webinstall_dialog.set_icon(self.window_icon) self.api_o = gui_misc.get_api_object(self.image_dir, self.pr, self.w_webinstall_dialog) gui_misc.setup_logging()
fm = file_manager.FileManager(root=dir_loc, readonly=False) try: for f in fm.walk(): # A non-readonly FileManager will move a file under a # non-preferred layout to the preferred layout during a # lookup. fm.lookup(f) except file_manager.UnrecognizedFilePaths as e: emsg(e) return 1 return 0 if __name__ == "__main__": setlocale(locale.LC_ALL, "") gettext.install("pkg", "/usr/share/locale") traceback_str = misc.get_traceback_message() try: # Out of memory errors can be raised as EnvironmentErrors with # an errno of ENOMEM, so in order to handle those exceptions # with other errnos, we nest this try block and have the outer # one handle the other instances. try: __ret = main_func() except (MemoryError, EnvironmentError) as __e: if isinstance(__e, EnvironmentError) and \ __e.errno != errno.ENOMEM: raise
def main_func(): misc.setlocale(locale.LC_ALL, "", error) gettext.install("pkg", "/usr/share/locale", codeset=locale.getpreferredencoding()) global_settings.client_name = "pkgsign" try: opts, pargs = getopt.getopt( sys.argv[1:], "a:c:i:k:ns:D:", ["help", "no-index", "no-catalog", "dkey=", "dcert="]) except getopt.GetoptError as e: usage(_("illegal global option -- {0}").format(e.opt)) show_usage = False sig_alg = "rsa-sha256" cert_path = None key_path = None chain_certs = [] add_to_catalog = True set_alg = False dry_run = False dkey = None dcert = None repo_uri = os.getenv("PKG_REPO", None) for opt, arg in opts: if opt == "-a": sig_alg = arg set_alg = True elif opt == "-c": cert_path = os.path.abspath(arg) if not os.path.isfile(cert_path): usage( _("{0} was expected to be a certificate " "but isn't a file.").format(cert_path)) elif opt == "-i": p = os.path.abspath(arg) if not os.path.isfile(p): usage( _("{0} was expected to be a certificate " "but isn't a file.").format(p)) chain_certs.append(p) elif opt == "-k": key_path = os.path.abspath(arg) if not os.path.isfile(key_path): usage( _("{0} was expected to be a key file " "but isn't a file.").format(key_path)) elif opt == "--dkey": dkey = os.path.abspath(arg) if not os.path.isfile(dkey): usage( _("{0} was expected to be a key file " "but isn't a file.").format(dkey)) elif opt == "--dcert": dcert = os.path.abspath(arg) if not os.path.isfile(dcert): usage( _("{0} was expected to be a certificate " "but isn't a file.").format(dcert)) elif opt == "-n": dry_run = True elif opt == "-s": repo_uri = misc.parse_uri(arg) elif opt == "--help": show_usage = True elif opt == "--no-catalog": add_to_catalog = False elif opt == "-D": try: key, value = arg.split("=", 1) DebugValues.set_value(key, value) except (AttributeError, ValueError): error( _("{opt} takes argument of form " "name=value, not {arg}").format(opt=opt, arg=arg)) if show_usage: usage(retcode=EXIT_OK) if not repo_uri: usage(_("a repository must be provided")) if key_path and not cert_path: usage( _("If a key is given to sign with, its associated " "certificate must be given.")) if cert_path and not key_path: usage( _("If a certificate is given, its associated key must be " "given.")) if chain_certs and not cert_path: usage( _("Intermediate certificates are only valid if a key " "and certificate are also provided.")) if not pargs: usage(_("At least one fmri or pattern must be provided to " "sign.")) if not set_alg and not key_path: sig_alg = "sha256" s, h = actions.signature.SignatureAction.decompose_sig_alg(sig_alg) if h is None: usage( _("{0} is not a recognized signature algorithm.").format(sig_alg)) if s and not key_path: usage( _("Using {0} as the signature algorithm requires that a " "key and certificate pair be presented using the -k and -c " "options.").format(sig_alg)) if not s and key_path: usage( _("The {0} hash algorithm does not use a key or " "certificate. Do not use the -k or -c options with this " "algorithm.").format(sig_alg)) if DebugValues: reload(digest) errors = [] t = misc.config_temp_root() temp_root = tempfile.mkdtemp(dir=t) del t cache_dir = tempfile.mkdtemp(dir=temp_root) incoming_dir = tempfile.mkdtemp(dir=temp_root) chash_dir = tempfile.mkdtemp(dir=temp_root) cert_dir = tempfile.mkdtemp(dir=temp_root) try: chain_certs = [__make_tmp_cert(cert_dir, c) for c in chain_certs] if cert_path is not None: cert_path = __make_tmp_cert(cert_dir, cert_path) xport, xport_cfg = transport.setup_transport() xport_cfg.add_cache(cache_dir, readonly=False) xport_cfg.incoming_root = incoming_dir # Configure publisher(s) transport.setup_publisher(repo_uri, "source", xport, xport_cfg, remote_prefix=True, ssl_key=dkey, ssl_cert=dcert) pats = pargs successful_publish = False concrete_fmris = [] unmatched_pats = set(pats) all_pats = frozenset(pats) get_all_pubs = False pub_prefs = set() # Gather the publishers whose catalogs will be needed. for pat in pats: try: p_obj = fmri.MatchingPkgFmri(pat) except fmri.IllegalMatchingFmri as e: errors.append(e) continue pub_prefix = p_obj.get_publisher() if pub_prefix: pub_prefs.add(pub_prefix) else: get_all_pubs = True # Check each publisher for matches to our patterns. for p in xport_cfg.gen_publishers(): if not get_all_pubs and p.prefix not in pub_prefs: continue cat = fetch_catalog(p, xport, temp_root) ms, tmp1, u = cat.get_matching_fmris(pats) # Find which patterns matched. matched_pats = all_pats - u # Remove those patterns from the unmatched set. unmatched_pats -= matched_pats for v_list in ms.values(): concrete_fmris.extend([(v, p) for v in v_list]) if unmatched_pats: raise api_errors.PackageMatchErrors(unmatched_fmris=unmatched_pats) for pfmri, src_pub in sorted(set(concrete_fmris)): try: # Get the existing manifest for the package to # be signed. m_str = xport.get_manifest(pfmri, content_only=True, pub=src_pub) m = manifest.Manifest() m.set_content(content=m_str) # Construct the base signature action. attrs = {"algorithm": sig_alg} a = actions.signature.SignatureAction(cert_path, **attrs) a.hash = cert_path # Add the action to the manifest to be signed # since the action signs itself. m.add_action(a, misc.EmptyI) # Set the signature value and certificate # information for the signature action. a.set_signature(m.gen_actions(), key_path=key_path, chain_paths=chain_certs, chash_dir=chash_dir) # The hash of 'a' is currently a path, we need # to find the hash of that file to allow # comparison to existing signatures. hsh = None if cert_path: # Action identity still uses the 'hash' # member of the action, so we need to # stay with the sha1 hash. hsh, _dummy = \ misc.get_data_digest(cert_path, hash_func=hashlib.sha1) # Check whether the signature about to be added # is identical, or almost identical, to existing # signatures on the package. Because 'a' has # already been added to the manifest, it is # generated by gen_actions_by_type, so the cnt # must be 2 or higher to be an issue. cnt = 0 almost_identical = False for a2 in m.gen_actions_by_type("signature"): try: if a.identical(a2, hsh): cnt += 1 except api_errors.AlmostIdentical as e: e.pkg = pfmri errors.append(e) almost_identical = True if almost_identical: continue if cnt == 2: continue elif cnt > 2: raise api_errors.DuplicateSignaturesAlreadyExist(pfmri) assert cnt == 1, "Cnt was:{0}".format(cnt) if not dry_run: # Append the finished signature action # to the published manifest. t = trans.Transaction(repo_uri, pkg_name=str(pfmri), xport=xport, pub=src_pub) try: t.append() t.add(a) for c in chain_certs: t.add_file(c) t.close(add_to_catalog=add_to_catalog) except: if t.trans_id: t.close(abandon=True) raise msg( _("Signed {0}").format( pfmri.get_fmri(include_build=False))) successful_publish = True except (api_errors.ApiException, fmri.FmriError, trans.TransactionError) as e: errors.append(e) if errors: error("\n".join([str(e) for e in errors])) if successful_publish: return EXIT_PARTIAL else: return EXIT_OOPS return EXIT_OK except api_errors.ApiException as e: error(e) return EXIT_OOPS finally: shutil.rmtree(temp_root)
error(e, cmd=subcommand) ret = EXIT_OOPS except getopt.GetoptError as e: usage( _("illegal {cmd} option -- {opt}").format(cmd=subcommand, opt=e.opt)) return ret # # Establish a specific exit status which means: "python barfed an exception" # so that we can more easily detect these in testing of the CLI commands. # if __name__ == "__main__": misc.setlocale(locale.LC_ALL, "", error) gettext.install("pkg", "/usr/share/locale", codeset=locale.getpreferredencoding()) misc.set_fd_limits(printer=error) # Make all warnings be errors. warnings.simplefilter('error') if six.PY3: # disable ResourceWarning: unclosed file warnings.filterwarnings("ignore", category=ResourceWarning) try: __ret = main_func() except (PipeError, KeyboardInterrupt): # We don't want to display any messages here to prevent
c = 10 else: c = 100 print "bytes left %d; retrieving %d files" % (total, c) rc.dump() # get 100 files r = s[0] for n in range(c): req = r[1].request(rc) total -= req[1] rc.dump() misc.setlocale(locale.LC_ALL) gettext.install("pkg", "/usr/share/locale") total_mb = 1000 # Scenario 1. A single origin. single = Scenario("single origin") single.add_origin_uri("origin", depot.SPEED_FAST, depot.CSPEED_LAN) single.set_megabytes(total_mb) single.run() # Scenario 2a. An origin and mirror, mirror faster.