chiark / gitweb /
auto-clean newlines and spaces in repo/archive descriptions
authorHans-Christoph Steiner <hans@eds.org>
Thu, 3 Jul 2014 00:57:47 +0000 (20:57 -0400)
committerHans-Christoph Steiner <hans@eds.org>
Mon, 14 Jul 2014 19:01:57 +0000 (15:01 -0400)
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.

examples/config.py
fdroidserver/common.py
tests/description-parsing.py [new file with mode: 0755]

index ce9f0b8701382b8376299919fb4cb5654b881e28..3918774a32d23a6bb62c700cfd6b5a9b3a33cafa 100644 (file)
@@ -33,11 +33,12 @@ repo_maxage = 0
 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.
+"""
 
 # As above, but for the archive repo.
 # archive_older sets the number of versions kept in the main repo, with all
@@ -47,9 +48,9 @@ archive_older = 3
 archive_url = "https://f-droid.org/archive"
 archive_name = "My First FDroid Archive Demo"
 archive_icon = "fdroid-icon.png"
-archive_description = (
-    "The repository of older versions of applications from the main demo "
-    + "repository.")
+archive_description = """
+The repository of older versions of applications from the main demo repository.
+"""
 
 
 # The ID of a GPG key for making detached signatures for apks. Optional.
index 663af8b1485cc90412c4e0a84f29fb41e9f2d591..c04a5c699b1e2b0bf5ca999f1c26468f50fca7f3 100644 (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)
diff --git a/tests/description-parsing.py b/tests/description-parsing.py
new file mode 100755 (executable)
index 0000000..05eba4b
--- /dev/null
@@ -0,0 +1,48 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+import os
+import sys
+
+sys.path.insert(1, os.path.join(os.getcwd(), '..', 'fdroidserver'))
+import common
+
+config = common.get_default_config()
+
+testtext = '''
+This is a block of text that has been wrapped to fit nicely in PEP8 style:
+
+GnuPrivacyGuard extends the gpgcli command line tool to bring an integrated
+privacy engine to your Android. It gives you command line access to the entire
+GnuPG suite of encryption software. It also serves as the test bed for
+complete Android integration for all of GnuPG's crypto services, including
+OpenPGP, symmetric encryption, and more.
+
+GPG is GNU’s tool for end-to-end secure communication and encrypted data
+storage. This trusted protocol is the free software alternative to PGP. This
+app is built upon GnuPG 2.1, the new modularized version of GnuPG that now
+supports S/MIME.
+
+GPG aims to provide an integrated experience, so clicking on PGP files should
+"just work". You can also share files to GPG to encrypt them. GPG will also
+respond when you click on a PGP fingerprint URL (one that starts with
+openpgp4fpr:).
+
+Before using GPG, be sure to launch the app and let it finish its installation
+process. Once it has completed, then you're ready to use it. The easiest way
+to get started with GPG is to install [[jackpal.androidterm]]. GPG will
+automatically configure Android Terminal Emulator as long as you have the
+"Allow PATH extensions" settings enabled.
+'''
+
+archive_description = """
+The repository of older versions of applications from the main demo repository.
+"""
+
+
+print('\n\n\n----------------------------------------------------')
+print(common.clean_description(testtext))
+print('\n\n\n----------------------------------------------------')
+print(common.clean_description(archive_description))
+print('\n\n\n----------------------------------------------------')
+print(common.clean_description(config['repo_description']))