aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <elena.valhalla@gmail.com>2011-04-18 08:34:42 +0200
committerElena ``of Valhalla'' Grandi <elena.valhalla@gmail.com>2011-04-18 08:34:42 +0200
commita5760cc47b5bc40c8e83a44a8d32840bc02e13ce (patch)
treef552f2a9c5acf06a2edbac0f1b9d564cb063c687
parentd2d5e08930d9cac2409582f440b4c6d09d5362c5 (diff)
make_guides.py: Riconoscimento opzioni e scheletri di funzioni.
-rwxr-xr-xmake_guides.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/make_guides.py b/make_guides.py
index 066c83e..40c2c3b 100755
--- a/make_guides.py
+++ b/make_guides.py
@@ -1,3 +1,79 @@
#!/usr/bin/env python3
+import argparse, os
+#import docutils
+def basename(fname):
+ '''Returns the name of the guide from either its name or its directory'''
+ if os.path.isdir(os.path.join('guides',fname)):
+ return fname
+ elif os.path.isdir(fname):
+ return os.path.basename(os.path.abspath(fname))
+ else:
+ msg = '%s is not a valid directory' % fname
+ raise argparse.ArgumentTypeError(msg)
+
+def build_latex(guide):
+ '''Builds the LaTeX source for the guide'''
+ build_dir = os.path.join('build',guide)
+ tex_name = guide+'.tex'
+ # DEBUG
+ print('Building LaTeX...')
+ if not os.path.isdir(build_dir):
+ os.mkdir(build_dir)
+ fp = open(os.path.join(build_dir,tex_name),'w')
+ fp.close()
+
+def build_pdf(guide):
+ '''Builds the A6 PDF for the guide'''
+ build_dir = os.path.join('build',guide)
+ dist_dir = os.path.join('dist','PDF')
+ tex_name = guide+'.tex'
+ pdf_name = guide+'.pdf'
+ # check for prerequisites
+ if not os.path.isfile(os.path.join(build_dir,tex_name)):
+ build_latex(guide)
+ # DEBUG
+ print('Building PDF...')
+ if not os.path.isdir(dist_dir):
+ os.mkdir(dist_dir)
+ fp = open(os.path.join(dist_dir,pdf_name),'w')
+ fp.close()
+
+def build_nup_pdf(guide):
+ '''Builds the nup-ed PDF for the guide'''
+ dist_dir = os.path.join('dist','PDF')
+ pdf_name = guide+'.pdf'
+ nup_name = guide+'-A6suA4.pdf'
+ # check for prerequisites
+ if not os.path.isfile(os.path.join(dist_dir,pdf_name)):
+ build_pdf(guide)
+ # DEBUG
+ print('Building nup PDF...')
+ if not os.path.isdir(dist_dir):
+ os.mkdir(dist_dir)
+ fp = open(os.path.join(dist_dir,nup_name),'w')
+ fp.close()
+
+def main():
+ parser = argparse.ArgumentParser(description='Build a distribution format of a 1800 words article')
+ parser.add_argument('guide', nargs='+', type=basename,
+ help='Source directory of the article')
+ parser.add_argument('-l','--latex',action='store_true',
+ help='Generate LaTeX source')
+ parser.add_argument('-p','--pdf',action='store_true',
+ help='Generate PDF')
+ parser.add_argument('-n','--nup-pdf',action='store_true',
+ help='Generate nup-ed A4 PDF')
+ args = parser.parse_args()
+
+ for guide in args.guide:
+ if args.latex:
+ build_latex(guide)
+ if args.pdf:
+ build_pdf(guide)
+ if args.nup_pdf:
+ build_nup_pdf(guide)
+
+
+if __name__ == '__main__': main()