Format code base with black

https://black.readthedocs.io/en/stable/

JIRA: COMPOSE-4086
Signed-off-by: Haibo Lin <hlin@redhat.com>
This commit is contained in:
Haibo Lin 2020-02-03 11:50:06 +08:00
parent 38142d30ba
commit 41a629969c
84 changed files with 5748 additions and 3325 deletions

View file

@ -11,24 +11,58 @@ from pungi.wrappers.comps import CompsFilter
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--output", help="redirect output to a file")
parser.add_argument("--arch", required=True,
help="filter groups and packages according to an arch")
parser.add_argument("--arch-only-groups", default=False, action="store_true",
help="keep only arch groups, remove the rest")
parser.add_argument("--arch-only-packages", default=False, action="store_true",
help="keep only arch packages, remove the rest")
parser.add_argument("--arch-only-environments", default=False, action="store_true",
help="keep only arch environments, remove the rest")
parser.add_argument("--remove-categories", default=False, action="store_true",
help="remove all categories")
parser.add_argument("--remove-langpacks", default=False, action="store_true",
help="remove the langpacks section")
parser.add_argument("--remove-translations", default=False, action="store_true",
help="remove all translations")
parser.add_argument("--remove-environments", default=False, action="store_true",
help="remove all environment sections")
parser.add_argument("--keep-empty-group", default=[], action="append", metavar="GROUPID",
help="keep groups even if they are empty")
parser.add_argument(
"--arch", required=True, help="filter groups and packages according to an arch"
)
parser.add_argument(
"--arch-only-groups",
default=False,
action="store_true",
help="keep only arch groups, remove the rest",
)
parser.add_argument(
"--arch-only-packages",
default=False,
action="store_true",
help="keep only arch packages, remove the rest",
)
parser.add_argument(
"--arch-only-environments",
default=False,
action="store_true",
help="keep only arch environments, remove the rest",
)
parser.add_argument(
"--remove-categories",
default=False,
action="store_true",
help="remove all categories",
)
parser.add_argument(
"--remove-langpacks",
default=False,
action="store_true",
help="remove the langpacks section",
)
parser.add_argument(
"--remove-translations",
default=False,
action="store_true",
help="remove all translations",
)
parser.add_argument(
"--remove-environments",
default=False,
action="store_true",
help="remove all environment sections",
)
parser.add_argument(
"--keep-empty-group",
default=[],
action="append",
metavar="GROUPID",
help="keep groups even if they are empty",
)
parser.add_argument(
"--lookaside-group",
default=[],
@ -36,13 +70,22 @@ def main():
metavar="GROUPID",
help="keep this group in environments even if they are not defined in the comps",
)
parser.add_argument("--no-cleanup", default=False, action="store_true",
help="don't remove empty groups and categories")
parser.add_argument("--no-reindent", default=False, action="store_true",
help="don't re-indent the output")
parser.add_argument("comps_file", metavar='COMPS_FILE')
parser.add_argument('--variant',
help='filter groups and packages according to variant name')
parser.add_argument(
"--no-cleanup",
default=False,
action="store_true",
help="don't remove empty groups and categories",
)
parser.add_argument(
"--no-reindent",
default=False,
action="store_true",
help="don't re-indent the output",
)
parser.add_argument("comps_file", metavar="COMPS_FILE")
parser.add_argument(
"--variant", help="filter groups and packages according to variant name"
)
opts = parser.parse_args()
@ -67,4 +110,4 @@ def main():
if opts.remove_environments:
f.remove_environments()
f.write(open(opts.output, 'wb') if opts.output else sys.stdout)
f.write(open(opts.output, "wb") if opts.output else sys.stdout)

View file

