forked from Normation/ncf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathncf
executable file
·62 lines (45 loc) · 1.56 KB
/
ncf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
# This will become the main command line tool for ncf
import os
import sys
import shutil
DEFAULT_NCF_DIR = '/usr/share/ncf'
NCF_DIR = os.path.dirname(os.path.realpath(__file__))
NCF_TREE_DIR = os.path.join(NCF_DIR, 'tree')
NCF_TOOLS_DIR = os.path.join(NCF_DIR, 'tools')
sys.path[0:0] = [NCF_TOOLS_DIR, DEFAULT_NCF_DIR]
import ncf
def usage():
print "ncf init [path]"
def get_ncf_dir():
# Try the directory this script is run from first (in case of a git clone)
# Otherwise use the system default path
target_dirs = [ NCF_TREE_DIR, os.path.join(DEFAULT_NCF_DIR, 'tree') ]
for dir in target_dirs:
if os.path.isdir(dir):
return dir
# If none found, return None
return None
def init(args):
# First argument is dir name, unless not specified then we use current dir
if len(args) == 0:
init_dir = os.getcwd()
print "INFO: No path specified, using current directory"
else:
init_dir = args[0]
print "INFO: Initialising in " + init_dir
# Check if this directory is already a ncf instance
if os.path.isdir(init_dir) and set(ncf.dirs).intersection(set(os.listdir(init_dir))):
print "ERROR: It looks like this directory is already initialized. Aborting"
exit(2)
for component_dir in ncf.dirs:
target_dir = os.path.join(init_dir, component_dir)
os.makedirs(target_dir)
shutil.copy(os.path.join(get_ncf_dir(), component_dir, "README.md"), target_dir)
print "INFO: Success"
if __name__ == '__main__':
if len(sys.argv) <= 1:
usage()
exit(1)
if sys.argv[1] == "init":
init(sys.argv[2:])