Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

#!/usr/local/bin/python 

# encoding: utf-8 

""" 

Documentation for rockAtlas can be found here: http://rockAtlas.readthedocs.org/en/stable 

 

Usage: 

rockAtlas init 

rockAtlas [-s <pathToSettingsFile>] 

 

Options: 

init setup the rockAtlas settings file for the first time 

-h, --help show this help message 

-v, --version show version 

-s, --settings the settings file 

""" 

################# GLOBAL IMPORTS #################### 

import sys 

import os 

os.environ['TERM'] = 'vt100' 

import readline 

import glob 

import pickle 

from docopt import docopt 

from fundamentals import tools, times 

from subprocess import Popen, PIPE, STDOUT 

# from ..__init__ import * 

 

 

def main(arguments=None): 

""" 

*The main function used when ``cl_utils.py`` is run as a single script from the cl, or when installed as a cl command* 

""" 

# setup the command-line util settings 

su = tools( 

arguments=arguments, 

docString=__doc__, 

logLevel="DEBUG", 

options_first=False, 

projectName="rockAtlas" 

) 

arguments, settings, log, dbConn = su.setup() 

 

# unpack remaining cl arguments using `exec` to setup the variable names 

# automatically 

for arg, val in arguments.iteritems(): 

if arg[0] == "-": 

varname = arg.replace("-", "") + "Flag" 

else: 

varname = arg.replace("<", "").replace(">", "") 

if varname == "import": 

varname = "iimport" 

if isinstance(val, str) or isinstance(val, unicode): 

exec(varname + " = '%s'" % (val,)) 

else: 

exec(varname + " = %s" % (val,)) 

if arg == "--dbConn": 

dbConn = val 

log.debug('%s = %s' % (varname, val,)) 

 

## START LOGGING ## 

startTime = times.get_now_sql_datetime() 

log.info( 

'--- STARTING TO RUN THE cl_utils.py AT %s' % 

(startTime,)) 

 

if init: 

from os.path import expanduser 

home = expanduser("~") 

filepath = home + "/.config/rockAtlas/rockAtlas.yaml" 

try: 

cmd = """open %(filepath)s""" % locals() 

p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True) 

except: 

pass 

try: 

cmd = """start %(filepath)s""" % locals() 

p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True) 

except: 

pass 

 

# CALL FUNCTIONS/OBJECTS 

 

if "dbConn" in locals() and dbConn: 

dbConn.commit() 

dbConn.close() 

## FINISH LOGGING ## 

endTime = times.get_now_sql_datetime() 

runningTime = times.calculate_time_difference(startTime, endTime) 

log.info('-- FINISHED ATTEMPT TO RUN THE cl_utils.py AT %s (RUNTIME: %s) --' % 

(endTime, runningTime, )) 

 

return 

 

 

if __name__ == '__main__': 

main()