@ -34,29 +34,29 @@ class ValidationCompose(pungi.compose.Compose):
@property
def old_composes(self):
return '/dummy' if self.has_old_composes else None
return "/dummy" if self.has_old_composes else None
@property
def compose_id(self):
return 'Dummy-1.0-20160811.t.0'
return "Dummy-1.0-20160811.t.0"
@property
def compose_type(self):
return 'test'
return "test"
@property
def compose_date(self):
return '20160811'
return "20160811"
@property
def compose_respin(self):
return '0'
return "0"
def read_variants(compose, config):
with pungi.util.temp_dir() as tmp_dir:
scm_dict = compose.conf["variants_file"]
if isinstance(scm_dict, six.string_types) and scm_dict[0] != '/':
if isinstance(scm_dict, six.string_types) and scm_dict[0] != "/":
config_dir = os.path.dirname(config)
scm_dict = os.path.join(config_dir, scm_dict)
files = pungi.wrappers.scm.get_file_from_scm(scm_dict, tmp_dir)
@ -144,24 +144,29 @@ def run(config, topdir, has_old, offline, defined_variables, schema_overrides):
class DumpSchemaAction(argparse.Action):
def __call__(self, parser, ns, values, option_string=None):
json.dump(pungi.checks.make_schema(), sys.stdout,
sort_keys=True, indent=4)
print('')
json.dump(pungi.checks.make_schema(), sys.stdout, sort_keys=True, indent=4)
print("")
sys.exit(0)
def main(args=None):
parser = argparse.ArgumentParser()
parser.add_argument('--dump-schema', nargs=0, action=DumpSchemaAction,
help='print JSON Schema of configuration and exit')
parser.add_argument('config', metavar='CONFIG',
help='configuration file to validate')
parser.add_argument('--old-composes', action='store_true',
help='indicate if pungi-koji will be run with --old-composes option')
parser.add_argument(
"--offline",
"--dump-schema",
nargs=0,
action=DumpSchemaAction,
help="print JSON Schema of configuration and exit",
)
parser.add_argument(
"config", metavar="CONFIG", help="configuration file to validate"
)
parser.add_argument(
"--old-composes",
action="store_true",
help="Do not validate git references in URLs",
help="indicate if pungi-koji will be run with --old-composes option",
)
parser.add_argument(
"--offline", action="store_true", help="Do not validate git references in URLs",
)
parser.add_argument(
"-e",

View file

@ -18,10 +18,7 @@ def parse_args():
parser = argparse.ArgumentParser(add_help=True)
parser.add_argument(
'compose',
metavar='<compose-path>',
nargs=1,
help='path to compose',
"compose", metavar="<compose-path>", nargs=1, help="path to compose",
)
return parser.parse_args()

View file

@ -8,18 +8,18 @@ import sys
def send(cmd, data):
topic = 'compose.%s' % cmd.replace('-', '.').lower()
fedmsg.publish(topic=topic, modname='pungi', msg=data)
topic = "compose.%s" % cmd.replace("-", ".").lower()
fedmsg.publish(topic=topic, modname="pungi", msg=data)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('cmd')
parser.add_argument("cmd")
opts = parser.parse_args()
config = fedmsg.config.load_config()
config['active'] = True # Connect out to a fedmsg-relay instance
config['cert_prefix'] = 'releng' # Use this cert.
config["active"] = True # Connect out to a fedmsg-relay instance
config["cert_prefix"] = "releng" # Use this cert.
fedmsg.init(**config)
data = json.load(sys.stdin)

View file

@ -22,24 +22,32 @@ from pungi_utils import patch_iso
def main(args=None):
parser = argparse.ArgumentParser()
parser.add_argument('-v', '--verbose', action='store_true',
help='Print debugging information')
parser.add_argument('--supported', choices=('true', 'false'),
help='Override supported bit on the ISO')
parser.add_argument('--volume-id',
help='Override volume ID on the ISO')
parser.add_argument('--force-arch',
help='Treat the ISO as bootable on given architecture')
parser.add_argument('target', metavar='TARGET_ISO',
help='which file to write the result to')
parser.add_argument('source', metavar='SOURCE_ISO',
help='source ISO to work with')
parser.add_argument('dirs', nargs="+", metavar='GRAFT_DIR',
help='extra directories to graft on the ISO')
parser.add_argument(
"-v", "--verbose", action="store_true", help="Print debugging information"
)
parser.add_argument(
"--supported",
choices=("true", "false"),
help="Override supported bit on the ISO",
)
parser.add_argument("--volume-id", help="Override volume ID on the ISO")
parser.add_argument(
"--force-arch", help="Treat the ISO as bootable on given architecture"
)
parser.add_argument(
"target", metavar="TARGET_ISO", help="which file to write the result to"
)
parser.add_argument("source", metavar="SOURCE_ISO", help="source ISO to work with")
parser.add_argument(
"dirs",
nargs="+",
metavar="GRAFT_DIR",
help="extra directories to graft on the ISO",
)
opts = parser.parse_args(args)
level = logging.DEBUG if opts.verbose else logging.INFO
format = '%(levelname)s: %(message)s'
format = "%(levelname)s: %(message)s"
logging.basicConfig(level=level, format=format)
log = logging.getLogger()

View file

@ -30,142 +30,290 @@ def get_arguments(config):
class SetConfig(Action):
def __call__(self, parser, namespace, value, option_string=None):
config.set('pungi', self.dest, value)
config.set("pungi", self.dest, value)
parser.add_argument('--version', action='version', version=get_full_version())
parser.add_argument("--version", action="version", version=get_full_version())
# Pulled in from config file to be cli options as part of pykickstart conversion
parser.add_argument(
"--name", dest="family", type=str, action=SetConfig,
help='the name for your distribution (defaults to "Fedora"), DEPRECATED')
"--name",
dest="family",
type=str,
action=SetConfig,
help='the name for your distribution (defaults to "Fedora"), DEPRECATED',
)
parser.add_argument(
"--family", dest="family", action=SetConfig,
help='the family name for your distribution (defaults to "Fedora")')
"--family",
dest="family",
action=SetConfig,
help='the family name for your distribution (defaults to "Fedora")',
)
parser.add_argument(
"--ver", dest="version", action=SetConfig,
help='the version of your distribution (defaults to datestamp)')
"--ver",
dest="version",
action=SetConfig,
help="the version of your distribution (defaults to datestamp)",
)
parser.add_argument(
"--flavor", dest="variant", action=SetConfig,
help='the flavor of your distribution spin (optional), DEPRECATED')
"--flavor",
dest="variant",
action=SetConfig,
help="the flavor of your distribution spin (optional), DEPRECATED",
)
parser.add_argument(
"--variant", dest="variant", action=SetConfig,
help='the variant of your distribution spin (optional)')
"--variant",
dest="variant",
action=SetConfig,
help="the variant of your distribution spin (optional)",
)
parser.add_argument(
"--destdir", dest="destdir", action=SetConfig,
help='destination directory (defaults to current directory)')
"--destdir",
dest="destdir",
action=SetConfig,
help="destination directory (defaults to current directory)",
)
parser.add_argument(
"--cachedir", dest="cachedir", action=SetConfig,
help='package cache directory (defaults to /var/cache/pungi)')
"--cachedir",
dest="cachedir",
action=SetConfig,
help="package cache directory (defaults to /var/cache/pungi)",
)
parser.add_argument(
"--bugurl", dest="bugurl", action=SetConfig,
help='the url for your bug system (defaults to http://bugzilla.redhat.com)')
"--bugurl",
dest="bugurl",
action=SetConfig,
help="the url for your bug system (defaults to http://bugzilla.redhat.com)",
)
parser.add_argument(
"--selfhosting", action="store_true", dest="selfhosting",
help='build a self-hosting tree by following build dependencies (optional)')
"--selfhosting",
action="store_true",
dest="selfhosting",
help="build a self-hosting tree by following build dependencies (optional)",
)
parser.add_argument(
"--fulltree", action="store_true", dest="fulltree",
help='build a tree that includes all packages built from corresponding source rpms (optional)')
"--fulltree",
action="store_true",
dest="fulltree",
help="build a tree that includes all packages built from corresponding source rpms (optional)",
)
parser.add_argument(
"--nosource", action="store_true", dest="nosource",
help='disable gathering of source packages (optional)')
"--nosource",
action="store_true",
dest="nosource",
help="disable gathering of source packages (optional)",
)
parser.add_argument(
"--nodebuginfo", action="store_true", dest="nodebuginfo",
help='disable gathering of debuginfo packages (optional)')
"--nodebuginfo",
action="store_true",
dest="nodebuginfo",
help="disable gathering of debuginfo packages (optional)",
)
parser.add_argument(
"--nodownload", action="store_true", dest="nodownload",
help='disable downloading of packages. instead, print the package URLs (optional)')
"--nodownload",
action="store_true",
dest="nodownload",
help="disable downloading of packages. instead, print the package URLs (optional)",
)
parser.add_argument(
"--norelnotes", action="store_true", dest="norelnotes",
help='disable gathering of release notes (optional); DEPRECATED')
"--norelnotes",
action="store_true",
dest="norelnotes",
help="disable gathering of release notes (optional); DEPRECATED",
)
parser.add_argument(
"--nogreedy", action="store_true", dest="nogreedy",
help='disable pulling of all providers of package dependencies (optional)')
"--nogreedy",
action="store_true",
dest="nogreedy",
help="disable pulling of all providers of package dependencies (optional)",
)
parser.add_argument(
"--nodeps", action="store_false", dest="resolve_deps", default=True,
help='disable resolving dependencies')
"--nodeps",
action="store_false",
dest="resolve_deps",
default=True,
help="disable resolving dependencies",
)
parser.add_argument(
"--sourceisos", default=False, action="store_true", dest="sourceisos",
help='Create the source isos (other arch runs must be done)')
"--sourceisos",
default=False,
action="store_true",
dest="sourceisos",
help="Create the source isos (other arch runs must be done)",
)
parser.add_argument(
"--force", default=False, action="store_true",
help='Force reuse of an existing destination directory (will overwrite files)')
"--force",
default=False,
action="store_true",
help="Force reuse of an existing destination directory (will overwrite files)",
)
parser.add_argument(
"--isfinal", default=False, action="store_true",
help='Specify this is a GA tree, which causes betanag to be turned off during install')
"--isfinal",
default=False,
action="store_true",
help="Specify this is a GA tree, which causes betanag to be turned off during install",
)
parser.add_argument(
"--nohash", default=False, action="store_true",
help='disable hashing the Packages trees')
"--nohash",
default=False,
action="store_true",
help="disable hashing the Packages trees",
)
parser.add_argument(
"--full-archlist", action="store_true",
help='Use the full arch list for x86_64 (include i686, i386, etc.)')
parser.add_argument("--arch", help='Override default (uname based) arch')
"--full-archlist",
action="store_true",
help="Use the full arch list for x86_64 (include i686, i386, etc.)",
)
parser.add_argument("--arch", help="Override default (uname based) arch")
parser.add_argument(
"--greedy", metavar="METHOD",
help='Greedy method; none, all, build')
"--greedy", metavar="METHOD", help="Greedy method; none, all, build"
)
parser.add_argument(
"--multilib", action="append", metavar="METHOD",
help='Multilib method; can be specified multiple times; recommended: devel, runtime')
"--multilib",
action="append",
metavar="METHOD",
help="Multilib method; can be specified multiple times; recommended: devel, runtime",
)
parser.add_argument(
"--lookaside-repo", action="append", dest="lookaside_repos", metavar="NAME",
help='Specify lookaside repo name(s) (packages will used for depsolving but not be included in the output)')
"--lookaside-repo",
action="append",
dest="lookaside_repos",
metavar="NAME",
help="Specify lookaside repo name(s) (packages will used for depsolving but not be included in the output)",
)
parser.add_argument(
"--workdirbase", dest="workdirbase", action=SetConfig,
help='base working directory (defaults to destdir + /work)')
parser.add_argument("--no-dvd", default=False, action="store_true", dest="no_dvd",
help='Do not make a install DVD/CD only the netinstall image and the tree')
parser.add_argument("--lorax-conf",
help='Path to lorax.conf file (optional)')
"--workdirbase",
dest="workdirbase",
action=SetConfig,
help="base working directory (defaults to destdir + /work)",
)
parser.add_argument(
"-i", "--installpkgs", default=[], action="append", metavar="STRING",
help="Package glob for lorax to install before runtime-install.tmpl runs. (may be listed multiple times)")
"--no-dvd",
default=False,
action="store_true",
dest="no_dvd",
help="Do not make a install DVD/CD only the netinstall image and the tree",
)
parser.add_argument("--lorax-conf", help="Path to lorax.conf file (optional)")
parser.add_argument(
"--multilibconf", default=None, action=SetConfig,
help="Path to multilib conf files. Default is /usr/share/pungi/multilib/")
parser.add_argument("-c", "--config", dest="config", required=True,
help='Path to kickstart config file')
parser.add_argument("--all-stages", action="store_true", default=True, dest="do_all",
help="Enable ALL stages")
parser.add_argument("-G", action="store_true", default=False, dest="do_gather",
help="Flag to enable processing the Gather stage")
parser.add_argument("-C", action="store_true", default=False, dest="do_createrepo",
help="Flag to enable processing the Createrepo stage")
parser.add_argument("-B", action="store_true", default=False, dest="do_buildinstall",
help="Flag to enable processing the BuildInstall stage")
parser.add_argument("-I", action="store_true", default=False, dest="do_createiso",
help="Flag to enable processing the CreateISO stage")
parser.add_argument("--relnotepkgs", dest="relnotepkgs", action=SetConfig,
help='Rpms which contain the release notes')
"-i",
"--installpkgs",
default=[],
action="append",
metavar="STRING",
help="Package glob for lorax to install before runtime-install.tmpl runs. (may be listed multiple times)",
)
parser.add_argument(
"--relnotefilere", dest="relnotefilere", action=SetConfig,
help='Which files are the release notes -- GPL EULA')
parser.add_argument("--nomacboot", action="store_true", dest="nomacboot",
help='disable setting up macboot as no hfs support ')
"--multilibconf",
default=None,
action=SetConfig,
help="Path to multilib conf files. Default is /usr/share/pungi/multilib/",
)
parser.add_argument(
"--rootfs-size", dest="rootfs_size", action=SetConfig, default=False,
help='Size of root filesystem in GiB. If not specified, use lorax default value')
"-c",
"--config",
dest="config",
required=True,
help="Path to kickstart config file",
)
parser.add_argument(
"--all-stages",
action="store_true",
default=True,
dest="do_all",
help="Enable ALL stages",
)
parser.add_argument(
"-G",
action="store_true",
default=False,
dest="do_gather",
help="Flag to enable processing the Gather stage",
)
parser.add_argument(
"-C",
action="store_true",
default=False,
dest="do_createrepo",
help="Flag to enable processing the Createrepo stage",
)
parser.add_argument(
"-B",
action="store_true",
default=False,
dest="do_buildinstall",
help="Flag to enable processing the BuildInstall stage",
)
parser.add_argument(
"-I",
action="store_true",
default=False,
dest="do_createiso",
help="Flag to enable processing the CreateISO stage",
)
parser.add_argument(
"--relnotepkgs",
dest="relnotepkgs",
action=SetConfig,
help="Rpms which contain the release notes",
)
parser.add_argument(
"--relnotefilere",
dest="relnotefilere",
action=SetConfig,
help="Which files are the release notes -- GPL EULA",
)
parser.add_argument(
"--nomacboot",
action="store_true",
dest="nomacboot",
help="disable setting up macboot as no hfs support ",
)
parser.add_argument(
"--pungirc", dest="pungirc", default='~/.pungirc', action=SetConfig,
help='Read pungi options from config file ')
"--rootfs-size",
dest="rootfs_size",
action=SetConfig,
default=False,
help="Size of root filesystem in GiB. If not specified, use lorax default value",
)
parser.add_argument(
"--pungirc",
dest="pungirc",
default="~/.pungirc",
action=SetConfig,
help="Read pungi options from config file ",
)
opts = parser.parse_args()
if not config.get('pungi', 'variant').isalnum() and not config.get('pungi', 'variant') == '':
if (
not config.get("pungi", "variant").isalnum()
and not config.get("pungi", "variant") == ""
):
parser.error("Variant must be alphanumeric")
if opts.do_gather or opts.do_createrepo or opts.do_buildinstall or opts.do_createiso:
if (
opts.do_gather
or opts.do_createrepo
or opts.do_buildinstall
or opts.do_createiso
):
opts.do_all = False
if opts.arch and (opts.do_all or opts.do_buildinstall):
parser.error("Cannot override arch while the BuildInstall stage is enabled")
# set the iso_basename.
if not config.get('pungi', 'variant') == '':
config.set('pungi', 'iso_basename', '%s-%s' % (config.get('pungi', 'family'), config.get('pungi', 'variant')))
if not config.get("pungi", "variant") == "":
config.set(
"pungi",
"iso_basename",
"%s-%s" % (config.get("pungi", "family"), config.get("pungi", "variant")),
)
else:
config.set('pungi', 'iso_basename', config.get('pungi', 'family'))
config.set("pungi", "iso_basename", config.get("pungi", "family"))
return opts
@ -192,45 +340,53 @@ def main():
print("INFO: selinux disabled")
enforcing = False
if enforcing:
print("WARNING: SELinux is enforcing. This may lead to a compose with selinux disabled.")
print(
"WARNING: SELinux is enforcing. This may lead to a compose with selinux disabled."
)
print("Consider running with setenforce 0.")
# Set up the kickstart parser and pass in the kickstart file we were handed
ksparser = pungi.ks.get_ksparser(ks_path=opts.config)
if opts.sourceisos:
config.set('pungi', 'arch', 'source')
config.set("pungi", "arch", "source")
for part in ksparser.handler.partition.partitions:
if part.mountpoint == 'iso':
config.set('pungi', 'cdsize', str(part.size))
if part.mountpoint == "iso":
config.set("pungi", "cdsize", str(part.size))
config.set('pungi', 'force', str(opts.force))
config.set("pungi", "force", str(opts.force))
if config.get('pungi', 'workdirbase') == '/work':
config.set('pungi', 'workdirbase', "%s/work" % config.get('pungi', 'destdir'))
if config.get("pungi", "workdirbase") == "/work":
config.set("pungi", "workdirbase", "%s/work" % config.get("pungi", "destdir"))
# Set up our directories
if not os.path.exists(config.get('pungi', 'destdir')):
if not os.path.exists(config.get("pungi", "destdir")):
try:
os.makedirs(config.get('pungi', 'destdir'))
os.makedirs(config.get("pungi", "destdir"))
except OSError:
print("Error: Cannot create destination dir %s" % config.get('pungi', 'destdir'),
file=sys.stderr)
print(
"Error: Cannot create destination dir %s"
% config.get("pungi", "destdir"),
file=sys.stderr,
)
sys.exit(1)
else:
print("Warning: Reusing existing destination directory.")
if not os.path.exists(config.get('pungi', 'workdirbase')):
if not os.path.exists(config.get("pungi", "workdirbase")):
try:
os.makedirs(config.get('pungi', 'workdirbase'))
os.makedirs(config.get("pungi", "workdirbase"))
except OSError:
print("Error: Cannot create working base dir %s" % config.get('pungi', 'workdirbase'),
file=sys.stderr)
print(
"Error: Cannot create working base dir %s"
% config.get("pungi", "workdirbase"),
file=sys.stderr,
)
sys.exit(1)
else:
print("Warning: Reusing existing working base directory.")
cachedir = config.get('pungi', 'cachedir')
cachedir = config.get("pungi", "cachedir")
if not os.path.exists(cachedir):
try:
@ -241,32 +397,32 @@ def main():
# Set debuginfo flag
if opts.nodebuginfo:
config.set('pungi', 'debuginfo', "False")
config.set("pungi", "debuginfo", "False")
if opts.greedy:
config.set('pungi', 'greedy', opts.greedy)
config.set("pungi", "greedy", opts.greedy)
else:
# XXX: compatibility
if opts.nogreedy:
config.set('pungi', 'greedy', "none")
config.set("pungi", "greedy", "none")
else:
config.set('pungi', 'greedy', "all")
config.set('pungi', 'resolve_deps', str(bool(opts.resolve_deps)))
config.set("pungi", "greedy", "all")
config.set("pungi", "resolve_deps", str(bool(opts.resolve_deps)))
if opts.isfinal:
config.set('pungi', 'isfinal', "True")
config.set("pungi", "isfinal", "True")
if opts.nohash:
config.set('pungi', 'nohash', "True")
config.set("pungi", "nohash", "True")
if opts.full_archlist:
config.set('pungi', 'full_archlist', "True")
config.set("pungi", "full_archlist", "True")
if opts.arch:
config.set('pungi', 'arch', opts.arch)
config.set("pungi", "arch", opts.arch)
if opts.multilib:
config.set('pungi', 'multilib', " ".join(opts.multilib))
config.set("pungi", "multilib", " ".join(opts.multilib))
if opts.lookaside_repos:
config.set('pungi', 'lookaside_repos', " ".join(opts.lookaside_repos))
config.set("pungi", "lookaside_repos", " ".join(opts.lookaside_repos))
if opts.no_dvd:
config.set('pungi', 'no_dvd', "True")
config.set("pungi", "no_dvd", "True")
if opts.nomacboot:
config.set('pungi', 'nomacboot', "True")
config.set("pungi", "nomacboot", "True")
config.set("pungi", "fulltree", str(bool(opts.fulltree)))
config.set("pungi", "selfhosting", str(bool(opts.selfhosting)))
config.set("pungi", "nosource", str(bool(opts.nosource)))
@ -303,7 +459,9 @@ def main():
flags_str = ",".join(line["flags"])
if flags_str:
flags_str = "(%s)" % flags_str
sys.stdout.write("DEBUGINFO%s: %s\n" % (flags_str, line["path"]))
sys.stdout.write(
"DEBUGINFO%s: %s\n" % (flags_str, line["path"])
)
sys.stdout.flush()
else:
mypungi.downloadDebuginfo()
@ -320,7 +478,10 @@ def main():
print("RPM size: %s MiB" % (mypungi.size_packages() / 1024 ** 2))
if not opts.nodebuginfo:
print("DEBUGINFO size: %s MiB" % (mypungi.size_debuginfo() / 1024 ** 2))
print(
"DEBUGINFO size: %s MiB"
% (mypungi.size_debuginfo() / 1024 ** 2)
)
if not opts.nosource:
print("SRPM size: %s MiB" % (mypungi.size_srpms() / 1024 ** 2))
@ -340,10 +501,13 @@ def main():
# Do things slightly different for src.
if opts.sourceisos:
# we already have all the content gathered
mypungi.topdir = os.path.join(config.get('pungi', 'destdir'),
config.get('pungi', 'version'),
config.get('pungi', 'variant'),
'source', 'SRPMS')
mypungi.topdir = os.path.join(
config.get("pungi", "destdir"),
config.get("pungi", "version"),
config.get("pungi", "variant"),
"source",
"SRPMS",
)
mypungi.doCreaterepo(comps=False)
if opts.do_all or opts.do_createiso:
mypungi.doCreateIsos()

View file

@ -18,22 +18,17 @@ from pungi.util import temp_dir
def get_parser():
parser = argparse.ArgumentParser()
parser.add_argument(
"--profiler",
action="store_true",
"--profiler", action="store_true",
)
parser.add_argument(
"--arch",
required=True,
"--arch", required=True,
)
parser.add_argument(
"--config",
metavar="PATH",
required=True,
help="path to kickstart config file",
"--config", metavar="PATH", required=True, help="path to kickstart config file",
)
parser.add_argument(
"--download-to",
metavar='PATH',
metavar="PATH",
help="download packages to given directory instead of just printing paths",
)
@ -47,9 +42,7 @@ def get_parser():
group = parser.add_argument_group("Gather options")
group.add_argument(
"--nodeps",
action="store_true",
help="disable resolving dependencies",
"--nodeps", action="store_true", help="disable resolving dependencies",
)
group.add_argument(
"--selfhosting",
@ -68,9 +61,7 @@ def get_parser():
choices=["none", "all", "build"],
)
group.add_argument(
"--multilib",
metavar="[METHOD]",
action="append",
"--multilib", metavar="[METHOD]", action="append",
)
group.add_argument(
"--tempdir",
@ -135,13 +126,13 @@ def main(ns, persistdir, cachedir):
continue
if not getattr(ks_repo, "metalink", False):
dnf_obj.add_repo(
ks_repo.name, ks_repo.baseurl, enablegroups=False
)
dnf_obj.add_repo(ks_repo.name, ks_repo.baseurl, enablegroups=False)
else:
dnf_obj.add_repo(
ks_repo.name, ks_repo.baseurl, enablegroups=False,
metalink=ks_repo.metalink
ks_repo.name,
ks_repo.baseurl,
enablegroups=False,
metalink=ks_repo.metalink,
)
for ks_repo in ksparser.handler.repo.repoList:
@ -150,8 +141,7 @@ def main(ns, persistdir, cachedir):
if not getattr(ks_repo, "metalink", False):
dnf_obj.add_repo(ks_repo.name, ks_repo.baseurl)
else:
dnf_obj.add_repo(ks_repo.name, ks_repo.baseurl,
metalink=ks_repo.metalink)
dnf_obj.add_repo(ks_repo.name, ks_repo.baseurl, metalink=ks_repo.metalink)
with Profiler("DnfWrapper.fill_sack()"):
dnf_obj.fill_sack(load_system_repo=False, load_available_repos=True)
@ -190,7 +180,7 @@ def _get_url(pkg):
def _fmt_flags(flags):
return "(%s)" % ",".join(sorted(f.name.replace('_', '-') for f in flags))
return "(%s)" % ",".join(sorted(f.name.replace("_", "-") for f in flags))
def deduplicate(gather_obj, items):

View file

@ -35,7 +35,7 @@ COMPOSE = None
def main():
global COMPOSE
PHASES_NAMES_MODIFIED = PHASES_NAMES + ['productimg']
PHASES_NAMES_MODIFIED = PHASES_NAMES + ["productimg"]
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group(required=True)
@ -51,19 +51,19 @@ def main():
)
parser.add_argument(
"--label",
help="specify compose label (example: Snapshot-1.0); required for production composes"
help="specify compose label (example: Snapshot-1.0); required for production composes",
)
parser.add_argument(
"--no-label",
action="store_true",
default=False,
help="make a production compose without label"
help="make a production compose without label",
)
parser.add_argument(
"--supported",
action="store_true",
default=False,
help="set supported flag on media (automatically on for 'RC-x.y' labels)"
help="set supported flag on media (automatically on for 'RC-x.y' labels)",
)
parser.add_argument(
"--old-composes",
@ -73,11 +73,7 @@ def main():
action="append",
help="Path to directory with old composes. Reuse an existing repodata from the most recent compose.",
)
parser.add_argument(
"--config",
help="Config file",
required=True
)
parser.add_argument("--config", help="Config file", required=True)
parser.add_argument(
"--skip-phase",
metavar="PHASE",
@ -127,7 +123,7 @@ def main():
metavar="ID",
type=util.parse_koji_event,
help="specify a koji event for populating package set, either as event ID "
"or a path to a compose from which to reuse the event",
"or a path to a compose from which to reuse the event",
)
parser.add_argument(
"--version",
@ -139,14 +135,14 @@ def main():
"--notification-script",
action="append",
default=[],
help="script for sending progress notification messages"
help="script for sending progress notification messages",
)
parser.add_argument(
"--no-latest-link",
action="store_true",
default=False,
dest="no_latest_link",
help="don't create latest symbol link to this compose"
help="don't create latest symbol link to this compose",
)
parser.add_argument(
"--latest-link-status",
@ -159,23 +155,30 @@ def main():
"--print-output-dir",
action="store_true",
default=False,
help="print the compose directory"
help="print the compose directory",
)
parser.add_argument(
"--quiet",
action="store_true",
default=False,
help="quiet mode, don't print log on screen"
help="quiet mode, don't print log on screen",
)
opts = parser.parse_args()
import pungi.notifier
notifier = pungi.notifier.PungiNotifier(opts.notification_script)
def fail_to_start(msg, **kwargs):
notifier.send('fail-to-start', workdir=opts.target_dir,
command=sys.argv, target_dir=opts.target_dir,
config=opts.config, detail=msg, **kwargs)
notifier.send(
"fail-to-start",
workdir=opts.target_dir,
command=sys.argv,
target_dir=opts.target_dir,
config=opts.config,
detail=msg,
**kwargs
)
def abort(msg):
fail_to_start(msg)
@ -184,11 +187,17 @@ def main():
if opts.target_dir and not opts.compose_dir:
opts.target_dir = os.path.abspath(opts.target_dir)
if not os.path.isdir(opts.target_dir):
abort("The target directory does not exist or is not a directory: %s" % opts.target_dir)
abort(
"The target directory does not exist or is not a directory: %s"
% opts.target_dir
)
else:
opts.compose_dir = os.path.abspath(opts.compose_dir)
if not os.path.isdir(opts.compose_dir):
abort("The compose directory does not exist or is not a directory: %s" % opts.compose_dir)
abort(
"The compose directory does not exist or is not a directory: %s"
% opts.compose_dir
)
opts.config = os.path.abspath(opts.config)
@ -214,12 +223,13 @@ def main():
conf = util.load_config(opts.config)
compose_type = opts.compose_type or conf.get('compose_type', 'production')
compose_type = opts.compose_type or conf.get("compose_type", "production")
if compose_type == "production" and not opts.label and not opts.no_label:
abort("must specify label for a production compose")
# check if all requirements are met
import pungi.checks
if not pungi.checks.check(conf):
sys.exit(1)
pungi.checks.check_umask(logger)
@ -229,8 +239,11 @@ def main():
# TODO: workaround for config files containing skip_phase = productimg
# Remove when all config files are up to date
if 'productimg' in opts.skip_phase or 'productimg' in opts.just_phase:
print('WARNING: productimg phase has been removed, please remove it from --skip-phase or --just-phase option', file=sys.stderr)
if "productimg" in opts.skip_phase or "productimg" in opts.just_phase:
print(
"WARNING: productimg phase has been removed, please remove it from --skip-phase or --just-phase option",
file=sys.stderr,
)
for err in errors[:]:
if "'productimg' is not one of" in err:
errors.remove(err)
@ -242,29 +255,37 @@ def main():
if errors:
for error in errors:
print(error, file=sys.stderr)
fail_to_start('Config validation failed', errors=errors)
fail_to_start("Config validation failed", errors=errors)
sys.exit(1)
if opts.target_dir:
compose_dir = Compose.get_compose_dir(opts.target_dir, conf, compose_type=compose_type, compose_label=opts.label)
compose_dir = Compose.get_compose_dir(
opts.target_dir, conf, compose_type=compose_type, compose_label=opts.label
)
else:
compose_dir = opts.compose_dir
if opts.print_output_dir:
print('Compose dir: %s' % compose_dir)
print("Compose dir: %s" % compose_dir)
compose = Compose(conf,
topdir=compose_dir,
skip_phases=opts.skip_phase,
just_phases=opts.just_phase,
old_composes=opts.old_composes,
koji_event=opts.koji_event,
supported=opts.supported,
logger=logger,
notifier=notifier)
compose = Compose(
conf,
topdir=compose_dir,
skip_phases=opts.skip_phase,
just_phases=opts.just_phase,
old_composes=opts.old_composes,
koji_event=opts.koji_event,
supported=opts.supported,
logger=logger,
notifier=notifier,
)
notifier.compose = compose
COMPOSE = compose
run_compose(compose, create_latest_link=create_latest_link, latest_link_status=latest_link_status)
run_compose(
compose,
create_latest_link=create_latest_link,
latest_link_status=latest_link_status,
)
def run_compose(compose, create_latest_link=True, latest_link_status=None):
@ -279,7 +300,9 @@ def run_compose(compose, create_latest_link=True, latest_link_status=None):
compose.log_info("Pungi version: %s" % get_full_version())
compose.log_info("User name: %s" % getpass.getuser())
compose.log_info("Working directory: %s" % os.getcwd())
compose.log_info("Command line: %s" % " ".join([shlex_quote(arg) for arg in sys.argv]))
compose.log_info(
"Command line: %s" % " ".join([shlex_quote(arg) for arg in sys.argv])
)
compose.log_info("Compose top directory: %s" % compose.topdir)
compose.log_info("Current timezone offset: %s" % pungi.util.get_tz_offset())
compose.read_variants()
@ -301,7 +324,9 @@ def run_compose(compose, create_latest_link=True, latest_link_status=None):
gather_phase = pungi.phases.GatherPhase(compose, pkgset_phase)
extrafiles_phase = pungi.phases.ExtraFilesPhase(compose, pkgset_phase)
createrepo_phase = pungi.phases.CreaterepoPhase(compose, pkgset_phase)
ostree_installer_phase = pungi.phases.OstreeInstallerPhase(compose, buildinstall_phase, pkgset_phase)
ostree_installer_phase = pungi.phases.OstreeInstallerPhase(
compose, buildinstall_phase, pkgset_phase
)
ostree_phase = pungi.phases.OSTreePhase(compose, pkgset_phase)
createiso_phase = pungi.phases.CreateisoPhase(compose, buildinstall_phase)
extra_isos_phase = pungi.phases.ExtraIsosPhase(compose)
@ -313,12 +338,24 @@ def run_compose(compose, create_latest_link=True, latest_link_status=None):
test_phase = pungi.phases.TestPhase(compose)
# check if all config options are set
for phase in (init_phase, pkgset_phase, createrepo_phase,
buildinstall_phase, gather_phase,
extrafiles_phase, createiso_phase, liveimages_phase,
livemedia_phase, image_build_phase, image_checksum_phase,
test_phase, ostree_phase, ostree_installer_phase,
extra_isos_phase, osbs_phase):
for phase in (
init_phase,
pkgset_phase,
createrepo_phase,
buildinstall_phase,
gather_phase,
extrafiles_phase,
createiso_phase,
liveimages_phase,
livemedia_phase,
image_build_phase,
image_checksum_phase,
test_phase,
ostree_phase,
ostree_installer_phase,
extra_isos_phase,
osbs_phase,
):
if phase.skip():
continue
try:
@ -330,7 +367,7 @@ def run_compose(compose, create_latest_link=True, latest_link_status=None):
for i in errors:
compose.log_error(i)
print(i)
raise RuntimeError('Configuration is not valid')
raise RuntimeError("Configuration is not valid")
# PREP
@ -338,10 +375,12 @@ def run_compose(compose, create_latest_link=True, latest_link_status=None):
# in same way as .validate() or .run()
# Prep for liveimages - Obtain a password for signing rpm wrapped images
if ("signing_key_password_file" in compose.conf
and "signing_command" in compose.conf
and "%(signing_key_password)s" in compose.conf["signing_command"]
and not liveimages_phase.skip()):
if (
"signing_key_password_file" in compose.conf
and "signing_command" in compose.conf
and "%(signing_key_password)s" in compose.conf["signing_command"]
and not liveimages_phase.skip()
):
# TODO: Don't require key if signing is turned off
# Obtain signing key password
signing_key_password = None
@ -357,7 +396,11 @@ def run_compose(compose, create_latest_link=True, latest_link_status=None):
else:
# Use text file with password
try:
signing_key_password = open(compose.conf["signing_key_password_file"], "r").readline().rstrip('\n')
signing_key_password = (
open(compose.conf["signing_key_password_file"], "r")
.readline()
.rstrip("\n")
)
except IOError:
# Filename is not print intentionally in case someone puts password directly into the option
err_msg = "Cannot load password from file specified by 'signing_key_password_file' option"
@ -388,7 +431,9 @@ def run_compose(compose, create_latest_link=True, latest_link_status=None):
# write treeinfo before ISOs are created
for variant in compose.get_variants():
for arch in variant.arches + ["src"]:
pungi.metadata.write_tree_info(compose, arch, variant, bi=buildinstall_phase)
pungi.metadata.write_tree_info(
compose, arch, variant, bi=buildinstall_phase
)
# write .discinfo and media.repo before ISOs are created
for variant in compose.get_variants():
@ -441,17 +486,28 @@ def run_compose(compose, create_latest_link=True, latest_link_status=None):
if compose.get_status() in [s.upper() for s in latest_link_status]:
latest_link = True
else:
compose.log_warning("Compose status (%s) doesn't match with specified latest-link-status (%s), not create latest link."
% (compose.get_status(), str(latest_link_status)))
compose.log_warning(
"Compose status (%s) doesn't match with specified latest-link-status (%s), not create latest link."
% (compose.get_status(), str(latest_link_status))
)
if latest_link:
compose_dir = os.path.basename(compose.topdir)
if len(compose.conf["release_version"].split(".")) == 1:
symlink_name = "latest-%s-%s" % (compose.conf["release_short"], compose.conf["release_version"])
symlink_name = "latest-%s-%s" % (
compose.conf["release_short"],
compose.conf["release_version"],
)
else:
symlink_name = "latest-%s-%s" % (compose.conf["release_short"], ".".join(compose.conf["release_version"].split(".")[:-1]))
symlink_name = "latest-%s-%s" % (
compose.conf["release_short"],
".".join(compose.conf["release_version"].split(".")[:-1]),
)
if compose.conf.get("base_product_name", ""):
symlink_name += "-%s-%s" % (compose.conf["base_product_short"], compose.conf["base_product_version"])
symlink_name += "-%s-%s" % (
compose.conf["base_product_short"],
compose.conf["base_product_version"],
)
symlink = os.path.join(compose.topdir, "..", symlink_name)
try:
@ -471,8 +527,7 @@ def run_compose(compose, create_latest_link=True, latest_link_status=None):
def sigterm_handler(signum, frame):
if COMPOSE:
COMPOSE.log_error("Compose run failed: signal %s" % signum)
COMPOSE.log_error("Traceback:\n%s"
% '\n'.join(traceback.format_stack(frame)))
COMPOSE.log_error("Traceback:\n%s" % "\n".join(traceback.format_stack(frame)))
COMPOSE.log_critical("Compose failed: %s" % COMPOSE.topdir)
COMPOSE.write_status("TERMINATED")
else:
@ -495,6 +550,7 @@ def cli_main():
COMPOSE.log_critical("Compose failed: %s" % COMPOSE.topdir)
COMPOSE.write_status("DOOMED")
import kobo.tback
with open(tb_path, "wb") as f:
f.write(kobo.tback.Traceback().get_traceback())
else:

