Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __call__(self, parser, namespace, values, option_string=None):
write_config(DEFAULT_CONF_FNAME)
parser.exit()
def save_prefs(options):
conf_dir = os.path.dirname(DEFAULT_CONF_FNAME)
if not os.path.isdir(conf_dir):
os.makedirs(conf_dir)
settings = ConfigObj(DEFAULT_CONF_FNAME)
settings.update(
{
"persist": options["persist"] or "",
"http-timeout": options["http_timeout"],
"persist-size-limit": options["persist_size_limit"],
"background_downloads": "yes" if options["background_downloads"] else "no",
"approx-policy": "auto" if options["approx_policy"] else "none",
"enable-telemetry": "yes" if options["enable_telemetry"] else "no",
}
)
# only save base url in the file if it differs from the default.
if options["archive_base_url"] and options["archive_base_url"] != ARCHIVE_BASE_URL:
settings["archive-base-url"] = options["archive_base_url"]
elif "archive-base-url" in settings:
del settings["archive-base-url"]
# likewise only save args if it has a value
def set_default_prefs():
"""Set the default prefs for a first launch of the application."""
if not os.path.isfile(DEFAULT_CONF_FNAME):
options = get_prefs()
options["persist"] = os.path.join(os.path.dirname(DEFAULT_CONF_FNAME), "persist")
options["persist_size_limit"] = 2.0
save_prefs(options)
def cli(argv=None, conf_file=DEFAULT_CONF_FNAME, namespace=None):
"""
parse cli args basically and returns a :class:`Configuration`.
if namespace is given, it will be used as a arg parsing result, so no
arg parsing will be done.
"""
config = get_config(conf_file)
if namespace:
options = namespace
else:
options = parse_args(argv=argv, defaults=config)
if not options.cmdargs:
# we don't set the cmdargs default to be that from the
# configuration file, because then any new arguments
# will be appended: https://bugs.python.org/issue16399
options.cmdargs = config["cmdargs"]
try:
# else, try to load a valid certificate locally
with open(TC_CREDENTIALS_FNAME) as f:
creds = json.load(f)
if not tc_utils.isExpired(creds["certificate"]):
return creds
except Exception:
pass
# here we need to ask for a certificate, this require web browser
# authentication
logger.info(
"Authentication required from taskcluster. We are going to ask for a"
" certificate.\nNote that if you have long term access you can instead"
" set your taskcluster-clientid and taskcluster-accesstoken in the"
" configuration file (%s)." % DEFAULT_CONF_FNAME
)
creds = tc_utils.authenticate("mozregression private build access")
# save the credentials and the certificate for later use
with open(TC_CREDENTIALS_FNAME, "w") as f:
json.dump(creds, f)
return creds
def save_prefs(options):
conf_dir = os.path.dirname(DEFAULT_CONF_FNAME)
if not os.path.isdir(conf_dir):
os.makedirs(conf_dir)
settings = ConfigObj(DEFAULT_CONF_FNAME)
settings.update(
{
"persist": options["persist"] or "",
"http-timeout": options["http_timeout"],
"persist-size-limit": options["persist_size_limit"],
"background_downloads": "yes" if options["background_downloads"] else "no",
"approx-policy": "auto" if options["approx_policy"] else "none",
"enable-telemetry": "yes" if options["enable_telemetry"] else "no",
}
)
# only save base url in the file if it differs from the default.
if options["archive_base_url"] and options["archive_base_url"] != ARCHIVE_BASE_URL: