New ini syntax for list after =
authorKarl O. Pinc <kop@karlpinc.com>
Fri, 20 Nov 2020 23:37:44 +0000 (17:37 -0600)
committerKarl O. Pinc <kop@karlpinc.com>
Fri, 20 Nov 2020 23:37:44 +0000 (17:37 -0600)
examples/etc/pgwui.ini
examples/misc/development.ini
src/pgwui_server/pgwui_server.py
tests/test_pgwui_server.py

index 5bf231c397b3e75004db6fb4f7bc2064c80dbcb5..969a4dc87e94058c5c228ff557b3986da4491cf5 100644 (file)
@@ -89,10 +89,16 @@ pgwui.dry_run = False
 # PGWUI components in use.  The display value of the menu items can
 # be overridden using a "menu_label" setting for each component.
 # CAUTION: Do not uncomment the below, instead change the component's
-# "menu_label" setting.
+# "menu_label" setting.  E.g.:
 #pgwui.pgwui_upload =
 #    menu_label = upload -- Upload File Into Database
 
+# The order of the menu items can be manually specified based
+# PGWUI component name.  Omitted components come last.
+#pgwui.pgwui_menu =
+#    order = pgwui_upload
+#            pgwui_logout
+
 # pgwui_upload
 
 # Take uploaded column headings literally?
@@ -108,6 +114,7 @@ pgwui.pgwui_upload =
     literal_column_headings = off
     # menu_label = upload -- Upload File Into Database
 
+
 #
 # Pyramid configuration
 # https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html
index 645de433e6583e8150d5fe9b8f4b35f9c0022729..0d069bd39fdcc6c7054874f425f3123ef526150f 100644 (file)
@@ -93,6 +93,12 @@ pgwui.validate_hmac = False
 #pgwui.pgwui_upload =
 #    menu_label = upload -- Upload File Into Database
 
+# The order of the menu items can be manually specified based
+# PGWUI component name.  Omitted components come last.
+#pgwui.pgwui_menu =
+#    order = pgwui_upload
+#            pgwui_logout
+
 # pgwui_upload
 
 # Take uploaded column headings literally?
index eb3b7c39c90beec63ef4735a66d49a577012daf9..776e3fdd7fe52961cc58630bd123210aedc8fe1b 100644 (file)
@@ -77,15 +77,30 @@ def dot_to_dict(settings, key, new_key):
     del settings[key]
 
 
+def parse_multiline_assignments(lines, result):
+    '''Add the parse value to the result
+    '''
+    for line in lines.splitlines():
+        if '=' in line:
+            key, val = line.split('=', 1)
+            result.append((key.rstrip(), val.lstrip()))
+        else:
+            stripped = line.lstrip()
+            if stripped != '':
+                # Multiple values on different lines means a list
+                key, val = result[-1]
+                if not isinstance(val, list):
+                    val = [val]
+                val.append(stripped)
+                result[-1] = (key, val)
+
+
 def parse_assignments(lines):
     '''Return a list of key/value tuples from the lines of a setting
     '''
     result = []
     if isinstance(lines, str):
-        for line in lines.splitlines():
-            if '=' in line:
-                key, val = line.split('=', 1)
-                result.append((key.rstrip(), val.lstrip()))
+        parse_multiline_assignments(lines, result)
     else:
         for key, val in lines.items():
             result.append((key, val))
index 2ba90a11eb45e56b8a979bfb89e8ca171bc57871..640202a69d9f3de5f28d85cc391c169aab0bdfe8 100644 (file)
@@ -173,23 +173,46 @@ mock_dot_to_dict = testing.make_mock_fixture(
     pgwui_server, 'dot_to_dict')
 
 
+# parse_multiline_assigments()
+
+
+def test_parse_multiline_assignments_str():
+    '''Appends key/value string tuples and when there's no "=",
+    and more than just whitespace, a list is the result
+    '''
+    lines = ('key1 = value1\n'  # whitespace around = is ignored
+             '\n'
+             'second\n'
+             'third\n'
+             'key2=value2\n'    # missing whitespace is fine
+             'key3= value3=withequals\n'
+             )
+    result = []
+    pgwui_server.parse_multiline_assignments(lines, result)
+    assert result == [('key1', ['value1', 'second', 'third']),
+                      ('key2', 'value2'),
+                      ('key3', 'value3=withequals')]
+
+
+mock_parse_multiline_assignments = testing.make_mock_fixture(
+    pgwui_server, 'parse_multiline_assignments')
+
+
 # parse_assignments()
 
-def test_parse_assignments_str():
-    '''Returns key/value string tuples and ignores lines without an "="'''
+def test_parse_assignments_str(mock_parse_multiline_assignments):
+    '''Calls parse_multiline_assignments'''
     lines = ('key1 = value1\n'  # whitespace around = is ignored
              '\n'
              'ignored\n'
              'key2=value2\n'    # missing whitespace is fine
              'key3= value3=withequals\n'
              )
-    result = pgwui_server.parse_assignments(lines)
-    assert set(result) == set([('key1', 'value1'),
-                               ('key2', 'value2'),
-                               ('key3', 'value3=withequals')])
+    pgwui_server.parse_assignments(lines)
+    mock_parse_multiline_assignments.assert_called_once()
 
 
-def test_parse_assignments_dict():
+def test_parse_assignments_dict(mock_parse_multiline_assignments):
     '''Returns key value tuples.
     '''
     lines = {'key1': 'value1',