diff --git a/src/libprs500/manual/gui.html b/src/libprs500/manual/gui.html index e83aafd8bd..2eee951a1e 100644 --- a/src/libprs500/manual/gui.html +++ b/src/libprs500/manual/gui.html @@ -7,7 +7,7 @@ The Graphical User Interface - + diff --git a/src/libprs500/manual/images/cli.png b/src/libprs500/manual/images/cli.png new file mode 100644 index 0000000000..f6f94e7c0a Binary files /dev/null and b/src/libprs500/manual/images/cli.png differ diff --git a/src/libprs500/manual/libprs500.qhcp b/src/libprs500/manual/libprs500.qhcp index a501b8966b..4d99522707 100644 --- a/src/libprs500/manual/libprs500.qhcp +++ b/src/libprs500/manual/libprs500.qhcp @@ -2,7 +2,7 @@ libprs500 Help - qthelp://libprs500/manual/index.html + qthelp://libprs500/manual/start.html ../gui2/images/library.png false false diff --git a/src/libprs500/manual/libprs500.qhp b/src/libprs500/manual/libprs500.qhp index 5552224e4f..4797392025 100644 --- a/src/libprs500/manual/libprs500.qhp +++ b/src/libprs500/manual/libprs500.qhp @@ -10,16 +10,61 @@ libprs500 -
-
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- index.html + cli-isbndb.html + cli-pdfreflow.html + cli-mobi2lrf.html + cli-lrf-meta.html + cli-lit2lrf.html + cli-lrf2lrs.html + cli-index.html + cli-web2lrf.html + cli-lrs2lrf.html + cli-txt2lrf.html + start.html + cli-web2disk.html gui.html - common.css + cli-opf-meta.html + cli-html2lrf.html + cli-rtf2lrf.html + cli-librarything.html + cli-epub2lrf.html + cli-rtf-meta.html + cli-pdf2lrf.html + cli-lrf2html.html + cli-any2lrf.html + cli-mobi2oeb.html + styles/common.css images/edit_meta_information.png images/remove_books.png images/book_details.png @@ -37,6 +82,7 @@ images/news.png images/view.png images/fetch_news.png + images/cli.png diff --git a/src/libprs500/manual/libprs500.webprj b/src/libprs500/manual/libprs500.webprj index 97b7691da6..5171184d02 100644 --- a/src/libprs500/manual/libprs500.webprj +++ b/src/libprs500/manual/libprs500.webprj @@ -28,5 +28,7 @@ + + diff --git a/src/libprs500/manual/preprocess.py b/src/libprs500/manual/preprocess.py index 480ca234ec..3d940d498f 100644 --- a/src/libprs500/manual/preprocess.py +++ b/src/libprs500/manual/preprocess.py @@ -16,11 +16,16 @@ ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. '''''' -import sys, glob, mechanize, time, subprocess +import sys, glob, mechanize, time, subprocess, os, re from tempfile import NamedTemporaryFile from xml.etree.ElementTree import parse, tostring, fromstring from BeautifulSoup import BeautifulSoup +# Load libprs500 from source copy +sys.path[0:1] = [os.path.dirname(os.path.dirname(os.getcwdu()))] + +from libprs500.linux import entry_points + def browser(): opener = mechanize.Browser() opener.set_handle_refresh(True) @@ -32,8 +37,8 @@ def update_manifest(src='libprs500.qhp'): root = parse(src).getroot() files = root.find('filterSection').find('files') files.clear() - for f in glob.glob('*.html')+glob.glob('*.css')+glob.glob('images/*'): - if f.startswith('preview'): + for f in glob.glob('*.html')+glob.glob('styles/*.css')+glob.glob('images/*'): + if f.startswith('preview') or f in ('navtree.html', 'index.html'): continue files.append(fromstring('%s'%f)) @@ -46,6 +51,9 @@ def update_manifest(src='libprs500.qhp'): def validate_html(): br = browser() for f in glob.glob('*.html'): + if f.startswith('preview-'): + continue + print 'Validating', f raw = open(f).read() br.open('http://validator.w3.org/#validate_by_input') br.form = tuple(br.forms())[2] @@ -60,12 +68,152 @@ def validate_html(): time.sleep(2) return - +def clean(): + for pat in ('preview-*.html', '*.qhc', '*.qch', 'cli-*.html', '~/.assistant/libprs500*'): + for f in glob.glob(pat): + f = os.path.abspath(os.path.expanduser(f)) + if os.path.exists(f): + if os.path.isfile(f): + os.unlink(f) +def generate_cli_docs(src='libprs500.qhp'): + documented_cmds = [] + undocumented_cmds = [] + + for script in entry_points['console_scripts']: + module = script[script.index('=')+1:script.index(':')].strip() + cmd = script[:script.index('=')].strip() + module = __import__(module, fromlist=[module.split('.')[-1]]) + if hasattr(module, 'option_parser'): + documented_cmds.append((cmd, getattr(module, 'option_parser')())) + else: + undocumented_cmds.append(cmd) + + documented_cmds.sort(cmp=lambda x, y: cmp(x[0], y[0])) + undocumented_cmds.sort() + + + def sanitize_text(txt): + return txt.replace('&', '&').replace('<', '<').replace('>', '>') + + for cmd, parser in documented_cmds: + output = open('cli-%s.html'%cmd, 'wb') + template = open('templates/basic.html', 'rb').read() + usage = [sanitize_text(i) for i in parser.usage.replace('%prog', cmd).splitlines(True) if i] + usage[0] = '
%s
'%usage[0] + usage[1:] = [i.replace(cmd, '%s'%cmd) for i in usage[1:]] + usage = ''.join(usage).replace('\n', '
') + body = ('\n

%s

\n'%cmd)+'
\n%s\n
'%usage + + + groups = {} + for grp in parser.option_groups: + groups[(grp.title, grp.description)] = grp.option_list + + def group_html(title, description, option_list): + res = [] + + if title is not None: + res.append('

%s

'%title) + if description is not None: + res.append('%s
 '%sanitize_text(description)) + for opt in option_list: + shf = ' '.join(opt._short_opts) + lgf = opt.get_opt_string() + name = '%s
%s'%(lgf, shf) + help = sanitize_text(opt.help) if opt.help else '' + res.append('%s%s'%(name, help)) + return '\n'.join(res) + + + gh = [group_html(None, None, parser.option_list)] + for title, desc in groups.keys(): + olist = groups[(title, desc)] + gh.append(group_html(title, desc, olist)) + + if ''.join(gh).strip(): + body += '\n

[options]

\n' + body += '\n\n%s\n
\n'%'\n'.join(gh) + output.write(template.replace('%body', body)) + + uc_html = '\n
    \n%s
\n'%'\n'.join(\ + '
  • %s
  • \n'%i for i in undocumented_cmds) + dc_html = '\n
      \n%s
    \n'%'\n'.join(\ + '
  • %s
  • \n'%(i[0], i[0]) for i in documented_cmds) + + body = '

    The Command Line Interface

    \n' + body += '
    ' + body += '

    %s

    \n'%'libprs500 has a very comprehensive command line interface to perform most operations that can be performed by the GUI.' + body += '

    Documented commands

    \n'+dc_html + body += '

    Undocumented commands

    \n'+uc_html + body += '

    You can see usage for undocumented commands by executing them without arguments in a terminal

    ' + open('cli-index.html', 'wb').write(template.replace('%body', body)) + + + + root = parse(src).getroot() + toc = root.find('filterSection').find('toc') + sec = None + + for c in toc.findall('section'): + if c.attrib['ref'] == 'cli-index.html': + sec = c + break + attr = sec.attrib.copy() + sec.clear() + sec.attrib = attr + + cmds = [i[0] for i in documented_cmds] + secs = ['
    \n'%(i, i) for i in cmds] + [sec.append(fromstring(i)) for i in secs] + raw = tostring(root, 'UTF-8') + raw = re.sub(r'(
    \n%s\n\n'%(sec.attrib['ref'], sec.attrib['title']) + if toplevel: + html=html.replace('','%s\n'%process_branch(sec)) + type = 'folder' + + parent.append(html.replace('||||', type)) + html = '\n'.join(parent) + if toplevel: + return html + return '
      \n%s\n
    '%html + + tree = process_branch(toc, True) + + template = open('templates/navtree.html').read() + open('navtree.html', 'wb').write(template.replace('%tree', tree)) + + def main(args=sys.argv): + generate_cli_docs() update_manifest() - validate_html() + create_html_interface() + #validate_html() + + return 0 diff --git a/src/libprs500/manual/index.html b/src/libprs500/manual/start.html similarity index 91% rename from src/libprs500/manual/index.html rename to src/libprs500/manual/start.html index ce7900fdaa..2997ad1932 100644 --- a/src/libprs500/manual/index.html +++ b/src/libprs500/manual/start.html @@ -7,7 +7,7 @@ libprs500 User Manual - + diff --git a/src/libprs500/manual/common.css b/src/libprs500/manual/styles/common.css similarity index 54% rename from src/libprs500/manual/common.css rename to src/libprs500/manual/styles/common.css index 9f7ed49057..76a3b8e8c1 100644 --- a/src/libprs500/manual/common.css +++ b/src/libprs500/manual/styles/common.css @@ -5,12 +5,17 @@ body { a { text-decoration: none; + color: blue; } a:hover { color: red; } +a:visited { + color: blue; +} + .documentHeading { text-align: center; font-family: monospace; @@ -33,4 +38,30 @@ font-family: monospace; font-size: x-small; color: lightgray; text-align: right; +} + +.option { + font-family: monospace; + color: green; +} + + +.option_table td { + padding-bottom : 1em; +} + +.cmd { + font-family: monospace; + font-weight: bold; +} + +.runcmd { + background: #eeeeee; + border: inset 2px; + padding: 0.2em; +} + +.cmdlist li { + font-family: monospace; + margin-bottom: 0.2em; } \ No newline at end of file diff --git a/src/libprs500/manual/templates/basic.html b/src/libprs500/manual/templates/basic.html index 58d245eb92..deb45fd783 100644 --- a/src/libprs500/manual/templates/basic.html +++ b/src/libprs500/manual/templates/basic.html @@ -1,20 +1,18 @@ - + - + + %body