2011-01-26 17:26:51 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2010-11-11 23:34:39 +01:00
|
|
|
#
|
2011-02-17 21:16:26 +01:00
|
|
|
# common.py - part of the FDroid server tools
|
2010-11-11 23:34:39 +01:00
|
|
|
# Copyright (C) 2010, Ciaran Gultnieks, ciaran@ciarang.com
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
2011-02-17 21:16:26 +01:00
|
|
|
import glob, os, sys
|
|
|
|
|
2011-01-26 17:02:30 +01:00
|
|
|
def read_metadata(verbose=False):
|
2010-11-11 23:34:39 +01:00
|
|
|
|
|
|
|
apps = []
|
|
|
|
|
|
|
|
for metafile in glob.glob(os.path.join('metadata','*.txt')):
|
|
|
|
|
|
|
|
thisinfo = {}
|
|
|
|
|
|
|
|
# Get metadata...
|
|
|
|
thisinfo['id'] = metafile[9:-4]
|
2011-01-26 17:02:30 +01:00
|
|
|
if verbose:
|
|
|
|
print "Reading metadata for " + thisinfo['id']
|
2010-11-11 23:34:39 +01:00
|
|
|
thisinfo['description'] = ''
|
2010-12-29 17:43:04 +01:00
|
|
|
thisinfo['name'] = None
|
2010-11-11 23:34:39 +01:00
|
|
|
thisinfo['summary'] = ''
|
|
|
|
thisinfo['license'] = 'Unknown'
|
|
|
|
thisinfo['web'] = ''
|
|
|
|
thisinfo['source'] = ''
|
|
|
|
thisinfo['tracker'] = ''
|
2011-01-22 14:45:18 +01:00
|
|
|
thisinfo['donate'] = None
|
2010-11-11 23:34:39 +01:00
|
|
|
thisinfo['disabled'] = None
|
2010-12-15 22:28:50 +01:00
|
|
|
thisinfo['antifeatures'] = None
|
2010-11-11 23:34:39 +01:00
|
|
|
thisinfo['marketversion'] = ''
|
|
|
|
thisinfo['marketvercode'] = '0'
|
|
|
|
thisinfo['repotype'] = ''
|
|
|
|
thisinfo['repo'] = ''
|
|
|
|
thisinfo['builds'] = []
|
2011-01-05 23:20:57 +01:00
|
|
|
thisinfo['usebuilt'] = False
|
2010-11-11 23:34:39 +01:00
|
|
|
f = open(metafile, 'r')
|
|
|
|
mode = 0
|
|
|
|
for line in f.readlines():
|
2010-11-12 19:22:06 +01:00
|
|
|
if not line.startswith("#"):
|
|
|
|
line = line.rstrip('\r\n')
|
|
|
|
if len(line) == 0:
|
|
|
|
pass
|
|
|
|
elif mode == 0:
|
|
|
|
index = line.find(':')
|
|
|
|
if index == -1:
|
|
|
|
print "Invalid metadata in " + metafile + " at:" + line
|
2010-11-11 23:34:39 +01:00
|
|
|
sys.exit(1)
|
2010-11-12 19:22:06 +01:00
|
|
|
field = line[:index]
|
|
|
|
value = line[index+1:]
|
|
|
|
if field == 'Description':
|
|
|
|
mode = 1
|
2010-12-29 17:43:04 +01:00
|
|
|
elif field == 'Name':
|
|
|
|
thisinfo['name'] = value
|
2010-11-12 19:22:06 +01:00
|
|
|
elif field == 'Summary':
|
|
|
|
thisinfo['summary'] = value
|
|
|
|
elif field == 'Source Code':
|
|
|
|
thisinfo['source'] = value
|
|
|
|
elif field == 'License':
|
|
|
|
thisinfo['license'] = value
|
|
|
|
elif field == 'Web Site':
|
|
|
|
thisinfo['web'] = value
|
|
|
|
elif field == 'Issue Tracker':
|
|
|
|
thisinfo['tracker'] = value
|
2011-01-19 01:12:36 +01:00
|
|
|
elif field == 'Donate':
|
|
|
|
thisinfo['donate'] = value
|
2010-11-12 19:22:06 +01:00
|
|
|
elif field == 'Disabled':
|
|
|
|
thisinfo['disabled'] = value
|
2010-12-15 22:28:50 +01:00
|
|
|
elif field == 'AntiFeatures':
|
|
|
|
parts = value.split(",")
|
|
|
|
for part in parts:
|
|
|
|
if (part != "Ads" and
|
|
|
|
part != "Tracking" and
|
|
|
|
part != "NonFreeNet" and
|
|
|
|
part != "NonFreeAdd"):
|
2011-01-26 17:02:30 +01:00
|
|
|
print "Unrecognised antifeature '" + part + "' in "+ metafile
|
2010-12-15 22:28:50 +01:00
|
|
|
sys.exit(1)
|
|
|
|
thisinfo['antifeatures'] = value
|
2010-11-12 19:22:06 +01:00
|
|
|
elif field == 'Market Version':
|
|
|
|
thisinfo['marketversion'] = value
|
|
|
|
elif field == 'Market Version Code':
|
|
|
|
thisinfo['marketvercode'] = value
|
|
|
|
elif field == 'Repo Type':
|
|
|
|
thisinfo['repotype'] = value
|
|
|
|
elif field == 'Repo':
|
|
|
|
thisinfo['repo'] = value
|
|
|
|
elif field == 'Build Version':
|
|
|
|
parts = value.split(",")
|
|
|
|
if len(parts) < 3:
|
2011-01-26 17:02:30 +01:00
|
|
|
print "Invalid build format: " + value + " in " + metafile
|
2010-11-12 19:22:06 +01:00
|
|
|
sys.exit(1)
|
|
|
|
thisbuild = {}
|
|
|
|
thisbuild['version'] = parts[0]
|
|
|
|
thisbuild['vercode'] = parts[1]
|
|
|
|
thisbuild['commit'] = parts[2]
|
|
|
|
for p in parts[3:]:
|
|
|
|
pp = p.split('=')
|
|
|
|
thisbuild[pp[0]] = pp[1]
|
|
|
|
thisinfo['builds'].append(thisbuild)
|
2011-01-05 23:20:57 +01:00
|
|
|
elif field == "Use Built":
|
|
|
|
if value == "Yes":
|
|
|
|
thisinfo['usebuilt'] = True
|
2010-11-11 23:34:39 +01:00
|
|
|
else:
|
2011-01-26 17:02:30 +01:00
|
|
|
print "Unrecognised field " + field + " in " + metafile
|
2010-11-12 19:22:06 +01:00
|
|
|
sys.exit(1)
|
|
|
|
elif mode == 1:
|
|
|
|
if line == '.':
|
|
|
|
mode = 0
|
|
|
|
else:
|
|
|
|
if len(line) == 0:
|
|
|
|
thisinfo['description'] += '\n\n'
|
|
|
|
else:
|
|
|
|
if (not thisinfo['description'].endswith('\n') and
|
|
|
|
len(thisinfo['description']) > 0):
|
|
|
|
thisinfo['description'] += ' '
|
|
|
|
thisinfo['description'] += line
|
|
|
|
|
|
|
|
if mode == 1:
|
2011-01-26 17:02:30 +01:00
|
|
|
print "Description not terminated in " + metafile
|
2010-11-12 19:22:06 +01:00
|
|
|
sys.exit(1)
|
2010-11-11 23:34:39 +01:00
|
|
|
if len(thisinfo['description']) == 0:
|
|
|
|
thisinfo['description'] = 'No description available'
|
|
|
|
|
|
|
|
apps.append(thisinfo)
|
|
|
|
|
|
|
|
return apps
|