mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-09-14 23:12:46 +03:00
convert comments above functions to python docstrings
This is how to write per-function comments. https://www.python.org/dev/peps/pep-0257/
This commit is contained in:
parent
1f55a40caa
commit
f8dca60a20
2 changed files with 35 additions and 21 deletions
|
@ -358,9 +358,11 @@ def get_local_metadata_files():
|
||||||
return glob.glob('.fdroid.[a-jl-z]*[a-rt-z]')
|
return glob.glob('.fdroid.[a-jl-z]*[a-rt-z]')
|
||||||
|
|
||||||
|
|
||||||
# Given the arguments in the form of multiple appid:[vc] strings, this returns
|
|
||||||
# a dictionary with the set of vercodes specified for each package.
|
|
||||||
def read_pkg_args(args, allow_vercodes=False):
|
def read_pkg_args(args, allow_vercodes=False):
|
||||||
|
"""
|
||||||
|
Given the arguments in the form of multiple appid:[vc] strings, this returns
|
||||||
|
a dictionary with the set of vercodes specified for each package.
|
||||||
|
"""
|
||||||
|
|
||||||
vercodes = {}
|
vercodes = {}
|
||||||
if not args:
|
if not args:
|
||||||
|
@ -380,9 +382,11 @@ def read_pkg_args(args, allow_vercodes=False):
|
||||||
return vercodes
|
return vercodes
|
||||||
|
|
||||||
|
|
||||||
# On top of what read_pkg_args does, this returns the whole app metadata, but
|
|
||||||
# limiting the builds list to the builds matching the vercodes specified.
|
|
||||||
def read_app_args(args, allapps, allow_vercodes=False):
|
def read_app_args(args, allapps, allow_vercodes=False):
|
||||||
|
"""
|
||||||
|
On top of what read_pkg_args does, this returns the whole app metadata, but
|
||||||
|
limiting the builds list to the builds matching the vercodes specified.
|
||||||
|
"""
|
||||||
|
|
||||||
vercodes = read_pkg_args(args, allow_vercodes)
|
vercodes = read_pkg_args(args, allow_vercodes)
|
||||||
|
|
||||||
|
@ -979,8 +983,8 @@ def retrieve_string_singleline(app_dir, string, xmlfiles=None):
|
||||||
return retrieve_string(app_dir, string, xmlfiles).replace('\n', ' ').strip()
|
return retrieve_string(app_dir, string, xmlfiles).replace('\n', ' ').strip()
|
||||||
|
|
||||||
|
|
||||||
# Return list of existing files that will be used to find the highest vercode
|
|
||||||
def manifest_paths(app_dir, flavours):
|
def manifest_paths(app_dir, flavours):
|
||||||
|
'''Return list of existing files that will be used to find the highest vercode'''
|
||||||
|
|
||||||
possible_manifests = \
|
possible_manifests = \
|
||||||
[os.path.join(app_dir, 'AndroidManifest.xml'),
|
[os.path.join(app_dir, 'AndroidManifest.xml'),
|
||||||
|
@ -997,8 +1001,8 @@ def manifest_paths(app_dir, flavours):
|
||||||
return [path for path in possible_manifests if os.path.isfile(path)]
|
return [path for path in possible_manifests if os.path.isfile(path)]
|
||||||
|
|
||||||
|
|
||||||
# Retrieve the package name. Returns the name, or None if not found.
|
|
||||||
def fetch_real_name(app_dir, flavours):
|
def fetch_real_name(app_dir, flavours):
|
||||||
|
'''Retrieve the package name. Returns the name, or None if not found.'''
|
||||||
for path in manifest_paths(app_dir, flavours):
|
for path in manifest_paths(app_dir, flavours):
|
||||||
if not has_extension(path, 'xml') or not os.path.isfile(path):
|
if not has_extension(path, 'xml') or not os.path.isfile(path):
|
||||||
continue
|
continue
|
||||||
|
@ -1070,10 +1074,12 @@ def app_matches_packagename(app, package):
|
||||||
return appid == package
|
return appid == package
|
||||||
|
|
||||||
|
|
||||||
# Extract some information from the AndroidManifest.xml at the given path.
|
|
||||||
# Returns (version, vercode, package), any or all of which might be None.
|
|
||||||
# All values returned are strings.
|
|
||||||
def parse_androidmanifests(paths, app):
|
def parse_androidmanifests(paths, app):
|
||||||
|
"""
|
||||||
|
Extract some information from the AndroidManifest.xml at the given path.
|
||||||
|
Returns (version, vercode, package), any or all of which might be None.
|
||||||
|
All values returned are strings.
|
||||||
|
"""
|
||||||
|
|
||||||
ignoreversions = app.UpdateCheckIgnore
|
ignoreversions = app.UpdateCheckIgnore
|
||||||
ignoresearch = re.compile(ignoreversions).search if ignoreversions else None
|
ignoresearch = re.compile(ignoreversions).search if ignoreversions else None
|
||||||
|
|
|
@ -152,24 +152,30 @@ class App():
|
||||||
self.lastupdated = None
|
self.lastupdated = None
|
||||||
self._modified = set()
|
self._modified = set()
|
||||||
|
|
||||||
# Translates human-readable field names to attribute names, e.g.
|
|
||||||
# 'Auto Name' to 'AutoName'
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def field_to_attr(cls, f):
|
def field_to_attr(cls, f):
|
||||||
|
"""
|
||||||
|
Translates human-readable field names to attribute names, e.g.
|
||||||
|
'Auto Name' to 'AutoName'
|
||||||
|
"""
|
||||||
return f.replace(' ', '')
|
return f.replace(' ', '')
|
||||||
|
|
||||||
# Translates attribute names to human-readable field names, e.g.
|
|
||||||
# 'AutoName' to 'Auto Name'
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def attr_to_field(cls, k):
|
def attr_to_field(cls, k):
|
||||||
|
"""
|
||||||
|
Translates attribute names to human-readable field names, e.g.
|
||||||
|
'AutoName' to 'Auto Name'
|
||||||
|
"""
|
||||||
if k in app_fields:
|
if k in app_fields:
|
||||||
return k
|
return k
|
||||||
f = re.sub(r'([a-z])([A-Z])', r'\1 \2', k)
|
f = re.sub(r'([a-z])([A-Z])', r'\1 \2', k)
|
||||||
return f
|
return f
|
||||||
|
|
||||||
# Constructs an old-fashioned dict with the human-readable field
|
|
||||||
# names. Should only be used for tests.
|
|
||||||
def field_dict(self):
|
def field_dict(self):
|
||||||
|
"""
|
||||||
|
Constructs an old-fashioned dict with the human-readable field
|
||||||
|
names. Should only be used for tests.
|
||||||
|
"""
|
||||||
d = {}
|
d = {}
|
||||||
for k, v in self.__dict__.items():
|
for k, v in self.__dict__.items():
|
||||||
if k == 'builds':
|
if k == 'builds':
|
||||||
|
@ -182,23 +188,23 @@ class App():
|
||||||
d[f] = v
|
d[f] = v
|
||||||
return d
|
return d
|
||||||
|
|
||||||
# Gets the value associated to a field name, e.g. 'Auto Name'
|
|
||||||
def get_field(self, f):
|
def get_field(self, f):
|
||||||
|
"""Gets the value associated to a field name, e.g. 'Auto Name'"""
|
||||||
if f not in app_fields:
|
if f not in app_fields:
|
||||||
warn_or_exception('Unrecognised app field: ' + f)
|
warn_or_exception('Unrecognised app field: ' + f)
|
||||||
k = App.field_to_attr(f)
|
k = App.field_to_attr(f)
|
||||||
return getattr(self, k)
|
return getattr(self, k)
|
||||||
|
|
||||||
# Sets the value associated to a field name, e.g. 'Auto Name'
|
|
||||||
def set_field(self, f, v):
|
def set_field(self, f, v):
|
||||||
|
"""Sets the value associated to a field name, e.g. 'Auto Name'"""
|
||||||
if f not in app_fields:
|
if f not in app_fields:
|
||||||
warn_or_exception('Unrecognised app field: ' + f)
|
warn_or_exception('Unrecognised app field: ' + f)
|
||||||
k = App.field_to_attr(f)
|
k = App.field_to_attr(f)
|
||||||
self.__dict__[k] = v
|
self.__dict__[k] = v
|
||||||
self._modified.add(k)
|
self._modified.add(k)
|
||||||
|
|
||||||
# Appends to the value associated to a field name, e.g. 'Auto Name'
|
|
||||||
def append_field(self, f, v):
|
def append_field(self, f, v):
|
||||||
|
"""Appends to the value associated to a field name, e.g. 'Auto Name'"""
|
||||||
if f not in app_fields:
|
if f not in app_fields:
|
||||||
warn_or_exception('Unrecognised app field: ' + f)
|
warn_or_exception('Unrecognised app field: ' + f)
|
||||||
k = App.field_to_attr(f)
|
k = App.field_to_attr(f)
|
||||||
|
@ -207,8 +213,8 @@ class App():
|
||||||
else:
|
else:
|
||||||
self.__dict__[k].append(v)
|
self.__dict__[k].append(v)
|
||||||
|
|
||||||
# Like dict.update(), but using human-readable field names
|
|
||||||
def update_fields(self, d):
|
def update_fields(self, d):
|
||||||
|
'''Like dict.update(), but using human-readable field names'''
|
||||||
for f, v in d.items():
|
for f, v in d.items():
|
||||||
if f == 'builds':
|
if f == 'builds':
|
||||||
for b in v:
|
for b in v:
|
||||||
|
@ -772,9 +778,11 @@ def read_srclibs():
|
||||||
srclibs[srclibname] = parse_srclib(metadatapath)
|
srclibs[srclibname] = parse_srclib(metadatapath)
|
||||||
|
|
||||||
|
|
||||||
# Read all metadata. Returns a list of 'app' objects (which are dictionaries as
|
|
||||||
# returned by the parse_txt_metadata function.
|
|
||||||
def read_metadata(xref=True):
|
def read_metadata(xref=True):
|
||||||
|
"""
|
||||||
|
Read all metadata. Returns a list of 'app' objects (which are dictionaries as
|
||||||
|
returned by the parse_txt_metadata function.
|
||||||
|
"""
|
||||||
|
|
||||||
# Always read the srclibs before the apps, since they can use a srlib as
|
# Always read the srclibs before the apps, since they can use a srlib as
|
||||||
# their source repository.
|
# their source repository.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue