Beispiel #1
0
def maketargets(args):
    """
    The targets must exist at the same path they should on the repo.
    
    This takes a list targets. We're not worrying about custom metadata at the
    moment. It's allowed to not provide keys.
    """
    options, args = getopt.getopt(args, "", ["keyid=", "metadir=", "parentdir=", "keystore=", "rolename="])
    opts = dict(options)
    fuzzy_keys = _get_key_ids(options)

    if len(args) < 1:
        usage()

    target_files = args

    meta = signerlib.generate_targets_meta(target_files)
    role = opts.get('--rolename', '')
    if not role:
        meta_dir = _get_meta_dir(options)
        filenames = _get_meta_filenames(meta_dir)
        dest = filenames['targets']
    else:
        dest = os.path.sep.join(meta, opts['--parentdir'], opts['--rolename'])
        dest += '.txt'
    _sign_and_write(meta, fuzzy_keys, dest, options)
def build_targets_txt(target_root, fuzzy_keys, key_db, server_root):
	server_root = os.path.abspath(server_root)
	target_root = os.path.abspath(target_root)
	logger.info(target_root)
	metadata_root = os.path.join(server_root, "meta")
	cwd = os.getcwd()
	os.chdir(server_root)
	server_root_length = len(server_root)
	# get the list of targets
	targets = []
	for root, dirs, files in walk(target_root):
		for target_file in files:
			targets.append(os.path.join(root, target_file)[server_root_length+1:])
	# feed it to signerlib
	targets_meta = signerlib.generate_targets_meta(targets)
	# sign it
	signed = signerlib.sign_meta(targets_meta, fuzzy_keys, key_db)
	# write it
	signerlib.write_metadata_file(signed, metadata_root + pathsep + "targets.txt")
	os.chdir(cwd)