mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-09-14 15:02:51 +03:00
Metadata parsing changes
A few small changes to the format of metadata files: "Build Version" lines can now contain include commas by escaping them with a backslash. They can also be split over multiple lines by ending each line (except the last) with a backslash. Additionally, empty lines in descriptions should now work correctly.
This commit is contained in:
parent
09c5c50993
commit
bce5da2543
2 changed files with 140 additions and 119 deletions
11
README
11
README
|
@ -169,9 +169,14 @@ configuration to the build. These are:
|
||||||
the SDK's ant rules, and forces the Java compiler to interpret
|
the SDK's ant rules, and forces the Java compiler to interpret
|
||||||
source files with this encoding. If you receive warnings during
|
source files with this encoding. If you receive warnings during
|
||||||
the compile about character encodings, you probably need this.
|
the compile about character encodings, you probably need this.
|
||||||
prebuild=xxxx Specifies a shell command (or commands - chain with &&) to run
|
|
||||||
before the build takes place - the only proviso being that you
|
prebuild=xxxx Specifies a shell command (or commands - chain with &&) to
|
||||||
can't use commas in the command.
|
run before the build takes place. Backslash can be used
|
||||||
|
as an escape character to insert literal commas, or as the
|
||||||
|
last character on a line to join that line with the next.
|
||||||
|
They have no special meaning in other contexts; in
|
||||||
|
particular, literal backslashes should not be escaped.
|
||||||
|
|
||||||
novcheck=yes Don't check that the version name and code in the resulting apk
|
novcheck=yes Don't check that the version name and code in the resulting apk
|
||||||
are correct by looking at the build output - assume the metadata
|
are correct by looking at the build output - assume the metadata
|
||||||
is correct. This takes away a useful level of sanity checking, and
|
is correct. This takes away a useful level of sanity checking, and
|
||||||
|
|
84
common.py
84
common.py
|
@ -16,19 +16,30 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import glob, os, sys
|
import glob, os, sys, re
|
||||||
|
|
||||||
def read_metadata(verbose=False):
|
def parse_metadata(metafile, **kw):
|
||||||
|
|
||||||
apps = []
|
def parse_buildline(value):
|
||||||
|
parts = [p.replace("\\,", ",")
|
||||||
for metafile in glob.glob(os.path.join('metadata','*.txt')):
|
for p in re.split(r"(?<!\\),", value)]
|
||||||
|
if len(parts) < 3:
|
||||||
|
print "Invalid build format: " + value + " in " + metafile.name
|
||||||
|
sys.exit(1)
|
||||||
|
thisbuild = {}
|
||||||
|
thisbuild['version'] = parts[0]
|
||||||
|
thisbuild['vercode'] = parts[1]
|
||||||
|
thisbuild['commit'] = parts[2]
|
||||||
|
for p in parts[3:]:
|
||||||
|
pk, pv = p.split('=', 1)
|
||||||
|
thisbuild[pk] = pv
|
||||||
|
return thisbuild
|
||||||
|
|
||||||
|
if not isinstance(metafile, file):
|
||||||
|
metafile = open(metafile, "r")
|
||||||
thisinfo = {}
|
thisinfo = {}
|
||||||
|
thisinfo['id'] = metafile.name[9:-4]
|
||||||
# Get metadata...
|
if kw.get("verbose", False):
|
||||||
thisinfo['id'] = metafile[9:-4]
|
|
||||||
if verbose:
|
|
||||||
print "Reading metadata for " + thisinfo['id']
|
print "Reading metadata for " + thisinfo['id']
|
||||||
thisinfo['description'] = ''
|
thisinfo['description'] = ''
|
||||||
thisinfo['name'] = None
|
thisinfo['name'] = None
|
||||||
|
@ -46,17 +57,18 @@ def read_metadata(verbose=False):
|
||||||
thisinfo['repo'] = ''
|
thisinfo['repo'] = ''
|
||||||
thisinfo['builds'] = []
|
thisinfo['builds'] = []
|
||||||
thisinfo['usebuilt'] = False
|
thisinfo['usebuilt'] = False
|
||||||
f = open(metafile, 'r')
|
|
||||||
mode = 0
|
mode = 0
|
||||||
for line in f.readlines():
|
buildline = []
|
||||||
if not line.startswith("#"):
|
for line in metafile:
|
||||||
line = line.rstrip('\r\n')
|
line = line.rstrip('\r\n')
|
||||||
|
if line.startswith("#"):
|
||||||
|
continue
|
||||||
|
if mode == 0:
|
||||||
if len(line) == 0:
|
if len(line) == 0:
|
||||||
pass
|
continue
|
||||||
elif mode == 0:
|
|
||||||
index = line.find(':')
|
index = line.find(':')
|
||||||
if index == -1:
|
if index == -1:
|
||||||
print "Invalid metadata in " + metafile + " at:" + line
|
print "Invalid metadata in " + metafile.name + " at: " + line
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
field = line[:index]
|
field = line[:index]
|
||||||
value = line[index+1:]
|
value = line[index+1:]
|
||||||
|
@ -85,7 +97,8 @@ def read_metadata(verbose=False):
|
||||||
part != "Tracking" and
|
part != "Tracking" and
|
||||||
part != "NonFreeNet" and
|
part != "NonFreeNet" and
|
||||||
part != "NonFreeAdd"):
|
part != "NonFreeAdd"):
|
||||||
print "Unrecognised antifeature '" + part + "' in "+ metafile
|
print "Unrecognised antifeature '" + part + "' in " \
|
||||||
|
+ metafile.name
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
thisinfo['antifeatures'] = value
|
thisinfo['antifeatures'] = value
|
||||||
elif field == 'Market Version':
|
elif field == 'Market Version':
|
||||||
|
@ -97,25 +110,18 @@ def read_metadata(verbose=False):
|
||||||
elif field == 'Repo':
|
elif field == 'Repo':
|
||||||
thisinfo['repo'] = value
|
thisinfo['repo'] = value
|
||||||
elif field == 'Build Version':
|
elif field == 'Build Version':
|
||||||
parts = value.split(",")
|
if value.endswith("\\"):
|
||||||
if len(parts) < 3:
|
mode = 2
|
||||||
print "Invalid build format: " + value + " in " + metafile
|
buildline = [value[:-1]]
|
||||||
sys.exit(1)
|
else:
|
||||||
thisbuild = {}
|
thisinfo['builds'].append(parse_buildline(value))
|
||||||
thisbuild['version'] = parts[0]
|
|
||||||
thisbuild['vercode'] = parts[1]
|
|
||||||
thisbuild['commit'] = parts[2]
|
|
||||||
for p in parts[3:]:
|
|
||||||
pk, pv = p.split('=', 1)
|
|
||||||
thisbuild[pk] = pv
|
|
||||||
thisinfo['builds'].append(thisbuild)
|
|
||||||
elif field == "Use Built":
|
elif field == "Use Built":
|
||||||
if value == "Yes":
|
if value == "Yes":
|
||||||
thisinfo['usebuilt'] = True
|
thisinfo['usebuilt'] = True
|
||||||
else:
|
else:
|
||||||
print "Unrecognised field " + field + " in " + metafile
|
print "Unrecognised field " + field + " in " + metafile.name
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
elif mode == 1:
|
elif mode == 1: # multi-line description
|
||||||
if line == '.':
|
if line == '.':
|
||||||
mode = 0
|
mode = 0
|
||||||
else:
|
else:
|
||||||
|
@ -126,13 +132,23 @@ def read_metadata(verbose=False):
|
||||||
len(thisinfo['description']) > 0):
|
len(thisinfo['description']) > 0):
|
||||||
thisinfo['description'] += ' '
|
thisinfo['description'] += ' '
|
||||||
thisinfo['description'] += line
|
thisinfo['description'] += line
|
||||||
|
elif mode == 2: # line continuation
|
||||||
|
if line.endswith("\\"):
|
||||||
|
buildline.append(line[:-1])
|
||||||
|
else:
|
||||||
|
buildline.append(line)
|
||||||
|
thisinfo['builds'].append(
|
||||||
|
parse_buildline("".join(buildline)))
|
||||||
|
mode = 0
|
||||||
if mode == 1:
|
if mode == 1:
|
||||||
print "Description not terminated in " + metafile
|
print "Description not terminated in " + metafile.name
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if len(thisinfo['description']) == 0:
|
if len(thisinfo['description']) == 0:
|
||||||
thisinfo['description'] = 'No description available'
|
thisinfo['description'] = 'No description available'
|
||||||
|
return thisinfo
|
||||||
|
|
||||||
apps.append(thisinfo)
|
def read_metadata(verbose=False):
|
||||||
|
apps = []
|
||||||
|
for metafile in glob.glob(os.path.join('metadata', '*.txt')):
|
||||||
|
apps.append(parse_metadata(metafile, verbose=verbose))
|
||||||
return apps
|
return apps
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue