def hardlock_name(path): base, tail = os.path.split(path) return os.path.join( base, ".%s.hardlock-%s-%s" % (tail, portage._decode_argv([os.uname()[1]])[0], portage.getpid()), )
def hardlock_cleanup(path, remove_all_locks=False): myhost = portage._decode_argv([os.uname()[1]])[0] mydl = os.listdir(path) results = [] mycount = 0 mylist = {} for x in mydl: if os.path.isfile(path + "/" + x): parts = x.split(".hardlock-") if len(parts) == 2: filename = parts[0][1:] hostpid = parts[1].split("-") host = "-".join(hostpid[:-1]) pid = hostpid[-1] if filename not in mylist: mylist[filename] = {} if host not in mylist[filename]: mylist[filename][host] = [] mylist[filename][host].append(pid) mycount += 1 results.append(_("Found %(count)s locks") % {"count": mycount}) for x in mylist: if myhost in mylist[x] or remove_all_locks: mylockname = hardlock_name(path + "/" + x) if hardlink_is_mine(mylockname, path + "/" + x) or \ not os.path.exists(path + "/" + x) or \ remove_all_locks: for y in mylist[x]: for z in mylist[x][y]: filename = path + "/." + x + ".hardlock-" + y + "-" + z if filename == mylockname: continue try: # We're sweeping through, unlinking everyone's locks. os.unlink(filename) results.append(_("Unlinked: ") + filename) except OSError: pass try: os.unlink(path + "/" + x) results.append(_("Unlinked: ") + path + "/" + x) os.unlink(mylockname) results.append(_("Unlinked: ") + mylockname) except OSError: pass else: try: os.unlink(mylockname) results.append(_("Unlinked: ") + mylockname) except OSError: pass return results
def emerge_main(args=None): """ @param args: command arguments (default: sys.argv[1:]) @type args: list """ if args is None: args = sys.argv[1:] args = portage._decode_argv(args) # Use system locale. try: locale.setlocale(locale.LC_ALL, "") except locale.Error as e: writemsg_level("setlocale: %s\n" % e, level=logging.WARN) # Disable color until we're sure that it should be enabled (after # EMERGE_DEFAULT_OPTS has been parsed). portage.output.havecolor = 0 # This first pass is just for options that need to be known as early as # possible, such as --config-root. They will be parsed again later, # together with EMERGE_DEFAULT_OPTS (which may vary depending on the # the value of --config-root). myaction, myopts, myfiles = parse_opts(args, silent=True) if "--debug" in myopts: os.environ["PORTAGE_DEBUG"] = "1" if "--config-root" in myopts: os.environ["PORTAGE_CONFIGROOT"] = myopts["--config-root"] if "--sysroot" in myopts: os.environ["SYSROOT"] = myopts["--sysroot"] if "--root" in myopts: os.environ["ROOT"] = myopts["--root"] if "--prefix" in myopts: os.environ["EPREFIX"] = myopts["--prefix"] if "--accept-properties" in myopts: os.environ["ACCEPT_PROPERTIES"] = myopts["--accept-properties"] if "--accept-restrict" in myopts: os.environ["ACCEPT_RESTRICT"] = myopts["--accept-restrict"] # optimize --help (no need to load config / EMERGE_DEFAULT_OPTS) if myaction == "help": emerge_help() return os.EX_OK elif myaction == "moo": print(COWSAY_MOO % platform.system()) return os.EX_OK elif myaction == "sync": # need to set this to True now in order for the repository config # loading to allow new repos with non-existent directories portage._sync_mode = True # Verify that /dev/null exists and is a device file as a cheap early # filter for obviously broken /dev/s. try: if os.stat(os.devnull).st_rdev == 0: writemsg_level("Failed to validate a sane '/dev'.\n" "'/dev/null' is not a device file.\n", level=logging.ERROR, noiselevel=-1) return 1 except OSError: writemsg_level("Failed to validate a sane '/dev'.\n" "'/dev/null' does not exist.\n", level=logging.ERROR, noiselevel=-1) return 1 # Verify that BASH process substitution works as another cheap early # filter. Process substitution uses '/dev/fd'. with open(os.devnull, 'r+b') as dev_null: fd_pipes = { 0: dev_null.fileno(), 1: dev_null.fileno(), 2: dev_null.fileno(), } if portage.process.spawn_bash("[[ $(< <(echo foo) ) == foo ]]", fd_pipes=fd_pipes) != 0: writemsg_level("Failed to validate a sane '/dev'.\n" "bash process substitution doesn't work; this may be an " "indication of a broken '/dev/fd'.\n", level=logging.ERROR, noiselevel=-1) return 1 # Portage needs to ensure a sane umask for the files it creates. os.umask(0o22) emerge_config = load_emerge_config( action=myaction, args=myfiles, opts=myopts) # Make locale variables from configuration files (make.defaults, make.conf) affect locale of emerge process. for locale_var_name in ("LANGUAGE", "LC_ALL", "LC_ADDRESS", "LC_COLLATE", "LC_CTYPE", "LC_IDENTIFICATION", "LC_MEASUREMENT", "LC_MESSAGES", "LC_MONETARY", "LC_NAME", "LC_NUMERIC", "LC_PAPER", "LC_TELEPHONE", "LC_TIME", "LANG"): locale_var_value = emerge_config.running_config.settings.get(locale_var_name) if locale_var_value is not None: os.environ.setdefault(locale_var_name, locale_var_value) try: locale.setlocale(locale.LC_ALL, "") except locale.Error as e: writemsg_level("setlocale: %s\n" % e, level=logging.WARN) tmpcmdline = [] if "--ignore-default-opts" not in myopts: tmpcmdline.extend(portage.util.shlex_split( emerge_config.target_config.settings.get( "EMERGE_DEFAULT_OPTS", ""))) tmpcmdline.extend(args) emerge_config.action, emerge_config.opts, emerge_config.args = \ parse_opts(tmpcmdline) try: return run_action(emerge_config) finally: # Call destructors for our portdbapi instances. for x in emerge_config.trees.values(): if "porttree" in x.lazy_items: continue x["porttree"].dbapi.close_caches()
def emerge_main(args=None): """ @param args: command arguments (default: sys.argv[1:]) @type args: list """ if args is None: args = sys.argv[1:] args = portage._decode_argv(args) # Use system locale. locale.setlocale(locale.LC_ALL, '') # Disable color until we're sure that it should be enabled (after # EMERGE_DEFAULT_OPTS has been parsed). portage.output.havecolor = 0 # This first pass is just for options that need to be known as early as # possible, such as --config-root. They will be parsed again later, # together with EMERGE_DEFAULT_OPTS (which may vary depending on the # the value of --config-root). myaction, myopts, myfiles = parse_opts(args, silent=True) if "--debug" in myopts: os.environ["PORTAGE_DEBUG"] = "1" if "--config-root" in myopts: os.environ["PORTAGE_CONFIGROOT"] = myopts["--config-root"] if "--root" in myopts: os.environ["ROOT"] = myopts["--root"] if "--prefix" in myopts: os.environ["EPREFIX"] = myopts["--prefix"] if "--accept-properties" in myopts: os.environ["ACCEPT_PROPERTIES"] = myopts["--accept-properties"] if "--accept-restrict" in myopts: os.environ["ACCEPT_RESTRICT"] = myopts["--accept-restrict"] # optimize --help (no need to load config / EMERGE_DEFAULT_OPTS) if myaction == "help": emerge_help() return os.EX_OK elif myaction == "moo": print(COWSAY_MOO % platform.system()) return os.EX_OK # Portage needs to ensure a sane umask for the files it creates. os.umask(0o22) if myaction == "sync": portage._sync_mode = True emerge_config = load_emerge_config( action=myaction, args=myfiles, opts=myopts) rval = profile_check(emerge_config.trees, emerge_config.action) if rval != os.EX_OK: return rval tmpcmdline = [] if "--ignore-default-opts" not in myopts: tmpcmdline.extend(portage.util.shlex_split( emerge_config.target_config.settings.get( "EMERGE_DEFAULT_OPTS", ""))) tmpcmdline.extend(args) emerge_config.action, emerge_config.opts, emerge_config.args = \ parse_opts(tmpcmdline) try: return run_action(emerge_config) finally: # Call destructors for our portdbapi instances. for x in emerge_config.trees.values(): if "porttree" in x.lazy_items: continue x["porttree"].dbapi.close_caches()
def emerge_main(args=None): """ @param args: command arguments (default: sys.argv[1:]) @type args: list """ if args is None: args = sys.argv[1:] args = portage._decode_argv(args) # Use system locale. try: locale.setlocale(locale.LC_ALL, "") except locale.Error as e: writemsg_level("setlocale: %s\n" % e, level=logging.WARN) # Disable color until we're sure that it should be enabled (after # EMERGE_DEFAULT_OPTS has been parsed). portage.output.havecolor = 0 # This first pass is just for options that need to be known as early as # possible, such as --config-root. They will be parsed again later, # together with EMERGE_DEFAULT_OPTS (which may vary depending on the # the value of --config-root). myaction, myopts, myfiles = parse_opts(args, silent=True) if "--debug" in myopts: os.environ["PORTAGE_DEBUG"] = "1" if "--config-root" in myopts: os.environ["PORTAGE_CONFIGROOT"] = myopts["--config-root"] if "--sysroot" in myopts: os.environ["SYSROOT"] = myopts["--sysroot"] if "--root" in myopts: os.environ["ROOT"] = myopts["--root"] if "--prefix" in myopts: os.environ["EPREFIX"] = myopts["--prefix"] if "--accept-properties" in myopts: os.environ["ACCEPT_PROPERTIES"] = myopts["--accept-properties"] if "--accept-restrict" in myopts: os.environ["ACCEPT_RESTRICT"] = myopts["--accept-restrict"] # optimize --help (no need to load config / EMERGE_DEFAULT_OPTS) if myaction == "help": emerge_help() return os.EX_OK if myaction == "moo": print(COWSAY_MOO % platform.system()) return os.EX_OK if myaction == "sync": # need to set this to True now in order for the repository config # loading to allow new repos with non-existent directories portage._sync_mode = True # Verify that /dev/null exists and is a device file as a cheap early # filter for obviously broken /dev/s. try: if os.stat(os.devnull).st_rdev == 0: writemsg_level( "Failed to validate a sane '/dev'.\n" "'/dev/null' is not a device file.\n", level=logging.ERROR, noiselevel=-1) return 1 except OSError: writemsg_level( "Failed to validate a sane '/dev'.\n" "'/dev/null' does not exist.\n", level=logging.ERROR, noiselevel=-1) return 1 # Verify that BASH process substitution works as another cheap early # filter. Process substitution uses '/dev/fd'. with open(os.devnull, 'r+b') as dev_null: fd_pipes = { 0: dev_null.fileno(), 1: dev_null.fileno(), 2: dev_null.fileno(), } if portage.process.spawn_bash("[[ $(< <(echo foo) ) == foo ]]", fd_pipes=fd_pipes) != 0: writemsg_level( "Failed to validate a sane '/dev'.\n" "bash process substitution doesn't work; this may be an " "indication of a broken '/dev/fd'.\n", level=logging.ERROR, noiselevel=-1) return 1 # Portage needs to ensure a sane umask for the files it creates. os.umask(0o22) emerge_config = load_emerge_config(action=myaction, args=myfiles, opts=myopts) # Make locale variables from configuration files (make.defaults, make.conf) affect locale of emerge process. for locale_var_name in ("LANGUAGE", "LC_ALL", "LC_ADDRESS", "LC_COLLATE", "LC_CTYPE", "LC_IDENTIFICATION", "LC_MEASUREMENT", "LC_MESSAGES", "LC_MONETARY", "LC_NAME", "LC_NUMERIC", "LC_PAPER", "LC_TELEPHONE", "LC_TIME", "LANG"): locale_var_value = emerge_config.running_config.settings.get( locale_var_name) if locale_var_value is not None: os.environ.setdefault(locale_var_name, locale_var_value) try: locale.setlocale(locale.LC_ALL, "") except locale.Error as e: writemsg_level("setlocale: %s\n" % e, level=logging.WARN) tmpcmdline = [] if "--ignore-default-opts" not in myopts: tmpcmdline.extend( portage.util.shlex_split( emerge_config.target_config.settings.get( "EMERGE_DEFAULT_OPTS", ""))) tmpcmdline.extend(args) emerge_config.action, emerge_config.opts, emerge_config.args = \ parse_opts(tmpcmdline) try: return run_action(emerge_config) finally: # Call destructors for our portdbapi instances. for x in emerge_config.trees.values(): if "porttree" in x.lazy_items: continue x["porttree"].dbapi.close_caches()
def emerge_main(args=None): """ @param args: command arguments (default: sys.argv[1:]) @type args: list """ if args is None: args = sys.argv[1:] args = portage._decode_argv(args) # Use system locale. try: locale.setlocale(locale.LC_ALL, '') except locale.Error as e: writemsg_level("setlocale: %s\n" % e, level=logging.WARN) # Disable color until we're sure that it should be enabled (after # EMERGE_DEFAULT_OPTS has been parsed). portage.output.havecolor = 0 # This first pass is just for options that need to be known as early as # possible, such as --config-root. They will be parsed again later, # together with EMERGE_DEFAULT_OPTS (which may vary depending on the # the value of --config-root). myaction, myopts, myfiles = parse_opts(args, silent=True) if "--debug" in myopts: os.environ["PORTAGE_DEBUG"] = "1" if "--config-root" in myopts: os.environ["PORTAGE_CONFIGROOT"] = myopts["--config-root"] if "--root" in myopts: os.environ["ROOT"] = myopts["--root"] if "--prefix" in myopts: os.environ["EPREFIX"] = myopts["--prefix"] if "--accept-properties" in myopts: os.environ["ACCEPT_PROPERTIES"] = myopts["--accept-properties"] if "--accept-restrict" in myopts: os.environ["ACCEPT_RESTRICT"] = myopts["--accept-restrict"] # optimize --help (no need to load config / EMERGE_DEFAULT_OPTS) if myaction == "help": emerge_help() return os.EX_OK elif myaction == "moo": print(COWSAY_MOO % platform.system()) return os.EX_OK # Portage needs to ensure a sane umask for the files it creates. os.umask(0o22) if myaction == "sync": portage._sync_mode = True emerge_config = load_emerge_config(action=myaction, args=myfiles, opts=myopts) rval = profile_check(emerge_config.trees, emerge_config.action) if rval != os.EX_OK: return rval tmpcmdline = [] if "--ignore-default-opts" not in myopts: tmpcmdline.extend( portage.util.shlex_split( emerge_config.target_config.settings.get( "EMERGE_DEFAULT_OPTS", ""))) tmpcmdline.extend(args) emerge_config.action, emerge_config.opts, emerge_config.args = \ parse_opts(tmpcmdline) try: return run_action(emerge_config) finally: # Call destructors for our portdbapi instances. for x in emerge_config.trees.values(): if "porttree" in x.lazy_items: continue x["porttree"].dbapi.close_caches()