コード例 #1
0
ファイル: repos.py プロジェクト: tclh123/portage
def repo_metadata(portdb, repoman_settings):
    # get lists of valid keywords, licenses, and use
    kwlist = set()
    liclist = set()
    uselist = set()
    profile_list = []
    global_pmasklines = []

    for path in portdb.porttrees:
        try:
            liclist.update(os.listdir(os.path.join(path, "licenses")))
        except OSError:
            pass
        kwlist.update(
            portage.grabfile(os.path.join(path, "profiles", "arch.list")))

        use_desc = portage.grabfile(os.path.join(path, 'profiles', 'use.desc'))
        for x in use_desc:
            x = x.split()
            if x:
                uselist.add(x[0])

        expand_desc_dir = os.path.join(path, 'profiles', 'desc')
        try:
            expand_list = os.listdir(expand_desc_dir)
        except OSError:
            pass
        else:
            for fn in expand_list:
                if not fn[-5:] == '.desc':
                    continue
                use_prefix = fn[:-5].lower() + '_'
                for x in portage.grabfile(os.path.join(expand_desc_dir, fn)):
                    x = x.split()
                    if x:
                        uselist.add(use_prefix + x[0])

        global_pmasklines.append(
            portage.util.grabfile_package(os.path.join(path, 'profiles',
                                                       'package.mask'),
                                          recursive=1,
                                          verify_eapi=True))

        desc_path = os.path.join(path, 'profiles', 'profiles.desc')
        try:
            desc_file = io.open(_unicode_encode(desc_path,
                                                encoding=_encodings['fs'],
                                                errors='strict'),
                                mode='r',
                                encoding=_encodings['repo.content'],
                                errors='replace')
        except EnvironmentError:
            pass
        else:
            for i, x in enumerate(desc_file):
                if x[0] == "#":
                    continue
                arch = x.split()
                if len(arch) == 0:
                    continue
                if len(arch) != 3:
                    err("wrong format: \"%s\" in %s line %d" % (
                        bad(x.strip()),
                        desc_path,
                        i + 1,
                    ))
                elif arch[0] not in kwlist:
                    err("invalid arch: \"%s\" in %s line %d" % (
                        bad(arch[0]),
                        desc_path,
                        i + 1,
                    ))
                elif arch[2] not in valid_profile_types:
                    err("invalid profile type: \"%s\" in %s line %d" % (
                        bad(arch[2]),
                        desc_path,
                        i + 1,
                    ))
                profile_desc = ProfileDesc(arch[0], arch[2], arch[1], path)
                if not os.path.isdir(profile_desc.abs_path):
                    logging.error(
                        "Invalid %s profile (%s) for arch %s in %s line %d",
                        arch[2], arch[1], arch[0], desc_path, i + 1)
                    continue
                if os.path.exists(
                        os.path.join(profile_desc.abs_path, 'deprecated')):
                    continue
                profile_list.append(profile_desc)
            desc_file.close()

    global_pmasklines = portage.util.stack_lists(global_pmasklines,
                                                 incremental=1)
    global_pmaskdict = {}
    for x in global_pmasklines:
        global_pmaskdict.setdefault(x.cp, []).append(x)
    del global_pmasklines

    return (kwlist, liclist, uselist, profile_list, global_pmaskdict,
            list_checks(kwlist, liclist, uselist, repoman_settings))
コード例 #2
0
ファイル: repos.py プロジェクト: zorry/zobsc
def repo_metadata(portdb, repoman_settings):
	# get lists of valid keywords, licenses, and use
	kwlist = set()
	liclist = set()
	uselist = set()
	profile_list = []
	global_pmasklines = []

	for path in portdb.porttrees:
		try:
			liclist.update(os.listdir(os.path.join(path, "licenses")))
		except OSError:
			pass
		kwlist.update(
			portage.grabfile(os.path.join(path, "profiles", "arch.list")))

		use_desc = portage.grabfile(os.path.join(path, 'profiles', 'use.desc'))
		for x in use_desc:
			x = x.split()
			if x:
				uselist.add(x[0])

		expand_desc_dir = os.path.join(path, 'profiles', 'desc')
		try:
			expand_list = os.listdir(expand_desc_dir)
		except OSError:
			pass
		else:
			for fn in expand_list:
				if not fn[-5:] == '.desc':
					continue
				use_prefix = fn[:-5].lower() + '_'
				for x in portage.grabfile(os.path.join(expand_desc_dir, fn)):
					x = x.split()
					if x:
						uselist.add(use_prefix + x[0])

		global_pmasklines.append(
			portage.util.grabfile_package(
				os.path.join(path, 'profiles', 'package.mask'),
				recursive=1, verify_eapi=True))

		desc_path = os.path.join(path, 'profiles', 'profiles.desc')
		try:
			desc_file = io.open(
				_unicode_encode(
					desc_path, encoding=_encodings['fs'], errors='strict'),
				mode='r', encoding=_encodings['repo.content'], errors='replace')
		except EnvironmentError:
			pass
		else:
			for i, x in enumerate(desc_file):
				if x[0] == "#":
					continue
				arch = x.split()
				if len(arch) == 0:
					continue
				if len(arch) != 3:
					err(
						"wrong format: \"%s\" in %s line %d" %
						(bad(x.strip()), desc_path, i + 1, ))
				elif arch[0] not in kwlist:
					err(
						"invalid arch: \"%s\" in %s line %d" %
						(bad(arch[0]), desc_path, i + 1, ))
				elif arch[2] not in valid_profile_types:
					err(
						"invalid profile type: \"%s\" in %s line %d" %
						(bad(arch[2]), desc_path, i + 1, ))
				profile_desc = ProfileDesc(arch[0], arch[2], arch[1], path)
				if not os.path.isdir(profile_desc.abs_path):
					logging.error(
						"Invalid %s profile (%s) for arch %s in %s line %d",
						arch[2], arch[1], arch[0], desc_path, i + 1)
					continue
				if os.path.exists(
					os.path.join(profile_desc.abs_path, 'deprecated')):
					continue
				profile_list.append(profile_desc)
			desc_file.close()

	global_pmasklines = portage.util.stack_lists(global_pmasklines, incremental=1)
	global_pmaskdict = {}
	for x in global_pmasklines:
		global_pmaskdict.setdefault(x.cp, []).append(x)
	del global_pmasklines

	return (
		kwlist, liclist, uselist, profile_list, global_pmaskdict,
		list_checks(kwlist, liclist, uselist, repoman_settings))