auto-clean newlines and spaces in repo/archive descriptions

This gives us flexibility in how the blocks of text can be formatted in
config.py, but also provides a more useful format for displaying since the
client can decide where to wrap the text.
This commit is contained in:
Hans-Christoph Steiner 2014-07-02 20:57:47 -04:00
parent c7962e7c6d
commit f34c842f55
3 changed files with 80 additions and 13 deletions

View file

@ -62,11 +62,12 @@ def get_default_config():
'repo_url': "https://MyFirstFDroidRepo.org/fdroid/repo",
'repo_name': "My First FDroid Repo Demo",
'repo_icon': "fdroid-icon.png",
'repo_description': (
"This is a repository of apps to be used with FDroid. Applications in this "
+ "repository are either official binaries built by the original application "
+ "developers, or are binaries built from source by the admin of f-droid.org "
+ "using the tools on https://gitlab.com/u/fdroid."),
'repo_description': '''
This is a repository of apps to be used with FDroid. Applications in this
repository are either official binaries built by the original application
developers, or are binaries built from source by the admin of f-droid.org
using the tools on https://gitlab.com/u/fdroid.
''',
'archive_older': 0,
}
@ -163,6 +164,10 @@ def read_config(opts, config_file='config.py'):
if k in config:
write_password_file(k)
for k in ["repo_description", "archive_description"]:
if k in config:
config[k] = clean_description(config[k])
# since this is used with rsync, where trailing slashes have meaning,
# ensure there is always a trailing slash
if 'serverwebroot' in config:
@ -290,6 +295,19 @@ def has_extension(filename, extension):
apk_regex = None
def clean_description(description):
'Remove unneeded newlines and spaces from a block of description text'
returnstring = ''
# this is split up by paragraph to make removing the newlines easier
for paragraph in re.split(r'\n\n', description):
paragraph = re.sub('\r', '', paragraph)
paragraph = re.sub('\n', ' ', paragraph)
paragraph = re.sub(' {2,}', ' ', paragraph)
paragraph = re.sub('^\s*(\w)', r'\1', paragraph)
returnstring += paragraph + '\n\n'
return returnstring.rstrip('\n')
def apknameinfo(filename):
global apk_regex
filename = os.path.basename(filename)