Mercurial > hg > config
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 |
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 | 21 parser.add_argument('input') |
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 | 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 | 30 # get output name from input |
31 output_filename = os.path.splitext(os.path.basename(input))[0] + '.html' | |
32 output = os.path.join(os.path.dirname(input), output_filename) | |
33 | |
34 # build command line | |
35 options = [] | |
36 command = ['rst2s5.py'] | |
37 command.extend(options) | |
38 command.extend([input, output]) | |
39 print subprocess.list2cmdline(command) | |
40 | |
41 # call it | |
42 subprocess.call(command) | |
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() |