mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-09 00:40:29 +03:00
some easier fixes for black code format
This commit is contained in:
parent
5968cfe7e0
commit
c6ad8505d4
1 changed files with 41 additions and 24 deletions
|
|
@ -109,7 +109,6 @@ yaml_app_fields = [x for x in yaml_app_field_order if x != '\n']
|
||||||
|
|
||||||
|
|
||||||
class App(dict):
|
class App(dict):
|
||||||
|
|
||||||
def __init__(self, copydict=None):
|
def __init__(self, copydict=None):
|
||||||
if copydict:
|
if copydict:
|
||||||
super().__init__(copydict)
|
super().__init__(copydict)
|
||||||
|
|
@ -252,7 +251,6 @@ build_flags = [
|
||||||
|
|
||||||
|
|
||||||
class Build(dict):
|
class Build(dict):
|
||||||
|
|
||||||
def __init__(self, copydict=None):
|
def __init__(self, copydict=None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.disable = ''
|
self.disable = ''
|
||||||
|
|
@ -375,7 +373,7 @@ def flagtype(name):
|
||||||
return TYPE_STRING
|
return TYPE_STRING
|
||||||
|
|
||||||
|
|
||||||
class FieldValidator():
|
class FieldValidator:
|
||||||
"""Designate App metadata field types and checks that it matches.
|
"""Designate App metadata field types and checks that it matches.
|
||||||
|
|
||||||
'name' - The long name of the field type
|
'name' - The long name of the field type
|
||||||
|
|
@ -495,8 +493,9 @@ def parse_yaml_srclib(metadatapath):
|
||||||
with symlink.open("r", encoding="utf-8") as s:
|
with symlink.open("r", encoding="utf-8") as s:
|
||||||
data = yaml.load(s)
|
data = yaml.load(s)
|
||||||
if type(data) is not dict:
|
if type(data) is not dict:
|
||||||
raise YAMLError(_('{file} is blank or corrupt!')
|
raise YAMLError(
|
||||||
.format(file=metadatapath))
|
_('{file} is blank or corrupt!').format(file=metadatapath)
|
||||||
|
)
|
||||||
except YAMLError as e:
|
except YAMLError as e:
|
||||||
_warn_or_exception(_("Invalid srclib metadata: could not "
|
_warn_or_exception(_("Invalid srclib metadata: could not "
|
||||||
"parse '{file}'")
|
"parse '{file}'")
|
||||||
|
|
@ -507,9 +506,11 @@ def parse_yaml_srclib(metadatapath):
|
||||||
|
|
||||||
for key in data:
|
for key in data:
|
||||||
if key not in thisinfo:
|
if key not in thisinfo:
|
||||||
_warn_or_exception(_("Invalid srclib metadata: unknown key "
|
_warn_or_exception(
|
||||||
"'{key}' in '{file}'")
|
_("Invalid srclib metadata: unknown key '{key}' in '{file}'").format(
|
||||||
.format(key=key, file=metadatapath))
|
key=key, file=metadatapath
|
||||||
|
)
|
||||||
|
)
|
||||||
return thisinfo
|
return thisinfo
|
||||||
else:
|
else:
|
||||||
if key == 'Subdir':
|
if key == 'Subdir':
|
||||||
|
|
@ -580,7 +581,8 @@ def read_metadata(appids={}, sort_by_time=False):
|
||||||
metadatafiles = common.get_metadata_files(vercodes)
|
metadatafiles = common.get_metadata_files(vercodes)
|
||||||
else:
|
else:
|
||||||
metadatafiles = list(Path('metadata').glob('*.yml')) + list(
|
metadatafiles = list(Path('metadata').glob('*.yml')) + list(
|
||||||
Path('.').glob('.fdroid.yml'))
|
Path('.').glob('.fdroid.yml')
|
||||||
|
)
|
||||||
|
|
||||||
if sort_by_time:
|
if sort_by_time:
|
||||||
entries = ((path.stat().st_mtime, path) for path in metadatafiles)
|
entries = ((path.stat().st_mtime, path) for path in metadatafiles)
|
||||||
|
|
@ -594,11 +596,15 @@ def read_metadata(appids={}, sort_by_time=False):
|
||||||
for metadatapath in metadatafiles:
|
for metadatapath in metadatafiles:
|
||||||
appid = metadatapath.stem
|
appid = metadatapath.stem
|
||||||
if appid != '.fdroid' and not common.is_valid_package_name(appid):
|
if appid != '.fdroid' and not common.is_valid_package_name(appid):
|
||||||
_warn_or_exception(_("{appid} from {path} is not a valid Java Package Name!")
|
_warn_or_exception(
|
||||||
.format(appid=appid, path=metadatapath))
|
_("{appid} from {path} is not a valid Java Package Name!").format(
|
||||||
|
appid=appid, path=metadatapath
|
||||||
|
)
|
||||||
|
)
|
||||||
if appid in apps:
|
if appid in apps:
|
||||||
_warn_or_exception(_("Found multiple metadata files for {appid}")
|
_warn_or_exception(
|
||||||
.format(appid=appid))
|
_("Found multiple metadata files for {appid}").format(appid=appid)
|
||||||
|
)
|
||||||
app = parse_metadata(metadatapath)
|
app = parse_metadata(metadatapath)
|
||||||
check_metadata(app)
|
check_metadata(app)
|
||||||
apps[app.id] = app
|
apps[app.id] = app
|
||||||
|
|
@ -654,8 +660,9 @@ def parse_metadata(metadatapath):
|
||||||
with metadatapath.open('r', encoding='utf-8') as mf:
|
with metadatapath.open('r', encoding='utf-8') as mf:
|
||||||
app.update(parse_yaml_metadata(mf))
|
app.update(parse_yaml_metadata(mf))
|
||||||
else:
|
else:
|
||||||
_warn_or_exception(_('Unknown metadata format: {path} (use: *.yml)')
|
_warn_or_exception(
|
||||||
.format(path=metadatapath))
|
_('Unknown metadata format: {path} (use: *.yml)').format(path=metadatapath)
|
||||||
|
)
|
||||||
|
|
||||||
if metadatapath.name != '.fdroid.yml' and app.Repo:
|
if metadatapath.name != '.fdroid.yml' and app.Repo:
|
||||||
build_dir = common.get_build_dir(app)
|
build_dir = common.get_build_dir(app)
|
||||||
|
|
@ -663,11 +670,15 @@ def parse_metadata(metadatapath):
|
||||||
if metadata_in_repo.is_file():
|
if metadata_in_repo.is_file():
|
||||||
try:
|
try:
|
||||||
commit_id = common.get_head_commit_id(git.Repo(build_dir))
|
commit_id = common.get_head_commit_id(git.Repo(build_dir))
|
||||||
logging.debug(_('Including metadata from %s@%s') % (metadata_in_repo, commit_id))
|
logging.debug(
|
||||||
|
_('Including metadata from %s@%s') % (metadata_in_repo, commit_id)
|
||||||
|
)
|
||||||
# See https://github.com/PyCQA/pylint/issues/2856 .
|
# See https://github.com/PyCQA/pylint/issues/2856 .
|
||||||
# pylint: disable-next=no-member
|
# pylint: disable-next=no-member
|
||||||
except git.exc.InvalidGitRepositoryError:
|
except git.exc.InvalidGitRepositoryError:
|
||||||
logging.debug(_('Including metadata from {path}').format(metadata_in_repo))
|
logging.debug(
|
||||||
|
_('Including metadata from {path}').format(metadata_in_repo)
|
||||||
|
)
|
||||||
app_in_repo = parse_metadata(metadata_in_repo)
|
app_in_repo = parse_metadata(metadata_in_repo)
|
||||||
for k, v in app_in_repo.items():
|
for k, v in app_in_repo.items():
|
||||||
if k not in app:
|
if k not in app:
|
||||||
|
|
@ -711,10 +722,12 @@ def parse_yaml_metadata(mf):
|
||||||
yaml = YAML(typ='safe')
|
yaml = YAML(typ='safe')
|
||||||
yamldata = yaml.load(mf)
|
yamldata = yaml.load(mf)
|
||||||
except YAMLError as e:
|
except YAMLError as e:
|
||||||
_warn_or_exception(_("could not parse '{path}'")
|
_warn_or_exception(
|
||||||
.format(path=mf.name) + '\n'
|
_("could not parse '{path}'").format(path=mf.name)
|
||||||
+ common.run_yamllint(mf.name, indent=4),
|
+ '\n'
|
||||||
cause=e)
|
+ common.run_yamllint(mf.name, indent=4),
|
||||||
|
cause=e,
|
||||||
|
)
|
||||||
|
|
||||||
if yamldata is None or yamldata == '':
|
if yamldata is None or yamldata == '':
|
||||||
yamldata = dict()
|
yamldata = dict()
|
||||||
|
|
@ -790,7 +803,7 @@ def post_parse_yaml_metadata(yamldata):
|
||||||
for k, v in yamldata.items():
|
for k, v in yamldata.items():
|
||||||
if fieldtype(k) == TYPE_LIST:
|
if fieldtype(k) == TYPE_LIST:
|
||||||
if isinstance(v, str):
|
if isinstance(v, str):
|
||||||
yamldata[k] = [v, ]
|
yamldata[k] = [v]
|
||||||
elif v:
|
elif v:
|
||||||
yamldata[k] = [str(i) for i in v]
|
yamldata[k] = [str(i) for i in v]
|
||||||
elif fieldtype(k) == TYPE_INT:
|
elif fieldtype(k) == TYPE_INT:
|
||||||
|
|
@ -930,7 +943,9 @@ def write_yaml(mf, app):
|
||||||
if hasattr(build, field):
|
if hasattr(build, field):
|
||||||
value = getattr(build, field)
|
value = getattr(build, field)
|
||||||
if field == 'gradle' and value == ['off']:
|
if field == 'gradle' and value == ['off']:
|
||||||
value = [ruamel.yaml.scalarstring.SingleQuotedScalarString('off')]
|
value = [
|
||||||
|
ruamel.yaml.scalarstring.SingleQuotedScalarString('off')
|
||||||
|
]
|
||||||
typ = flagtype(field)
|
typ = flagtype(field)
|
||||||
# don't check value == True for TYPE_INT as it could be 0
|
# don't check value == True for TYPE_INT as it could be 0
|
||||||
if value is not None and (typ == TYPE_INT or value):
|
if value is not None and (typ == TYPE_INT or value):
|
||||||
|
|
@ -960,7 +975,9 @@ def write_metadata(metadatapath, app):
|
||||||
with metadatapath.open('w') as mf:
|
with metadatapath.open('w') as mf:
|
||||||
return write_yaml(mf, app)
|
return write_yaml(mf, app)
|
||||||
else:
|
else:
|
||||||
raise FDroidException(_('ruamel.yaml not installed, can not write metadata.'))
|
raise FDroidException(
|
||||||
|
_('ruamel.yaml not installed, can not write metadata.')
|
||||||
|
)
|
||||||
|
|
||||||
_warn_or_exception(_('Unknown metadata format: %s') % metadatapath)
|
_warn_or_exception(_('Unknown metadata format: %s') % metadatapath)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue