mirror of
				https://github.com/f-droid/fdroidserver.git
				synced 2025-11-04 06:30:27 +03:00 
			
		
		
		
	common.get_app_display_name() for finding app names
This commit is contained in:
		
							parent
							
								
									c7fcfe3bfa
								
							
						
					
					
						commit
						0f6b638986
					
				
					 6 changed files with 44 additions and 11 deletions
				
			
		| 
						 | 
				
			
			@ -326,7 +326,7 @@ def try_init_submodules(app, last_build, vcs):
 | 
			
		|||
        try:
 | 
			
		||||
            vcs.initsubmodules()
 | 
			
		||||
        except NoSubmodulesException:
 | 
			
		||||
            logging.info("No submodules present for {}".format(app.Name))
 | 
			
		||||
            logging.info("No submodules present for {}".format(_getappname(app)))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Return all directories under startdir that contain any of the manifest
 | 
			
		||||
| 
						 | 
				
			
			@ -359,11 +359,7 @@ def possible_subdirs(app):
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
def _getappname(app):
 | 
			
		||||
    if app.Name:
 | 
			
		||||
        return app.Name
 | 
			
		||||
    if app.AutoName:
 | 
			
		||||
        return app.AutoName
 | 
			
		||||
    return app.id
 | 
			
		||||
    return common.get_app_display_name(app)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _getcvname(app):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3628,6 +3628,26 @@ def version_code_string_to_int(vercode):
 | 
			
		|||
        return int(vercode)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_app_display_name(app):
 | 
			
		||||
    """get a human readable name for the app for logging and sorting
 | 
			
		||||
 | 
			
		||||
    When trying to find a localized name, this first tries en-US since
 | 
			
		||||
    that his the historical language used for sorting.
 | 
			
		||||
 | 
			
		||||
    """
 | 
			
		||||
    if app.get('Name'):
 | 
			
		||||
        return app['Name']
 | 
			
		||||
    if app.get('localized'):
 | 
			
		||||
        localized = app['localized'].get('en-US')
 | 
			
		||||
        if not localized:
 | 
			
		||||
            for v in app['localized'].values():
 | 
			
		||||
                localized = v
 | 
			
		||||
                break
 | 
			
		||||
        if localized.get('name'):
 | 
			
		||||
            return localized['name']
 | 
			
		||||
    return app.get('AutoName') or app['id']
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def local_rsync(options, fromdir, todir):
 | 
			
		||||
    '''Rsync method for local to local copying of things
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -61,7 +61,7 @@ def make(apps, apks, repodir, archive):
 | 
			
		|||
        common.assert_config_keystore(common.config)
 | 
			
		||||
 | 
			
		||||
    # Historically the index has been sorted by App Name, so we enforce this ordering here
 | 
			
		||||
    sortedids = sorted(apps, key=lambda appid: apps[appid]['Name'].upper())
 | 
			
		||||
    sortedids = sorted(apps, key=lambda appid: common.get_app_display_name(apps[appid]).upper())
 | 
			
		||||
    sortedapps = collections.OrderedDict()
 | 
			
		||||
    for appid in sortedids:
 | 
			
		||||
        sortedapps[appid] = apps[appid]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -337,7 +337,7 @@ def check_duplicates(app):
 | 
			
		|||
        else:
 | 
			
		||||
            links_seen.add(v)
 | 
			
		||||
 | 
			
		||||
    name = app.Name or app.AutoName
 | 
			
		||||
    name = common.get_app_display_name(app)
 | 
			
		||||
    if app.Summary and name:
 | 
			
		||||
        if app.Summary.lower() == name.lower():
 | 
			
		||||
            yield _("Summary '%s' is just the app's name") % app.Summary
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -207,9 +207,12 @@ def update_wiki(apps, apks):
 | 
			
		|||
            requiresroot = 'Yes'
 | 
			
		||||
        else:
 | 
			
		||||
            requiresroot = 'No'
 | 
			
		||||
 | 
			
		||||
        apppagename = common.get_app_display_name(app)
 | 
			
		||||
 | 
			
		||||
        wikidata += '{{App|id=%s|name=%s|added=%s|lastupdated=%s|source=%s|tracker=%s|web=%s|changelog=%s|donate=%s|flattr=%s|liberapay=%s|bitcoin=%s|litecoin=%s|license=%s|root=%s|author=%s|email=%s}}\n' % (
 | 
			
		||||
            appid,
 | 
			
		||||
            app.Name,
 | 
			
		||||
            apppagename,
 | 
			
		||||
            app.added.strftime('%Y-%m-%d') if app.added else '',
 | 
			
		||||
            app.lastUpdated.strftime('%Y-%m-%d') if app.lastUpdated else '',
 | 
			
		||||
            app.SourceCode,
 | 
			
		||||
| 
						 | 
				
			
			@ -338,7 +341,6 @@ def update_wiki(apps, apks):
 | 
			
		|||
        # Make a redirect from the name to the ID too, unless there's
 | 
			
		||||
        # already an existing page with the name and it isn't a redirect.
 | 
			
		||||
        noclobber = False
 | 
			
		||||
        apppagename = app.Name
 | 
			
		||||
        for ch in '_{}:[]|':
 | 
			
		||||
            apppagename = apppagename.replace(ch, ' ')
 | 
			
		||||
        # Drop double spaces caused mostly by replacing ':' above
 | 
			
		||||
| 
						 | 
				
			
			@ -2116,7 +2118,7 @@ def read_names_from_apks(apps, apks):
 | 
			
		|||
 | 
			
		||||
        if bestver == UNSET_VERSION_CODE:
 | 
			
		||||
            if app.Name is None:
 | 
			
		||||
                app.Name = app.AutoName or appid
 | 
			
		||||
                app.Name = common.get_app_display_name(app)
 | 
			
		||||
            app.icon = None
 | 
			
		||||
        else:
 | 
			
		||||
            if app.Name is None:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1612,6 +1612,21 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
        self.assertEqual([dirtyfile, 'repo/status/running.json'],
 | 
			
		||||
                         data['fdroiddata']['untrackedFiles'])
 | 
			
		||||
 | 
			
		||||
    def test_get_app_display_name(self):
 | 
			
		||||
        testvalue = 'WIN!'
 | 
			
		||||
        for app in [
 | 
			
		||||
                {'Name': testvalue},
 | 
			
		||||
                {'AutoName': testvalue},
 | 
			
		||||
                {'id': testvalue},
 | 
			
		||||
                {'id': 'a', 'localized': {'de-AT': {'name': testvalue}}},
 | 
			
		||||
                {'id': 'a', 'localized': {
 | 
			
		||||
                    'de-AT': {'name': 'nope'},
 | 
			
		||||
                    'en-US': {'name': testvalue},
 | 
			
		||||
                }},
 | 
			
		||||
                {'AutoName': 'ignore me', 'Name': testvalue, 'id': 'nope'},
 | 
			
		||||
                {'AutoName': testvalue, 'id': 'nope'}]:
 | 
			
		||||
            self.assertEqual(testvalue, fdroidserver.common.get_app_display_name(app))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    os.chdir(os.path.dirname(__file__))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue