diff --git a/README.md b/README.md index 145cc45..e54a3b1 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,15 @@ After installing etherpump on the Varia server, we collectively decided to not w Change log / notes ================== +**October 2019** + +Improve `etherpump --help` handling to make it easier for new users. + +Added the `python-dateutil` and `pypandoc` dependencies + **September 2019** -Forking *etherpump* into *etherpump*. (Work in progress!) +Forking *etherpump* into *etherpump*. diff --git a/bin/etherpump b/bin/etherpump index 66d4e56..3ad5858 100755 --- a/bin/etherpump +++ b/bin/etherpump @@ -2,6 +2,7 @@ import os import sys +from importlib import import_module from pathlib import Path from etherpump import __VERSION__ @@ -9,14 +10,23 @@ from etherpump import __VERSION__ def subcommands(): """List all sub-commands for the `--help` output.""" + not_sub_commands = ['common.py', 'appendmeta.py', 'html5tidy.py', 'join.py'] subcommands = [] all_files = os.listdir(Path().absolute() / 'etherpump' / 'commands') - modules = filter(lambda file: not file.startswith('__'), all_files) + modules = filter( + lambda file: not file.startswith('__') + and not any(file == module for module in not_sub_commands), + all_files, + ) for module in modules: name = module.split('.py')[0] - subcommands.append(f' {name}') + try: + doc = import_module(f'etherpump.commands.{name}').__doc__ + except ModuleNotFoundError: + doc = "" + subcommands.append(f' {name}: {doc}') subcommands.sort() diff --git a/etherpump/commands/appendmeta.py b/etherpump/commands/appendmeta.py index 578ec18..356112d 100644 --- a/etherpump/commands/appendmeta.py +++ b/etherpump/commands/appendmeta.py @@ -1,8 +1,6 @@ #!/usr/bin/env python - import json -import os from argparse import ArgumentParser diff --git a/etherpump/commands/creatediffhtml.py b/etherpump/commands/creatediffhtml.py index bdf8d10..f24d7b8 100644 --- a/etherpump/commands/creatediffhtml.py +++ b/etherpump/commands/creatediffhtml.py @@ -1,3 +1,5 @@ +"""Calls the createDiffHTML API function for the given padid""" + import json from argparse import ArgumentParser from urllib.error import HTTPError, URLError diff --git a/etherpump/commands/deletepad.py b/etherpump/commands/deletepad.py index c2a2c7e..be9397c 100644 --- a/etherpump/commands/deletepad.py +++ b/etherpump/commands/deletepad.py @@ -1,3 +1,5 @@ +"""Calls the getText API function for the given padid""" + import json from argparse import ArgumentParser from urllib.error import HTTPError, URLError diff --git a/etherpump/commands/dumpcsv.py b/etherpump/commands/dumpcsv.py index 7ce2690..bda3aee 100644 --- a/etherpump/commands/dumpcsv.py +++ b/etherpump/commands/dumpcsv.py @@ -1,3 +1,5 @@ +"""Dumps a CSV of all pads""" + import json import re import sys diff --git a/etherpump/commands/gethtml.py b/etherpump/commands/gethtml.py index 3154feb..87c8b87 100644 --- a/etherpump/commands/gethtml.py +++ b/etherpump/commands/gethtml.py @@ -1,3 +1,5 @@ +"""Calls the getHTML API function for the given padid""" + import json from argparse import ArgumentParser from urllib.error import HTTPError, URLError diff --git a/etherpump/commands/gettext.py b/etherpump/commands/gettext.py index e66e81a..82909ad 100644 --- a/etherpump/commands/gettext.py +++ b/etherpump/commands/gettext.py @@ -1,3 +1,5 @@ +"""Calls the getText API function for the given padid""" + import json import sys from argparse import ArgumentParser diff --git a/etherpump/commands/index.py b/etherpump/commands/index.py index e811320..db10f6b 100644 --- a/etherpump/commands/index.py +++ b/etherpump/commands/index.py @@ -1,3 +1,5 @@ +"""Generate pages from etherpumps using a template""" + import json import os import re @@ -5,14 +7,12 @@ import sys import time from argparse import ArgumentParser from datetime import datetime -from time import sleep -from urllib.parse import quote, urlencode, urlparse, urlunparse -from urllib.request import HTTPError, URLError, urlopen +from urllib.parse import urlparse, urlunparse from jinja2 import Environment, FileSystemLoader import dateutil.parser -from etherpump.commands.common import * +from etherpump.commands.common import * # noqa """ @@ -39,10 +39,6 @@ def group(items, key=lambda x: x): return ret -# def base (x): -# return re.sub(r"(\.raw\.html)|(\.diff\.html)|(\.meta\.json)|(\.raw\.txt)$", "", x) - - def splitextlong(x): """ split "long" extensions, i.e. foo.bar.baz => ('foo', '.bar.baz') """ m = re.search(r"^(.*?)(\..*)$", x) diff --git a/etherpump/commands/init.py b/etherpump/commands/init.py index 04d84c0..4d22937 100644 --- a/etherpump/commands/init.py +++ b/etherpump/commands/init.py @@ -1,3 +1,5 @@ +"""Initialize an etherpump folder""" + import json import os import sys @@ -11,7 +13,6 @@ def get_api(url, cmd=None, data=None, verbose=False): useurl = url + cmd if data: useurl += "?" + urlencode(data) - # data['apikey'] = "7c8faa070c97f83d8f705c935a32d5141f89cbaa2158042fa92e8ddad5dbc5e1" if verbose: print("trying", useurl, file=sys.stderr) resp = urlopen(useurl).read() @@ -29,10 +30,6 @@ def get_api(url, cmd=None, data=None, verbose=False): if e.code == 401: # Unauthorized is how the API responds to an incorrect API key return {"code": 401, "message": e} - # resp = json.load(e) - # if "code" in resp and "message" in resp: - # # print ("returning", resp, file=sys.stderr) - # return resp def tryapiurl(url, verbose=False): @@ -58,8 +55,6 @@ def tryapiurl(url, verbose=False): apiurl = urlunparse((scheme, netloc, path, params, query, fragment)) if get_api(apiurl, "listAllPads", verbose=verbose): return apiurl - # except ValueError as e: - # print ("ValueError", e, file=sys.stderr) except URLError as e: print("URLError", e, file=sys.stderr) diff --git a/etherpump/commands/list.py b/etherpump/commands/list.py index 9ba715d..e5b985f 100644 --- a/etherpump/commands/list.py +++ b/etherpump/commands/list.py @@ -1,3 +1,5 @@ +"""Call listAllPads and print the results""" + import json import sys from argparse import ArgumentParser diff --git a/etherpump/commands/listauthors.py b/etherpump/commands/listauthors.py index d530162..e0ff08e 100644 --- a/etherpump/commands/listauthors.py +++ b/etherpump/commands/listauthors.py @@ -1,6 +1,7 @@ +"""Call listAuthorsOfPad for the padid""" + import json from argparse import ArgumentParser -from urllib.error import HTTPError, URLError from urllib.parse import urlencode from urllib.request import urlopen diff --git a/etherpump/commands/publication.py b/etherpump/commands/publication.py index c060d6a..5f821af 100644 --- a/etherpump/commands/publication.py +++ b/etherpump/commands/publication.py @@ -1,3 +1,5 @@ +"""Generate a single document from etherpumps using a template""" + import json import os import re @@ -5,15 +7,13 @@ import sys import time from argparse import ArgumentParser from datetime import datetime -from time import sleep -from urllib.parse import quote, urlencode, urlparse, urlunparse -from urllib.request import HTTPError, URLError, urlopen +from urllib.parse import urlparse, urlunparse from jinja2 import Environment, FileSystemLoader import dateutil.parser import pypandoc -from etherpump.commands.common import * +from etherpump.commands.common import * # noqa """ diff --git a/etherpump/commands/pull.py b/etherpump/commands/pull.py index 8c38ea0..3ae06f0 100644 --- a/etherpump/commands/pull.py +++ b/etherpump/commands/pull.py @@ -1,3 +1,5 @@ +"""Check for pads that have changed since last sync (according to .meta.json)""" + import json import os import re @@ -7,12 +9,12 @@ from datetime import datetime from fnmatch import fnmatch from time import sleep from urllib.parse import quote, urlencode -from urllib.request import HTTPError, URLError, urlopen +from urllib.request import HTTPError from xml.etree import ElementTree as ET import html5lib -from etherpump.commands.common import * +from etherpump.commands.common import * # noqa from etherpump.commands.html5tidy import html5tidy @@ -20,12 +22,8 @@ from etherpump.commands.html5tidy import html5tidy pull(meta): Update meta data files for those that have changed. Check for changed pads by looking at revisions & comparing to existing - - todo... use/prefer public interfaces ? (export functions) - - """ @@ -33,7 +31,7 @@ def try_deleting(files): for f in files: try: os.remove(f) - except OSError as e: + except OSError: pass diff --git a/etherpump/commands/revisionscount.py b/etherpump/commands/revisionscount.py index ea374af..c397ce5 100644 --- a/etherpump/commands/revisionscount.py +++ b/etherpump/commands/revisionscount.py @@ -1,3 +1,5 @@ +"""Call getRevisionsCount for the given padid""" + import json from argparse import ArgumentParser from urllib.error import HTTPError, URLError diff --git a/etherpump/commands/sethtml.py b/etherpump/commands/sethtml.py index 5bf6835..1ef3715 100644 --- a/etherpump/commands/sethtml.py +++ b/etherpump/commands/sethtml.py @@ -1,7 +1,8 @@ +"""Calls the setHTML API function for the given padid""" + import json import sys from argparse import ArgumentParser -from urllib.error import HTTPError, URLError from urllib.parse import urlencode from urllib.request import urlopen diff --git a/etherpump/commands/settext.py b/etherpump/commands/settext.py index 8368e22..24516d6 100644 --- a/etherpump/commands/settext.py +++ b/etherpump/commands/settext.py @@ -1,8 +1,10 @@ +"""Calls the getText API function for the given padid""" + import json import sys from argparse import ArgumentParser -from urllib.parse import quote, urlencode -from urllib.request import HTTPError, URLError, urlopen +from urllib.parse import urlencode +from urllib.request import urlopen import requests diff --git a/etherpump/commands/showmeta.py b/etherpump/commands/showmeta.py index d58d6ef..70ef29a 100644 --- a/etherpump/commands/showmeta.py +++ b/etherpump/commands/showmeta.py @@ -1,9 +1,11 @@ +"""Extract and output selected fields of metadata""" + import json import re import sys from argparse import ArgumentParser -from .common import * +from .common import * # noqa """ diff --git a/etherpump/commands/status.py b/etherpump/commands/status.py index b08cda6..76e93af 100644 --- a/etherpump/commands/status.py +++ b/etherpump/commands/status.py @@ -1,15 +1,10 @@ -import json +"""Update meta data files for those that have changed""" + import os -import re -import sys from argparse import ArgumentParser -from datetime import datetime -from math import ceil, floor -from urllib.error import HTTPError, URLError from urllib.parse import urlencode -from urllib.request import urlopen -from .common import * +from .common import * # noqa """ @@ -22,7 +17,7 @@ design decisions... ok based on the fact that only the txt file is pushable (via setText) it makes sense to give this file "primacy" ... ie to put the other forms (html, diff.html) in a special place (if created at all). Otherwise this -complicates the "syncing" idea.... +complicates the "syncing" idea.... """ diff --git a/setup.py b/setup.py index 3e47cae..97428ba 100644 --- a/setup.py +++ b/setup.py @@ -42,7 +42,7 @@ setup( description='Etherpump: pumping text from etherpads into publications', long_description=long_description, long_description_content_type='text/markdown', - install_requires=["html5lib", "jinja2"], + install_requires=["html5lib", "jinja2", "python-dateutil", "pypandoc"], classifiers=[ 'Programming Language :: Python :: 3', 'Environment :: Console',