mirror of
				https://github.com/f-droid/fdroidserver.git
				synced 2025-11-04 14:30:30 +03:00 
			
		
		
		
	set "accepted formats" for metadata in config.py
For a bit repo like f-droid.org, it makes sense to standardize on a single format for metadata files. This adds support for enforcing a single data format, or a reduced set of data formats. So f-droid.org would run like this if it changed to YAML: accepted_formats = ['txt', 'yaml'] Then once everything was converted to YAML, it could look like this: accepted_formats = ['yaml']
This commit is contained in:
		
							parent
							
								
									19ac44c189
								
							
						
					
					
						commit
						325db90918
					
				
					 4 changed files with 37 additions and 19 deletions
				
			
		| 
						 | 
				
			
			@ -213,6 +213,11 @@ carbon_port = 2003
 | 
			
		|||
# --server option on dedicated secure build server hosts.
 | 
			
		||||
build_server_always = False
 | 
			
		||||
 | 
			
		||||
# By default, fdroid will use YAML and the custom .txt metadata formats.  It
 | 
			
		||||
# is also possible to have metadata in JSON and XML. You can enable your
 | 
			
		||||
# preferred formats by setting them in a list:
 | 
			
		||||
# accepted_formats = ['json', 'txt', 'xml', 'yaml']
 | 
			
		||||
 | 
			
		||||
# Limit in number of characters that fields can take up
 | 
			
		||||
# Only the fields listed here are supported, defaults shown
 | 
			
		||||
char_limits = {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -59,6 +59,7 @@ default_config = {
 | 
			
		|||
    'ant': "ant",
 | 
			
		||||
    'mvn3': "mvn",
 | 
			
		||||
    'gradle': 'gradle',
 | 
			
		||||
    'accepted_formats': ['txt', 'yaml'],
 | 
			
		||||
    'sync_from_local_copy_dir': False,
 | 
			
		||||
    'per_app_repos': False,
 | 
			
		||||
    'make_current_version_link': True,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -499,23 +499,11 @@ def read_metadata(xref=True):
 | 
			
		|||
    # exception. So the original .txt format is parsed first, at least until
 | 
			
		||||
    # newer formats stabilize.
 | 
			
		||||
 | 
			
		||||
    for metadatapath in sorted(glob.glob(os.path.join('metadata', '*.txt'))):
 | 
			
		||||
        appid, appinfo = parse_txt_metadata(apps, metadatapath)
 | 
			
		||||
        check_metadata(appinfo)
 | 
			
		||||
        apps[appid] = appinfo
 | 
			
		||||
 | 
			
		||||
    for metadatapath in sorted(glob.glob(os.path.join('metadata', '*.json'))):
 | 
			
		||||
        appid, appinfo = parse_json_metadata(apps, metadatapath)
 | 
			
		||||
        check_metadata(appinfo)
 | 
			
		||||
        apps[appid] = appinfo
 | 
			
		||||
 | 
			
		||||
    for metadatapath in sorted(glob.glob(os.path.join('metadata', '*.xml'))):
 | 
			
		||||
        appid, appinfo = parse_xml_metadata(apps, metadatapath)
 | 
			
		||||
        check_metadata(appinfo)
 | 
			
		||||
        apps[appid] = appinfo
 | 
			
		||||
 | 
			
		||||
    for metadatapath in sorted(glob.glob(os.path.join('metadata', '*.yaml'))):
 | 
			
		||||
        appid, appinfo = parse_yaml_metadata(apps, metadatapath)
 | 
			
		||||
    for metadatapath in sorted(glob.glob(os.path.join('metadata', '*.txt'))
 | 
			
		||||
                               + glob.glob(os.path.join('metadata', '*.json'))
 | 
			
		||||
                               + glob.glob(os.path.join('metadata', '*.xml'))
 | 
			
		||||
                               + glob.glob(os.path.join('metadata', '*.yaml'))):
 | 
			
		||||
        appid, appinfo = parse_metadata(apps, metadatapath)
 | 
			
		||||
        check_metadata(appinfo)
 | 
			
		||||
        apps[appid] = appinfo
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -731,6 +719,29 @@ def _decode_dict(data):
 | 
			
		|||
    return rv
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def parse_metadata(apps, metadatapath):
 | 
			
		||||
    root, ext = os.path.splitext(metadatapath)
 | 
			
		||||
    metadataformat = ext[1:]
 | 
			
		||||
    accepted = common.config['accepted_formats']
 | 
			
		||||
    if metadataformat not in accepted:
 | 
			
		||||
        logging.critical('"' + metadatapath
 | 
			
		||||
                         + '" is not in an accepted format, '
 | 
			
		||||
                         + 'convert to: ' + ', '.join(accepted))
 | 
			
		||||
        sys.exit(1)
 | 
			
		||||
 | 
			
		||||
    if metadataformat == 'txt':
 | 
			
		||||
        return parse_txt_metadata(apps, metadatapath)
 | 
			
		||||
    elif metadataformat == 'json':
 | 
			
		||||
        return parse_json_metadata(apps, metadatapath)
 | 
			
		||||
    elif metadataformat == 'xml':
 | 
			
		||||
        return parse_xml_metadata(apps, metadatapath)
 | 
			
		||||
    elif metadataformat == 'yaml':
 | 
			
		||||
        return parse_yaml_metadata(apps, metadatapath)
 | 
			
		||||
    else:
 | 
			
		||||
        logging.critical('Unknown metadata format: ' + metadatapath)
 | 
			
		||||
        sys.exit(1)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def parse_json_metadata(apps, metadatapath):
 | 
			
		||||
 | 
			
		||||
    appid, thisinfo = get_default_app_info_list(apps, metadatapath)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -29,11 +29,12 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
        self.maxDiff = None
 | 
			
		||||
 | 
			
		||||
        # these only need to be set to prevent code running on None.  The
 | 
			
		||||
        # values are not used in metadata.py
 | 
			
		||||
        # these need to be set to prevent code running on None, only
 | 
			
		||||
        # 'accepted_formats' is actually used in metadata.py
 | 
			
		||||
        config = dict()
 | 
			
		||||
        config['sdk_path'] = '/opt/android-sdk'
 | 
			
		||||
        config['ndk_paths'] = dict()
 | 
			
		||||
        config['accepted_formats'] = ['json', 'txt', 'xml', 'yaml']
 | 
			
		||||
        fdroidserver.common.config = config
 | 
			
		||||
 | 
			
		||||
        apps = fdroidserver.metadata.read_metadata(xref=True)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue