Initial commit of the first prototype.

This commit is contained in:
Johannes Findeisen 2022-10-19 00:54:19 +02:00
commit 992d60336a
10 changed files with 97 additions and 319 deletions

5
.gitignore vendored
View file

@ -1,2 +1,5 @@
.idea/
man2ebook.iml
man2book.iml
/output/*.html
/tmp/
/venv/

View file

@ -1,6 +1,6 @@
MIT License
Copyright (c) <year> <copyright holders>
Copyright (c) 2022 Johannes Findeisen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

2
Makefile Normal file
View file

@ -0,0 +1,2 @@
clean:
rm -rf ./output/*.html

View file

@ -1,6 +1,6 @@
# man2ebook
# man2book
A tool to convert all installed man pages to a simple ebook with contents in the head.
A tool to convert all installed man pages to a simple ebook or other formats with contents in the head.
Maybe this could be only a small shell script but if not I will use Python.
@ -24,3 +24,15 @@ Not more... ;)
- https://docutils.sourceforge.io/ - Python
(as I can see now it only converts from .rst files.)
- https://github.com/hanez/aov-html2epub - Bash
## Workflow
1. Read manpage sections
2. Create HTML file for each manpage in each section
3. Read and store title(metadata) for in each file
4. Remove all unneeded stuff like html, head and body in each file
5. Create TOC for the entire ebook
6. Create a header HTML file for the ebook containing the head tag
7. Merge toc and content of all files for preparing the ebook
8. Merge the header file with the prepared ebook while inserting html and body tags which should result in a valid HTML file
9. Create ebook from the resulting HTML file using Pandoc

View file

@ -1,17 +0,0 @@
Mind Map generated by NB MindMap plugin
> __version__=`1.1`,showJumps=`true`
---
# man page
## "pandoc", "man2html" or "man \-Thtml df \> df\.html"
### maybe create a metadata file
### create contents and index files
### cleanup contents and index files
### merge contents and index files
### create epub file \(pandoc\)

74
man2book Executable file
View file

@ -0,0 +1,74 @@
#!/usr/bin/python3
import argparse
import os
# the limit is just for development to limit the number of man pages in each section. set to 0 to
# have no limit.
LIMIT = 0
MANPAGE_PATH = '/usr/share/man/'
OUTPUT_DIR = '~/code/man2book/output/'
TMP_DIR = '/tmp'
__author__ = 'Johannes Findeisen <you@hanez.org'
__version__ = '0.0.1'
def parse_args():
parser = argparse.ArgumentParser(
description='man2book is a tool to create a custom ebook of installed man pages or a '
'selection of manpage sections and pages.',
epilog='author: ' + __author__,
prog='man2book')
# if using this feature there must be a way to set the section for each manpage since the name
# can be used in more than one section. maybe make it optional like df:1 or so. so this feature
# is not reliable at the moment.
parser.add_argument('-m', '--manpages', metavar='MANPAGES', help='limit only to a subset of '
'man pages. e.g. cd or a list '
'like cd,df,mv. this feature '
'is not reliable at the '
'moment because it should be '
'possible to set the section '
'here optionally for each '
'manpage! e.g. df:1')
parser.add_argument('-s', '--sections', metavar='SECTIONS', help='the manpage sections. e.g. 8 '
'or a list like 1,2,3')
parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + str(__version__))
return parser.parse_args()
args = parse_args()
sections = ['1', '2', '3', '4', '5', '6', '7', '8']
if args.sections:
args_sections = args.sections.split(',')
new_sections = []
for section in args_sections:
if section not in sections:
print('section ' + section + ' not found! aborting...')
exit(1)
new_sections.append(section)
sections = new_sections
for section in sections:
x = 1
for manpage_file in os.listdir(MANPAGE_PATH + 'man' + section + '/'):
manpage = os.path.splitext(os.path.basename(manpage_file))[0]
manpage = os.path.splitext(manpage)[0]
if args.manpages:
manpages = args.manpages.split(',')
if manpage in manpages:
# this needs to be taken over by pandoc to create not only single pages but a whole
# ebook. this will require a lot of output manipulation before. removing html, head,
# body tags etc. before i need to get the title to create chapters from them and
# create and to create a toc. maybe the anchor in the toc can be a hash
os.system('/usr/bin/man -Thtml ' + manpage + ' > ' + OUTPUT_DIR + 'man' + section +
'.' + manpage + '.html')
if LIMIT > 0:
if x == LIMIT:
break
x += 1

0
output/.gitkeep Normal file
View file

2
requirements.txt Normal file
View file

@ -0,0 +1,2 @@
lxml~=4.9.1
pandocfilters~=1.5.0

View file

@ -1,298 +0,0 @@
<!-- Creator : groff version 1.22.4 -->
<!-- CreationDate: Mon Oct 17 01:28:34 2022 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title>DF</title>
</head>
<body>
<h1 align="center">DF</h1>
<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#OPTIONS">OPTIONS</a><br>
<a href="#AUTHOR">AUTHOR</a><br>
<a href="#REPORTING BUGS">REPORTING BUGS</a><br>
<a href="#COPYRIGHT">COPYRIGHT</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>
<hr>
<h2>NAME
<a name="NAME"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">df &minus;
report file system space usage</p>
<h2>SYNOPSIS
<a name="SYNOPSIS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>df</b>
[<i>OPTION</i>]... [<i>FILE</i>]...</p>
<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">This manual
page documents the GNU version of <b>df</b>. <b>df</b>
displays the amount of space available on the file system
containing each file name argument. If no file name is
given, the space available on all currently mounted file
systems is shown. Space is shown in 1K blocks by default,
unless the environment variable POSIXLY_CORRECT is set, in
which case 512-byte blocks are used.</p>
<p style="margin-left:11%; margin-top: 1em">If an argument
is the absolute file name of a device node containing a
mounted file system, <b>df</b> shows the space available on
that file system rather than on the file system containing
the device node. This version of <b>df</b> cannot show the
space available on unmounted file systems, because on most
kinds of systems doing so requires very nonportable intimate
knowledge of file system structures.</p>
<h2>OPTIONS
<a name="OPTIONS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">Show
information about the file system on which each FILE
resides, or all file systems by default.</p>
<p style="margin-left:11%; margin-top: 1em">Mandatory
arguments to long options are mandatory for short options
too. <b><br>
&minus;a</b>, <b>&minus;&minus;all</b></p>
<p style="margin-left:22%;">include pseudo, duplicate,
inaccessible file systems</p>
<p style="margin-left:11%;"><b>&minus;B</b>,
<b>&minus;&minus;block&minus;size</b>=<i>SIZE</i></p>
<p style="margin-left:22%;">scale sizes by SIZE before
printing them; e.g., &rsquo;&minus;BM&rsquo; prints sizes in
units of 1,048,576 bytes; see SIZE format below</p>
<p style="margin-left:11%;"><b>&minus;h</b>,
<b>&minus;&minus;human&minus;readable</b></p>
<p style="margin-left:22%;">print sizes in powers of 1024
(e.g., 1023M)</p>
<p style="margin-left:11%;"><b>&minus;H</b>,
<b>&minus;&minus;si</b></p>
<p style="margin-left:22%;">print sizes in powers of 1000
(e.g., 1.1G)</p>
<p style="margin-left:11%;"><b>&minus;i</b>,
<b>&minus;&minus;inodes</b></p>
<p style="margin-left:22%;">list inode information instead
of block usage</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="3%">
<p><b>&minus;k</b></p></td>
<td width="8%"></td>
<td width="30%">
<p>like <b>&minus;&minus;block&minus;size</b>=<i>1K</i></p></td>
<td width="48%">
</td></tr>
</table>
<p style="margin-left:11%;"><b>&minus;l</b>,
<b>&minus;&minus;local</b></p>
<p style="margin-left:22%;">limit listing to local file
systems</p>
<p style="margin-left:11%;"><b>&minus;&minus;no&minus;sync</b></p>
<p style="margin-left:22%;">do not invoke sync before
getting usage info (default)</p>
<p style="margin-left:11%;"><b>&minus;&minus;output</b>[=<i>FIELD_LIST</i>]</p>
<p style="margin-left:22%;">use the output format defined
by FIELD_LIST, or print all fields if FIELD_LIST is
omitted.</p>
<p style="margin-left:11%;"><b>&minus;P</b>,
<b>&minus;&minus;portability</b></p>
<p style="margin-left:22%;">use the POSIX output format</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>&minus;&minus;sync</b></p></td>
<td width="2%"></td>
<td width="56%">
<p>invoke sync before getting usage info</p></td>
<td width="22%">
</td></tr>
</table>
<p style="margin-left:11%;"><b>&minus;&minus;total</b></p>
<p style="margin-left:22%;">elide all entries insignificant
to available space, and produce a grand total</p>
<p style="margin-left:11%;"><b>&minus;t</b>,
<b>&minus;&minus;type</b>=<i>TYPE</i></p>
<p style="margin-left:22%;">limit listing to file systems
of type TYPE</p>
<p style="margin-left:11%;"><b>&minus;T</b>,
<b>&minus;&minus;print&minus;type</b></p>
<p style="margin-left:22%;">print file system type</p>
<p style="margin-left:11%;"><b>&minus;x</b>,
<b>&minus;&minus;exclude&minus;type</b>=<i>TYPE</i></p>
<p style="margin-left:22%;">limit listing to file systems
not of type TYPE</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>&minus;v</b></p></td>
<td width="2%"></td>
<td width="40%">
<p>(ignored)</p></td>
<td width="38%">
</td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>&minus;&minus;help</b></p></td>
<td width="2%"></td>
<td width="40%">
<p>display this help and exit</p></td>
<td width="38%">
</td></tr>
</table>
<p style="margin-left:11%;"><b>&minus;&minus;version</b></p>
<p style="margin-left:22%;">output version information and
exit</p>
<p style="margin-left:11%; margin-top: 1em">Display values
are in units of the first available SIZE from
<b>&minus;&minus;block&minus;size</b>, and the
DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment
variables. Otherwise, units default to 1024 bytes (or 512 if
POSIXLY_CORRECT is set).</p>
<p style="margin-left:11%; margin-top: 1em">The SIZE
argument is an integer and optional unit (example: 10K is
10*1024). Units are K,M,G,T,P,E,Z,Y (powers of 1024) or
KB,MB,... (powers of 1000). Binary prefixes can be used,
too: KiB=K, MiB=M, and so on.</p>
<p style="margin-left:11%; margin-top: 1em">FIELD_LIST is a
comma&minus;separated list of columns to be included. Valid
field names are: &rsquo;source&rsquo;, &rsquo;fstype&rsquo;,
&rsquo;itotal&rsquo;, &rsquo;iused&rsquo;,
&rsquo;iavail&rsquo;, &rsquo;ipcent&rsquo;,
&rsquo;size&rsquo;, &rsquo;used&rsquo;, &rsquo;avail&rsquo;,
&rsquo;pcent&rsquo;, &rsquo;file&rsquo; and
&rsquo;target&rsquo; (see info page).</p>
<h2>AUTHOR
<a name="AUTHOR"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">Written by
Torbjorn Granlund, David MacKenzie, and Paul Eggert.</p>
<h2>REPORTING BUGS
<a name="REPORTING BUGS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">GNU coreutils
online help: &lt;https://www.gnu.org/software/coreutils/&gt;
<br>
Report any translation bugs to
&lt;https://translationproject.org/team/&gt;</p>
<h2>COPYRIGHT
<a name="COPYRIGHT"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">Copyright
&copy; 2022 Free Software Foundation, Inc. License GPLv3+:
GNU GPL version 3 or later
&lt;https://gnu.org/licenses/gpl.html&gt;. <br>
This is free software: you are free to change and
redistribute it. There is NO WARRANTY, to the extent
permitted by law.</p>
<h2>SEE ALSO
<a name="SEE ALSO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">Full
documentation
&lt;https://www.gnu.org/software/coreutils/df&gt; <br>
or available locally via: info '(coreutils) df
invocation'</p>
<hr>
</body>
</html>

0
workflow.txt Normal file
View file