Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 39561
1
#!/usr/bin/python
2
3
import os, platform, shutil, sys
4
5
PLATFORM = platform.system().lower()
6
7
def new_file(path):
8
if os.path.exists(path):
9
# nothing to do.
10
return
11
12
base, filename = os.path.split(path)
13
14
if base and not os.path.exists(base):
15
os.makedirs(base)
16
17
ext = os.path.splitext(path)[1].lower()
18
for places in [os.environ['HOME'], os.path.dirname(os.path.realpath(__file__))]:
19
template = os.path.join(places, 'templates', PLATFORM, 'default' + ext)
20
if os.path.exists(template):
21
shutil.copyfile(template, path)
22
return
23
24
# No template found
25
open(path,'w').close()
26
27
def main():
28
if len(sys.argv) == 1:
29
print """
30
This script is called like so:
31
32
%s path/to/file.tex another/path/to/a/file.tex ....
33
34
If path/to/file.tex already exists, nothing happens.
35
If path/to/file.tex does not exist, it is created (including the directory that contains it),
36
and if there is a file $HOME/templates/default.tex or /projects/templates/[platform]/default.tex (for tex extension),
37
then that template file is set to the initial contents. """%(sys.argv[0])
38
sys.exit(1)
39
40
41
for x in sys.argv[1:]:
42
new_file(x)
43
44
if __name__ == "__main__":
45
main()
46
47
48
49
50