View file

@ -8,7 +8,7 @@ import sys
def main():
parser = argparse.ArgumentParser()
parser.add_argument('cmd')
parser.add_argument("cmd")
opts = parser.parse_args()
data = json.load(sys.stdin)

View file

@ -39,40 +39,40 @@ def ts_log(msg):
def main():
parser = argparse.ArgumentParser()
parser.add_argument('cmd')
parser.add_argument("cmd")
opts = parser.parse_args()
if opts.cmd != 'ostree':
if opts.cmd != "ostree":
# Not an announcement of new ostree commit, nothing to do.
sys.exit()
try:
data = json.load(sys.stdin)
except ValueError:
print('Failed to decode data', file=sys.stderr)
print("Failed to decode data", file=sys.stderr)
sys.exit(1)
repo = data['local_repo_path']
commit = data['commitid']
repo = data["local_repo_path"]
commit = data["commitid"]
if not commit:
print("No new commit was created, nothing will get signed.")
sys.exit(0)
path = '%s/objects/%s/%s.commitmeta' % (repo, commit[:2], commit[2:])
path = "%s/objects/%s/%s.commitmeta" % (repo, commit[:2], commit[2:])
config = fedmsg.config.load_config()
config['active'] = True # Connect out to a fedmsg-relay instance
config['cert_prefix'] = 'releng' # Use this cert.
config["active"] = True # Connect out to a fedmsg-relay instance
config["cert_prefix"] = "releng" # Use this cert.
fedmsg.init(**config)
topic = 'compose.%s' % opts.cmd.replace('-', '.').lower()
topic = "compose.%s" % opts.cmd.replace("-", ".").lower()
count = 0
while not os.path.exists(path):
ts_log("Commit not signed yet, waiting...")
count += 1
if count >= 60: # Repeat every 5 minutes
print('Repeating notification')
fedmsg.publish(topic=topic, modname='pungi', msg=data)
print("Repeating notification")
fedmsg.publish(topic=topic, modname="pungi", msg=data)
count = 0
time.sleep(5)