annotate python/s5ify.py @ 887:79eeb5390c8a

hgignore
author Jeff Hammel <k0scist@gmail.com>
date Sat, 24 Apr 2021 14:27:57 -0700
parents e047129c84bc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
761
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3 """
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 my front end to rst2st.py
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 """
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7 # imports
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 import argparse
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 import os
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10 import subprocess
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11 import sys
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13 def normalize_filename(filename):
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 return None # TODO
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 def main(args=sys.argv[1:]):
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 """CLI"""
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 # parse command line
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20 parser = argparse.ArgumentParser(description=__doc__)
762
Jeff Hammel <k0scist@gmail.com>
parents: 761
diff changeset
21 parser.add_argument('input')
Jeff Hammel <k0scist@gmail.com>
parents: 761
diff changeset
22 options = parser.parse_args(args)
761
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
23
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
24 # sanity
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
25 input = options.input
762
Jeff Hammel <k0scist@gmail.com>
parents: 761
diff changeset
26 if not os.path.isfile(input):
761
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27 parser.error("Not a file: '{}'".format(input))
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
28 input = os.path.abspath(options.input)
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
29
763
e047129c84bc ch ch ch changes
Jeff Hammel <k0scist@gmail.com>
parents: 762
diff changeset
30 # get output name from input
e047129c84bc ch ch ch changes
Jeff Hammel <k0scist@gmail.com>
parents: 762
diff changeset
31 output_filename = os.path.splitext(os.path.basename(input))[0] + '.html'
e047129c84bc ch ch ch changes
Jeff Hammel <k0scist@gmail.com>
parents: 762
diff changeset
32 output = os.path.join(os.path.dirname(input), output_filename)
e047129c84bc ch ch ch changes
Jeff Hammel <k0scist@gmail.com>
parents: 762
diff changeset
33
e047129c84bc ch ch ch changes
Jeff Hammel <k0scist@gmail.com>
parents: 762
diff changeset
34 # build command line
e047129c84bc ch ch ch changes
Jeff Hammel <k0scist@gmail.com>
parents: 762
diff changeset
35 options = []
e047129c84bc ch ch ch changes
Jeff Hammel <k0scist@gmail.com>
parents: 762
diff changeset
36 command = ['rst2s5.py']
e047129c84bc ch ch ch changes
Jeff Hammel <k0scist@gmail.com>
parents: 762
diff changeset
37 command.extend(options)
e047129c84bc ch ch ch changes
Jeff Hammel <k0scist@gmail.com>
parents: 762
diff changeset
38 command.extend([input, output])
e047129c84bc ch ch ch changes
Jeff Hammel <k0scist@gmail.com>
parents: 762
diff changeset
39 print subprocess.list2cmdline(command)
e047129c84bc ch ch ch changes
Jeff Hammel <k0scist@gmail.com>
parents: 762
diff changeset
40
e047129c84bc ch ch ch changes
Jeff Hammel <k0scist@gmail.com>
parents: 762
diff changeset
41 # call it
e047129c84bc ch ch ch changes
Jeff Hammel <k0scist@gmail.com>
parents: 762
diff changeset
42 subprocess.call(command)
e047129c84bc ch ch ch changes
Jeff Hammel <k0scist@gmail.com>
parents: 762
diff changeset
43
761
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
44 if __name__ == '__main__':
9e4a21ca48af add a front end to rst2s5; stub
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
45 main()