fdroidserver.metadata module

class fdroidserver.metadata.App(copydict=None)

Bases: dict

Methods

clear()

copy()

fromkeys(iterable[, value])

Create a new dictionary with keys from iterable and values set to value.

get(key[, default])

Return the value for key if key is in the dictionary, else default.

items()

keys()

pop(key[, default])

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem(/)

Remove and return a (key, value) pair as a 2-tuple.

setdefault(key[, default])

Insert key with a value of default if key is not in the dictionary.

update([E, ]**F)

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

class fdroidserver.metadata.Build(copydict=None)

Bases: dict

Methods

clear()

copy()

fromkeys(iterable[, value])

Create a new dictionary with keys from iterable and values set to value.

get(key[, default])

Return the value for key if key is in the dictionary, else default.

items()

keys()

ndk_path()

Return the path string of the first configured NDK or an empty string.

output_method()

pop(key[, default])

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem(/)

Remove and return a (key, value) pair as a 2-tuple.

setdefault(key[, default])

Insert key with a value of default if key is not in the dictionary.

update([E, ]**F)

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

build_method

to_yaml

build_method()
ndk_path() str

Return the path string of the first configured NDK or an empty string.

output_method()
classmethod to_yaml(representer, node)
class fdroidserver.metadata.FieldValidator(name, matching, fields)

Bases: object

Designate App metadata field types and checks that it matches.

‘name’ - The long name of the field type ‘matching’ - List of possible values or regex expression ‘sep’ - Separator to use if value may be a list ‘fields’ - Metadata fields (Field:Value) of this type

Methods

check

check(v, appid)
fdroidserver.metadata.add_metadata_arguments(parser)

Add common command line flags related to metadata processing.

fdroidserver.metadata.check_metadata(app)
fdroidserver.metadata.fieldtype(name)
fdroidserver.metadata.flagtype(name)
fdroidserver.metadata.parse_localized_antifeatures(app)

Read in localized Anti-Features files from the filesystem.

To support easy integration with Weblate and other translation systems, there is a special type of metadata that can be maintained in a Fastlane-style directory layout, where each field is represented by a text file on directories that specified which app it belongs to, which locale, etc. This function reads those in and puts them into the internal dict, to be merged with any related data that came from the metadata.yml file.

This needs to be run after parse_yaml_metadata() since that normalizes the data structure. Also, these values are lower priority than what comes from the metadata file. So this should not overwrite anything parse_yaml_metadata() puts into the App instance.

metadata/<Application ID>/<locale>/antifeatures/<Version Code>_<Anti-Feature>.txt metadata/<Application ID>/<locale>/antifeatures/<Anti-Feature>.txt

└── metadata/
└── <Application ID>/

├── en-US/ │ └── antifeatures/ │ ├── 123_Ads.txt -> “includes ad lib” │ ├── 123_Tracking.txt -> “standard suspects” │ └── NoSourceSince.txt -> “it vanished” │ └── zh-CN/

└── antifeatures/

└── 123_Ads.txt -> “包括广告库”

Gets parsed into the metadata data structure:

AntiFeatures:
NoSourceSince:

en-US: it vanished

Builds:
  • versionCode: 123 antifeatures:

    Ads:

    en-US: includes ad lib zh-CN: 包括广告库

    Tracking:

    en-US: standard suspects

fdroidserver.metadata.parse_metadata(metadatapath)

Parse metadata file, also checking the source repo for .fdroid.yml.

This function finds the relevant files, gets them parsed, converts dicts into App and Build instances, and combines the results into a single App instance.

If this is a metadata file from 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.

.fdroid.yml is embedded in the app’s source repo, so it is “user-generated”. That means that it can have weird things in it that need to be removed so they don’t break the overall process, e.g. if the upstream developer includes some broken field, it can be overridden in the metadata file.

Parameters:
metadatapath

The file path to read. The “Application ID” aka “Package Name” for the application comes from this filename.

Returns:
Returns a dictionary containing all the details of the
application. There are two major kinds of information in the
dictionary. Keys beginning with capital letters correspond
directory to identically named keys in the metadata file. Keys
beginning with lower case letters are generated in one way or
another, and are not found verbatim in the metadata.
Raises:
FDroidException when there are syntax errors.
fdroidserver.metadata.parse_yaml_metadata(mf)

Parse the .yml file and post-process it.

This function handles parsing a metadata YAML file and converting all the various data types into a consistent internal representation. The results are meant to update an existing App instance or used as a plain dict.

Clean metadata .yml files can be used directly, but in order to make a better user experience for people editing .yml files, there is post processing. That makes the parsing perform something like Strict YAML.

fdroidserver.metadata.parse_yaml_srclib(metadatapath)
fdroidserver.metadata.post_parse_yaml_metadata(yamldata)

Convert human-readable metadata data structures into consistent data structures.

“Be conservative in what is written out, be liberal in what is parsed.” https://en.wikipedia.org/wiki/Robustness_principle

This also handles conversions that make metadata YAML behave something like StrictYAML. Specifically, a field should have a fixed value type, regardless of YAML 1.2’s type auto-detection.

TODO: None values should probably be treated as the string ‘null’, since YAML 1.2 uses that for nulls

fdroidserver.metadata.read_metadata(appids={}, sort_by_time=False)

Return a list of App instances sorted newest first.

This reads all of the metadata files in a ‘data’ repository, then builds a list of App instances from those files. The list is sorted based on creation time, newest first. Most of the time, the newer files are the most interesting.

appids is a dict with appids a keys and versionCodes as values.

fdroidserver.metadata.read_srclibs()

Read all srclib metadata.

The information read will be accessible as metadata.srclibs, which is a dictionary, keyed on srclib name, with the values each being a dictionary in the same format as that returned by the parse_yaml_srclib function.

A MetaDataException is raised if there are any problems with the srclib metadata.

fdroidserver.metadata.write_metadata(metadatapath, app)
fdroidserver.metadata.write_yaml(mf, app)

Write metadata in yaml format.

Parameters:
mf

active file discriptor for writing

app

app metadata to written to the yaml file