allow metadata to be embedded in source repos via .fdroid.yml

This allows a source repo to include a complete metadata file so that it
can be built directly in place using `fdroid build`.  If that app is then
included in fdroiddata, it will first load the source repo type and URL
from fdroiddata, then read .fdroid.yml if it exists, then include the rest
of the metadata as specified in fdroiddata, so that fdroiddata has
precedence over the metadata in the source code.

This lets `fdroid build` apps without having a whole fdroiddata setup, but
instead just directly in place in the source code.  This also lets devs
optionallu maintain the fdroid metadata as part of their app, rather than
in fdroiddata without loosing any control.  This should make it easier to
spread around the maintenance load.
This commit is contained in:
Hans-Christoph Steiner 2016-11-07 21:47:53 +01:00
parent b4a39ee272
commit a4e4310803
8 changed files with 121 additions and 16 deletions

View file

@ -224,6 +224,21 @@ class App():
else:
self.set_field(f, v)
def update(self, d):
'''Like dict.update()'''
for k, v in d.__dict__.items():
if k == '_modified':
continue
elif k == 'builds':
for b in v:
build = Build()
del(b.__dict__['_modified'])
build.update_flags(b.__dict__)
self.builds.append(build)
elif v:
self.__dict__[k] = v
self._modified.add(k)
TYPE_UNKNOWN = 0
TYPE_OBSOLETE = 1
@ -778,10 +793,12 @@ def read_srclibs():
srclibs[srclibname] = parse_srclib(metadatapath)
def read_metadata(xref=True):
def read_metadata(xref=True, check_vcs=[]):
"""
Read all metadata. Returns a list of 'app' objects (which are dictionaries as
returned by the parse_txt_metadata function.
check_vcs is the list of packageNames to check for .fdroid.yml in source
"""
# Always read the srclibs before the apps, since they can use a srlib as
@ -809,7 +826,7 @@ def read_metadata(xref=True):
packageName, _ = fdroidserver.common.get_extension(os.path.basename(metadatapath))
if packageName in apps:
warn_or_exception("Found multiple metadata files for " + packageName)
app = parse_metadata(metadatapath)
app = parse_metadata(metadatapath, packageName in check_vcs)
check_metadata(app)
apps[app.id] = app
@ -962,7 +979,9 @@ def _decode_bool(s):
warn_or_exception("Invalid bool '%s'" % s)
def parse_metadata(metadatapath):
def parse_metadata(metadatapath, check_vcs=False):
'''parse metadata file, optionally checking the git repo for metadata first'''
_, ext = fdroidserver.common.get_extension(metadatapath)
accepted = fdroidserver.common.config['accepted_formats']
if ext not in accepted:
@ -971,7 +990,11 @@ def parse_metadata(metadatapath):
app = App()
app.metadatapath = metadatapath
app.id, _ = fdroidserver.common.get_extension(os.path.basename(metadatapath))
name, _ = fdroidserver.common.get_extension(os.path.basename(metadatapath))
if name == '.fdroid':
check_vcs = False
else:
app.id = name
with open(metadatapath, 'r', encoding='utf-8') as mf:
if ext == 'txt':
@ -985,7 +1008,28 @@ def parse_metadata(metadatapath):
else:
warn_or_exception('Unknown metadata format: %s' % metadatapath)
if check_vcs and app.Repo:
build_dir = fdroidserver.common.get_build_dir(app)
metadata_in_repo = os.path.join(build_dir, '.fdroid.yml')
if not os.path.isfile(metadata_in_repo):
vcs, build_dir = fdroidserver.common.setup_vcs(app)
vcs.gotorevision('HEAD') # HEAD since we can't know where else to go
if os.path.isfile(metadata_in_repo):
logging.debug('Including metadata from ' + metadata_in_repo)
app.update(parse_metadata(metadata_in_repo))
post_metadata_parse(app)
if not app.id:
if app.builds:
build = app.builds[-1]
if build.subdir:
root_dir = build.subdir
else:
root_dir = '.'
paths = fdroidserver.common.manifest_paths(root_dir, build.gradle)
_, _, app.id = fdroidserver.common.parse_androidmanifests(paths, app)
return app