Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmakePyLoT.py
More file actions
Latest commit
228 lines (189 loc) · 6.91 KB
/
Copy pathmakePyLoT.py
File metadata and controls
228 lines (189 loc) · 6.91 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/usr/bin/env python
# encoding: utf-8
from __future__ importprint_function
"""
makePyLoT -- build and install PyLoT
makePyLoT is a python make file in order to establish the folder structure and
meet requisites
It defines
:class CLIError:
:method main:
:author: Sebastian Wehling-Benatelli
:copyright: 2014 MAGS2 EP3 Working Group. All rights reserved.
:license: GNU Lesser General Public License, Version 3
(http://www.gnu.org/copyleft/lesser.html)
:contact: sebastian.wehling@rub.de
updated: Updated
"""
importglob
importos
importsys
importshutil
importcopy
fromargparseimportArgumentParser
fromargparseimportRawDescriptionHelpFormatter
__all__= []
__version__=0.1
__date__='2014-11-26'
__updated__='2016-04-28'
DEBUG=0
TESTRUN=0
PROFILE=0
classCLIError(Exception):
"""Generic exception to raise and log different fatal errors."""
def__init__(self, msg):
super(CLIError).__init__(type(self))
self.msg="E: %s"%msg
def__str__(self):
returnself.msg
def__unicode__(self):
returnself.msg
defmain(argv=None): # IGNORE:C0111
'''Command line options.'''
ifargvisNone:
argv=sys.argv
else:
sys.argv.extend(argv)
program_name=os.path.basename(sys.argv[0])
program_version="v%s"%__version__
program_build_date=str(__updated__)
program_version_message='makePyLoT %s (%s)'% (
program_version, program_build_date)
program_shortdesc=__import__('__main__').__doc__.split("\n")[1]
program_license='''{0:s}
Created by Sebastian Wehling-Benatelli on {1:s}.
Copyright 2014 MAGS2 EP3 Working Group. All rights reserved.
GNU Lesser General Public License, Version 3
(http://www.gnu.org/copyleft/lesser.html)
Distributed on an "AS IS" basis without warranties
or conditions of any kind, either express or implied.
USAGE
'''.format(program_shortdesc, str(__date__))
try:
# Setup argument parser
parser=ArgumentParser(description=program_license,
formatter_class=RawDescriptionHelpFormatter)
parser.add_argument("-b", "--build", dest="build", action="store_true",
help="build PyLoT")
parser.add_argument("-v", "--verbose", dest="verbose", action="count",
help="set verbosity level")
parser.add_argument("-i", "--install", dest="install",
action="store_true",
help="install PyLoT on the system")
parser.add_argument("-d", "--directory", dest="directory",
help="installation directory", metavar="RE")
parser.add_argument('-V', '--version', action='version',
version=program_version_message)
# Process arguments
args=parser.parse_args()
verbose=args.verbose
build=args.build
install=args.install
directory=args.directory
ifverbose>0:
print("Verbose mode on")
ifinstallandnotdirectory:
raiseCLIError("""Trying to install without appropriate
destination; please specify an installation
directory!""")
ifbuildandinstall:
print("Building and installing PyLoT ...\n")
buildPyLoT(verbose)
installPyLoT(verbose)
elifbuildandnotinstall:
print("Building PyLoT without installing! Please wait ...\n")
buildPyLoT(verbose)
cleanUp()
return0
exceptKeyboardInterrupt:
cleanUp(1)
return0
exceptExceptionase:
ifDEBUGorTESTRUN:
raisee
indent=len(program_name) *" "
sys.stderr.write(program_name+": "+repr(e) +"\n")
sys.stderr.write(indent+" for help use --help")
return2
defbuildPyLoT(verbosity=None):
system=sys.platform
ifverbosity>1:
msg= ("... on system: {0}\n"
"\n"
" Current working directory: {1}\n"
).format(system, os.getcwd())
print(msg)
ifsystem.startswith(('win', 'microsoft')):
raiseCLIError(
"building on Windows system not tested yet; implementation pending")
elifsystem=='darwin':
# create a symbolic link to the desired python interpreter in order to
# display the right application name
forpathinos.getenv('PATH').split(':'):
found=glob.glob(os.path.join(path, 'python'))
iffound:
os.symlink(found, './PyLoT')
break
definstallPyLoT(verbosity=None):
files_to_copy= {'pylot_local.in': ['~', '.pylot'],
'pylot_regional.in': ['~', '.pylot'],
'pylot_global.in': ['~', '.pylot']}
ifverbosity>0:
print('starting installation of PyLoT ...')
ifverbosity>1:
print('copying input files into destination folder ...')
ans=input('please specify scope of interest '
'([0]=local, 1=regional, 2=global, 3=active) :') or0
ifnotisinstance(ans, int):
ans=int(ans)
ifans==0:
ans='local'
elifans==1:
ans='regional'
elifans==2:
ans='global'
elifans==3:
ans='active'
link_dest= []
forfile, destinationinfiles_to_copy.items():
link_file=ansinfile
iflink_file:
link_dest=copy.deepcopy(destination)
link_dest.append('pylot.in')
link_dest=os.path.join(*link_dest)
destination.append(file)
destination=os.path.join(*destination)
srcfile=os.path.join('input', file)
assertnotos.path.isabs(srcfile), 'source files seem to be ' \
'corrupted ...'
ifverbosity>1:
print('copying file {file} to folder {dest}'.format(file=file, dest=destination))
shutil.copyfile(srcfile, destination)
iflink_file:
ifverbosity:
print('linking input file for autoPyLoT ...')
os.symlink(destination, link_dest)
defcleanUp(verbosity=None):
ifverbosity>=1:
print('cleaning up build files...')
ifsys.platform=='darwin':
os.remove('./PyLoT')
if__name__=="__main__":
ifDEBUG:
sys.argv.append("-h")
sys.argv.append("-v")
ifTESTRUN:
importdoctest
doctest.testmod()
ifPROFILE:
importcProfile
importpstats
profile_filename='makePyLoT_profile.txt'
cProfile.run('main()', profile_filename)
statsfile=open("profile_stats.txt", "wb")
p=pstats.Stats(profile_filename, stream=statsfile)
stats=p.strip_dirs().sort_stats('cumulative')
stats.print_stats()
statsfile.close()
sys.exit(0)
sys.exit(main())