-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathpacclient.py
More file actions
executable file
·1375 lines (1251 loc) · 38.7 KB
/
pacclient.py
File metadata and controls
executable file
·1375 lines (1251 loc) · 38.7 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
import sys
import os
import getopt
import httplib2
from xml.etree import ElementTree as ET
from xml.dom import minidom
from configparser import ConfigParser
from configparser import NoSectionError
import getpass
import socket
import re
import urllib.parse
import calendar
from datetime import timedelta, datetime
import csv
from pac_api import *
import logging
def logon_usage():
print ( (_getmsg("logon_usage") + "\n") )
def main_logon(argv):
url=''
user=''
password=''
try:
opts, args = getopt.getopt(argv, "hl:u:p:", ['help','url=','user=','pass='])
except getopt.GetoptError:
logon_usage()
return
for opt, arg in opts:
if ((opt == "-h") | (opt == "--help")) :
logon_usage()
return
elif ((opt == '-l') | (opt == "--url")) :
url = arg
elif ((opt == '-u') | (opt == "--user")) :
user = arg
elif ((opt == '-p') | (opt == "--pass")) :
password = arg
if len(url) == 0:
url=input( _getmsg("logon_url_prompt") )
url,context = parseUrl(url);
p = re.compile('^(http|https)://[\w\W]+:\d+[/]{0,1}$')
if (len(url) == 0) | (p.match(url.lower()) == None):
print ( _getmsg("logon_null_url") )
return
url = url + context
url = removeQuote(url)
x509Flag, key, cert = checkX509PEMCert(url)
if (x509Flag == False) | ( len(user) > 0) | (len(password) > 0):
if len(user) == 0:
user=input( _getmsg("logon_username") )
if len(user) == 0:
print ( _getmsg("logon_specify_username") )
return
if len(password) == 0:
password=getpass.getpass()
if len(password) == 0:
print ( _getmsg("logon_specify_password") )
return
if ( (len(url) != 0) & ('https' in url.lower()) ):
if ( ( os.path.isfile('cacert.pem') == False ) & (httplib2.__version__ >= '0.7.0') ):
print ( _getmsg("https_certificate_missing") )
return
# In xml, & should be written as & Or it will generate exception when CFX parses
password = password.replace("&", "&")
# < === <
password = password.replace("<", "<")
# > === >
password = password.replace(">", ">")
# remove the quote
password = removeQuote(password)
user = removeQuote(user)
# Log on action
logon(url, user, password)
def submit_usage():
print ( (_getmsg("submit_usage") + "\n") )
def main_submit(argv):
if len(argv) == 0:
submit_usage()
return
appName=''
profile=''
params=''
slash = getFileSeparator()
try:
opts, args = getopt.getopt(argv, "ha:c:p:", ['help','app=','conf=', 'param='])
except getopt.GetoptError:
submit_usage()
return
for opt, arg in opts:
if ((opt == "-h") | (opt == "--help")) :
submit_usage()
return
elif ((opt == '-a') | (opt == "--app")) :
appName = arg
elif ((opt == '-c') | (opt == "--conf")) :
profile = arg
elif ((opt == '-p') | (opt == "--param")) :
params = arg
if len(appName) <= 0:
print ( _getmsg("submit_arg_missing") )
return
inputParams={}
inputFiles={}
if len(profile) > 0:
profile = removeQuote(profile)
if (":" not in profile) & ( slash != profile[0]):
dir = os.getcwd() + slash
profile = dir + profile
if os.path.isfile(profile) is False:
print ( _getmsg("submit_file_notexist") % profile )
return
config = ConfigParser()
config.optionxform = str #make option name case-sensitive
try:
config.read(profile)
except IOError:
print ( _getmsg("submit_cannot_openfile") % profile )
return
try:
for option in config.options('Parameter'):
inputParams[option]=config.get('Parameter', option)
except NoSectionError:
print ( _getmsg("submit_param_missing") % profile )
return
try:
for option in config.options('Inputfile'):
inputFiles[option]=config.get('Inputfile', option)
except NoSectionError:
print ( _getmsg("submit_inputfile_missing") % profile )
return
if len(params) > 0:
for pp in params.split(';'):
if len(pp) > 0:
nv = pp.split('=',1)
if len(nv) > 1:
if ',' in nv[1]:
inputFiles[nv[0]] = nv[1]
else:
inputParams[nv[0]] = nv[1]
else:
print ( _getmsg("submit_input_invalid") )
return
JobDict={}
JobDict[APP_NAME]=appName
try:
span = inputParams['SPAN']
inputParams['SPAN'] = "span[%s]" % span
except KeyError:
pass
JobDict['PARAMS']=inputParams
JobDict['INPUT_FILES']=inputFiles
status, message = submitJob(JobDict)
if status == 'ok':
print ( _getmsg("submit_success").format(message) )
else:
print ( message)
def job_usage():
print ( (_getmsg("job_usage") + "\n\n") )
def main_job(argv):
jobStatus=''
jobName=''
jobId=''
long=''
group=''
user=''
past=''
try:
opts, args = getopt.getopt(argv, "hu:ls:n:g:p:", ['help','user=','long','status=','name=','group=','past='])
except getopt.GetoptError:
job_usage()
return
for opt, arg in opts:
if ((opt == "-h") | (opt == "--help")) :
job_usage()
return
elif ((opt=='-u') | (opt == '--user')) :
user=arg
elif ((opt=='-l') | (opt == '--long')) :
long='yes'
elif ((opt == '-s') | (opt == "--status")) :
jobStatus = arg
elif ((opt == '-n') | (opt == "--name")) :
jobName = urllib.parse.quote(arg)
elif ((opt == '-g') | (opt == "--group")) :
group=urllib.parse.quote(arg)
elif ((opt == '-p') | (opt == '--past')) :
past=arg
if len(args) > 0:
jobId = args[0]
p = re.compile('^[1-9]{1}[0-9]{0,}$')
pl = re.compile('^[1-9]{1}[0-9]{0,}\[{1}[0-9]{0,}\]{1}$')
if (len(jobId) == 0) | ((p.match(jobId.lower()) == None) and (pl.match(jobId.lower()) == None)) | (len(args)>1):
job_usage()
return
if (len(jobStatus) > 0 and len(jobName) > 0) | (len(jobStatus) > 0 and len(jobId) > 0) | (len(jobId) > 0 and len(jobName) > 0) | (len(jobId)>0 and len(group)>0) | (len(jobName)>0 and len(group)>0) | (len(jobStatus)>0 and len(group)>0):
print ( _getmsg("job_usage_error") )
return
status = ''
message = ''
statusFlag = False
nameFlag = False
groupFlag=False
if len(jobStatus) > 0:
status, message = getJobListInfo('status='+jobStatus+'&user='+user+'&details='+long+'&past='+past)
statusFlag = True
elif len(jobName) > 0:
status, message = getJobListInfo('name='+jobName+'&user='+user+'&details='+long+'&past='+past)
nameFlag = True
elif len(group) > 0:
status, message = getJobListInfo('group='+group+'&user='+user+'&details='+long+'&past='+past)
groupFlag=True
if status != '':
if status == 'ok':
tree = ET.fromstring(message)
jobs =tree.iter("Job")
count = len(tree.findall('Job'))
if count == 0:
if statusFlag == True:
print ( _getmsg("job_nomatch_status").format(jobStatus) )
elif nameFlag == True:
print ( _getmsg("job_nomatch_name").format(jobName) )
elif groupFlag== True:
print ( _getmsg("job_nomatch_group").format(group) )
return
showJobinfo(jobs,long, count)
else:
print(message)
return
if len(jobId) > 0:
status, message= getJobListInfo('id='+jobId+'&user='+user+'&details='+long+'&past='+past)
if status == 'ok':
tree = ET.fromstring(message)
jobs =tree.iter("Job")
count = len(tree.findall('Job'))
showJobinfo(jobs,long, count)
else:
print(message)
return
else:
status, message= getJobListInfo('user='+user+'&details='+long+'&past='+past)
if status == 'ok':
tree = ET.fromstring(message)
jobs =tree.iter("Job")
count = len(tree.findall('Job'))
showJobinfo(jobs,long, count)
else:
print(message)
return
job_usage()
def showJobinfo(jobs,long,count):
if long == '':
print ( _getmsg("job_info_title") )
for xdoc in jobs:
jobId=xdoc.find('id').text
status=xdoc.find('status')
extStatus=xdoc.find('extStatus')
name=xdoc.find('name').text
cmd=xdoc.find('cmd')
print('%-10s%-10s%-23s%-25s%s' % (jobId, checkFieldValidity(status), SubStr(checkFieldValidity(extStatus)), SubStr(name),checkFieldValidity(cmd)))
else:
for xdoc in jobs:
jobId=xdoc.find('id').text
name=xdoc.find('name').text
user=xdoc.find('user')
jobType=xdoc.find('jobType')
status=xdoc.find('status')
appType=xdoc.find('appType')
submitTime=xdoc.find('submitTime')
endTime=xdoc.find('endTime')
startTime=xdoc.find('startTime')
estimatedStartTime=xdoc.find('estimatedStartTime')
if estimatedStartTime != None:
if estimatedStartTime.text != '-' :
startTime.text = startTime.text + " (Estimated)"
queue=xdoc.find('queue')
cmd=xdoc.find('cmd')
projectName=xdoc.find('projectName')
pendReason=xdoc.find('pendReason')
description=xdoc.find('description')
extStatus=xdoc.find('extStatus')
priority=xdoc.find('priority')
exitCode=xdoc.find('exitCode')
swap=xdoc.find('swap')
pgid=xdoc.find('pgid')
pid=xdoc.find('pid')
nthreads=xdoc.find('nthreads')
numProcessors=xdoc.find('numProcessors')
fromHost=xdoc.find('fromHost')
exHosts=xdoc.find('exHosts')
askedHosts=xdoc.find('askedHosts')
runTime=xdoc.find('runTime')
mem=xdoc.find('mem')
timeRemaining=xdoc.find('timeRemaining')
estimateRunTime=xdoc.find('estimateRunTime')
infile=xdoc.find('infile')
outfile=xdoc.find('outfile')
execCwd=xdoc.find('execCwd')
graphicJob=xdoc.find('graphicJob')
cwd=xdoc.find('cwd')
timeRemaining=xdoc.find('timeRemaining')
app=xdoc.find('app')
jobForwarding=xdoc.find('jobForwarding')
localClusterName=xdoc.find('localClusterName')
localJobId=xdoc.find('localJobId')
remoteJobId=xdoc.find('remoteJobId')
remoteClusterName=xdoc.find('remoteClusterName')
# Add slots number: 123295
slotsNum = xdoc.find('slotsNum')
cpuEfficiency = xdoc.find('cpuEfficiency')
# Add group name
groupName = xdoc.find('groupName')
# Add container
container = xdoc.find('container')
print ( _getmsg("job_info_id") % jobId )
print ( _getmsg("job_info_name") % name )
print ( _getmsg("job_info_type") % checkFieldValidity(jobType) )
print ( _getmsg("job_info_status") % checkFieldValidity(status) )
print ( _getmsg("job_info_apptype") % checkFieldValidity(appType) )
print ( _getmsg("job_info_submittime") % checkFieldValidity(submitTime) )
print ( _getmsg("job_info_user") % checkFieldValidity(user) )
print ( _getmsg("job_info_endtime") % checkFieldValidity(endTime) )
print ( _getmsg("job_info_starttime") % checkFieldValidity(startTime) )
print ( _getmsg("job_info_queue") % checkFieldValidity(queue) )
print ( _getmsg("job_info_cmd") % checkFieldValidity(cmd) )
print ( _getmsg("job_info_projname") % checkFieldValidity(projectName) )
print ( _getmsg("job_info_pending_reason") % checkFieldValidity(pendReason) )
print ( _getmsg("job_info_desc") % checkFieldValidity(description) )
print ( _getmsg("job_info_exstatus") % checkFieldValidity(extStatus) )
print ( _getmsg("job_info_priority") % checkFieldValidity(priority) )
print ( _getmsg("job_info_exitcode") % checkFieldValidity(exitCode) )
print ( _getmsg("job_info_mem") % checkFieldValidity(mem) )
print ( _getmsg("job_info_swap") % checkFieldValidity(swap) )
print ( _getmsg("job_info_container") % checkFieldValidity(container) )
print ( _getmsg("job_info_gid") % checkFieldValidity(pgid) )
print ( _getmsg("job_info_pid") % checkFieldValidity(pid) )
print ( _getmsg("job_info_numthread") % checkFieldValidity(nthreads) )
print ( _getmsg("job_info_reqprocessors") % checkFieldValidity(numProcessors) )
print ( _getmsg("job_info_submithost") % checkFieldValidity(fromHost) )
print ( _getmsg("job_info_exeutionhost") % checkFieldValidity(exHosts) )
print ( _getmsg("job_info_reqhost") % checkFieldValidity(askedHosts) )
print ( _getmsg("job_info_runtime") % checkFieldValidity(runTime) )
print ( _getmsg("job_info_cpuefficiency") % checkFieldValidity(cpuEfficiency) )
print ( _getmsg("job_info_timeremain") % checkFieldValidity(timeRemaining) )
print ( _getmsg("job_info_est_runtime") % checkFieldValidity(estimateRunTime) )
print ( _getmsg("job_info_inputfile") % checkFieldValidity(infile) )
print ( _getmsg("job_info_outfile") % checkFieldValidity(outfile) )
print ( _getmsg("job_info_exe_cwd") % checkFieldValidity(execCwd) )
print ( _getmsg("job_info_gjob") % checkFieldValidity(graphicJob) )
print ( _getmsg("job_info_curdir") % checkFieldValidity(cwd) )
print ( _getmsg("job_info_app_profile") % checkFieldValidity(app) )
print ( _getmsg("job_info_localid") % checkFieldValidity(localJobId) )
print ( _getmsg("job_info_localcluster") % checkFieldValidity(localClusterName) )
print ( _getmsg("job_info_fwd") % checkFieldValidity(jobForwarding) )
# Add slots number: 123295
print ( _getmsg("job_info_slotsnum") % checkFieldValidity(slotsNum) )
# Add group name
print ( _getmsg("job_info_groupname") % checkFieldValidity(groupName) )
if checkFieldValidity(jobForwarding) != 'None':
print ( _getmsg("job_info_remoteid") % checkFieldValidity(remoteJobId) )
print ( _getmsg("job_info_remotecluster") % checkFieldValidity(remoteClusterName) )
if count > 1:
print(' ')
print(' ')
def SubStr(field, size=None):
if size is None:
size = 10
if len(field) > size :
field = '*' + field[-(size-1):]
return field
def checkFieldValidity(field):
if field != None:
if field.text == None :
field = ''
else:
field = field.text
else:
field='-'
return field
def download_usage():
print ( (_getmsg("download_usage") + "\n\n") )
def main_download(argv):
if len(argv) == 0:
download_usage()
return
dir=''
file = ''
jobId=''
cmd=''
# Total size of uploaded files
totalSize = 0
try:
opts, args = getopt.getopt(argv, "hd:f:c:", ['help','dir=','file=','cmd='])
except getopt.GetoptError:
download_usage()
return
for opt, arg in opts:
if ((opt == "-h") | (opt == "--help")) :
download_usage()
return
elif ((opt == '-d') | (opt == "--dir")) :
dir = arg
elif ((opt == '-f') | (opt == '--file')) :
file = arg
elif ((opt == '-c') | (opt == '--cmd')) :
cmd = arg
if dir == '' and cmd == '' and file == '' and len(args) <=0:
download_usage()
return
if len(args) <= 0:
print ( _getmsg("download_specify_id") )
return
if len(dir) <=0:
dir = os.getcwd()
jobId = args[0]
if os.path.exists(dir) == False :
print ( _getmsg("download_dirnotexist") % dir )
return
dir = removeQuote(dir)
file = removeQuote(file)
downloadJobFiles(jobId, dir, file, cmd)
def upload_usage():
print ( (_getmsg("upload_usage") + "\n") )
def main_upload(argv):
if len(argv) == 0:
upload_usage()
return
dir=''
file = ''
jobId=''
# Total size of uploaded files
totalSize = 0
try:
opts, args = getopt.getopt(argv, "hd:f:")
except getopt.GetoptError:
upload_usage()
return
for opt, arg in opts:
if ((opt == "-h")) :
upload_usage()
return
elif ((opt == '-d')) :
dir = arg
elif ((opt == '-f')) :
file = arg
dir = removeQuote(dir)
file = removeQuote(file)
if file == '':
print ( _getmsg("submit_file_notexist") )
return
p = re.compile('^[\w\W]+:/[\w\W]+')
# Windows regular express compiler
winp = re.compile('^[\w\W]+:[a-zA-Z]:[/\\\\]+')
if (((dir == '') | ((len(dir) > 0) and (('/' != dir[0]) and (p.match(dir.lower()) == None) and ( winp.match(dir.lower()) == None) ))) and (len(args) <= 0)):
print ( _getmsg("upload_specify_jobid") )
return
if ((':' in dir) and (p.match(dir.lower()) == None) and ( winp.match(dir.lower()) == None)):
print ( _getmsg("upload_specify_absolutepath") )
return
cwd = os.getcwd()
files = file.split(',')
paths = ''
p = re.compile('^[a-zA-Z]:[/\\][\w\W]+')
slash = getFileSeparator()
valid = True
for f in files:
f.strip()
if len(f) > 0:
if ((slash != f[0]) and (p.match(f.lower()) == None)):
f = cwd + slash + f
if not os.path.isfile(f):
valid = False
print ( _getmsg("upload_file_notfound") % f )
elif os.access(f, os.R_OK) == 0:
valid = False
print ( _getmsg("upload_fileread_denied") % f )
else:
# Get all files total size
totalSize += os.path.getsize(f)
paths = paths + f + ','
if not valid:
return
elif len(paths)<=0:
print ( _getmsg("upload_file_notfound") % file )
return
else:
paths = paths[:-1]
p = re.compile('^[\w\W]+:/[\w\W]+')
if ((len(dir) > 0) and (('/' == dir[0]) | (p.match(dir.lower()) != None) | (winp.match(dir.lower()) != None))):
jobId = '0'
else:
jobId = args[0]
p = re.compile('^[1-9]{1}[0-9]{0,}$')
if p.match(jobId.lower()) == None:
print ( _getmsg("upload_jobid_invalid") )
return
# If total file size is greater than 500Mb, upload them separately by WS API.
if (totalSize > 536870912):
# If one file size is greater than 500Mb, split it into chunks and every chunk max size is 500Mb
files = paths.split(',')
for f in files:
if os.path.getsize(f) > 536870912:
# Upload larger file
uploadLargeFile(jobId, dir, f)
else:
# Upload normal file
uploadJobFiles(jobId, dir, f)
else:
uploadJobFiles(jobId, dir, paths)
def jobaction_usage():
print ( (_getmsg("jobaction_usage") + "\n") )
def main_jobaction(argv):
jobAction=''
jobId=''
try:
opts, args = getopt.getopt(argv, "ha:", ['help','action='])
except getopt.GetoptError:
jobaction_usage()
return
for opt, arg in opts:
if ((opt == "-h") | (opt == "--help")) :
jobaction_usage()
return
elif ((opt == '-a') | (opt == "--action")) :
jobAction = arg
if len(args) <= 0 and len(jobAction) <= 0:
jobaction_usage()
return
if len(args) <= 0:
print ( _getmsg("jobaction_specify_jobid") )
return
if len(args) >0 :
jobId = args[0]
p = re.compile('^[1-9]{1}[0-9]{0,}$')
pl = re.compile('^[1-9]{1}[0-9]{0,}\[{1}[0-9]{0,}\]{1}$')
if (p.match(jobId.lower()) == None) and (pl.match(jobId.lower()) == None):
jobaction_usage()
return
jobId=args[0]
status, message = doJobAction(jobAction, jobId)
print(message)
def flowdef_usage():
print ( (_getmsg("flowdef_usage") + "\n") )
def main_flowDef(argv):
flowName=''
userName=''
published=False
status=''
try:
opts, args = getopt.getopt(argv, "hn:u:ps:", ['help','name=','username=','published','status='])
except getopt.GetoptError:
flowdef_usage()
return
for opt, arg in opts:
if ((opt == "-h") | (opt == "--help")) :
flowdef_usage()
return
elif ((opt == '-n') | (opt == "--name")) :
flowName = arg
elif ((opt == '-u') | (opt == "--username") | (opt == "--user_name")) :
userName = arg
elif ((opt == '-p') | (opt == "--published")) :
published = True
elif ((opt == '-s') | (opt == "--status")) :
status = arg
if len(args) > 0 :
flowdef_usage()
return
status, message = getflowDef(flowName, userName, published, status)
if status == 'ok':
tree = ET.fromstring(message)
flowdefs =tree.iter("pseudoFlowDefinition")
showFlowdefInfo(flowdefs)
else:
print(message)
def showFlowdefInfo(flowdefs):
print ( _getmsg("flowdef_info_title") )
for xdoc in flowdefs:
name = xdoc.find('name').text
user = xdoc.find('user').text
status = xdoc.find('status').text
published = xdoc.find('published').text
version = xdoc.find('version').text
print('%-31s%-16s%-10s%-11s%s' % (SubStr(name, 31-1), SubStr(user, 16-1), status, published, version))
def flowdefaction_usage():
print ( (_getmsg("flowdefaction_usage") + "\n") )
def main_flowDefaction(argv):
flowAction=''
flowName=''
flowPath=''
variables=''
comment=''
version=''
forceFlag=False
useF=False
useV=False
useC=False
try:
opts, args = getopt.getopt(argv, "hfa:v:c:", ['help','force','action=','variables=','comment='])
except getopt.GetoptError:
flowdefaction_usage()
return
for opt, arg in opts:
if ((opt == "-h") | (opt == "--help")) :
flowdefaction_usage()
return
elif ((opt=='-f') | (opt == '--force')) :
forceFlag=True
useF=True
elif ((opt=='-a') | (opt == '--action')) :
flowAction=arg
elif ((opt == '-v') | (opt == "--variables") | (opt == "--version")) :
variables=arg
version=arg
useV=True
elif ((opt == '-c') | (opt == '--comment')) :
comment=arg
useC=True
if len(args) <= 0 and len(flowAction) <= 0:
flowdefaction_usage()
return
if ( (flowAction != "commit") and (flowAction != 'submit') and (flowAction != 'release') and
(flowAction != 'publish') and (flowAction != 'unpublish') and (flowAction != 'hold') and
(flowAction != 'delete')):
print ( _getmsg("flowdefaction_unsupported") )
return
if flowAction != 'delete' and useF==True:
flowdefaction_usage()
return
if flowAction != 'commit' and useC==True:
flowdefaction_usage()
return
if flowAction != 'commit' and flowAction != 'submit' and useV==True:
flowdefaction_usage()
return
if len(args) <= 0:
if flowAction == 'commit':
print ( _getmsg("flowdefaction_specify_filepath") )
return
else:
print ( _getmsg("flowdefaction_specify_flowname") )
return
if flowAction == 'commit':
flowPath = args[0]
else:
flowName = args[0]
status, message = doflowDefAction(flowAction, flowName, flowPath, variables, comment, forceFlag,version)
print(message)
def usercmd_usage():
print ( (_getmsg("usercmd_usage") + "\n") )
def main_usercmd(argv):
userCmd=''
for i in range(0, len(argv)):
if ((argv[i] == '-h')):
usercmd_usage()
return
elif (((argv[i] == '-c')) & (i+1 < len(argv))):
userCmd = removeQuote(argv[i+1]).strip()
if len(userCmd) <= 0:
usercmd_usage()
return
for arg in argv[i+2:]:
temp = removeQuote(arg).strip()
if len(temp) > 0:
userCmd = userCmd + ' "' + temp + '"'
break
else:
usercmd_usage()
return
if len(userCmd) <= 0:
usercmd_usage()
return
status, message = doUserCmd(userCmd)
print(message)
def ping_usage():
print ( (_getmsg("ping_usage") + "\n") )
def main_ping(argv):
url = ''
try:
opts, args = getopt.getopt(argv, "hl:", ['help','url='])
except getopt.GetoptError:
ping_usage()
return
for opt, arg in opts:
if ((opt == "-h") | (opt == "--help")) :
ping_usage()
return
elif ((opt == '-l') | (opt == "--url")) :
url = arg
if len(url) == 0:
url=input( _getmsg("ping_url"))
url,context = parseUrl(url);
p = re.compile('^(http|https)://[\w\W]+:\d+[/]{0,1}$')
if (len(url) == 0) | (p.match(url.lower()) == None):
print ( _getmsg("ping_urlformat_example") )
return
url = url + context
ping(url)
def logout_usage():
print ( (_getmsg("logout_usage") + "\n") )
def main_logout(argv):
try:
opts, args = getopt.getopt(argv, "h", ['help'])
except getopt.GetoptError:
logout_usage()
return
for opt, arg in opts:
if ((opt == "-h") | (opt == "--help")) :
logout_usage()
return
logout()
def main_usage():
print ( (_getmsg("main_usage") + "\n") )
def app_usage():
print ( (_getmsg("app_usage") + "\n") )
def main_app(argv):
if len(argv) == 0:
app_usage()
return
appName = ''
list = False
try:
opts, args = getopt.getopt(argv, "hlp:", ['help','list','param='])
except getopt.GetoptError:
app_usage()
return
for opt, arg in opts:
if ((opt == "-h") | (opt == "--help")):
app_usage()
return
elif ((opt == "-l") | (opt == "--list")):
list = True
elif ((opt == "-p") | (opt == "--param")):
appName = arg
if list == True:
status, message = getAllAppStatus()
if status == 'ok':
xdoc = minidom.parseString(message)
apps = xdoc.getElementsByTagName('AppInfo')
if len(apps) == 0:
print ( _getmsg("app_no_published_app") )
return
print ( _getmsg("app_allappstatus_title") )
for app in apps:
appStatus=''
appName=''
for apparg in app.childNodes:
if apparg.nodeName == 'appName':
appName = apparg.childNodes[0].nodeValue
elif apparg.nodeName == 'status':
appStatus = apparg.childNodes[0].nodeValue
print('%-24s%-15s' % (appName, appStatus))
else:
print(message)
return
if len(appName) > 0:
status, message = getAppParameter(appName)
if status == "ok":
xdoc = minidom.parseString(message)
params = xdoc.getElementsByTagName('AppParam')
print ( _getmsg("app_app_param_title") )
for param in params:
id = ''
label = ''
mandatory = ''
dValue = ''
for paramValue in param.childNodes:
if paramValue.nodeName == 'id':
id = paramValue.childNodes[0].nodeValue
elif paramValue.nodeName == 'label':
label = paramValue.childNodes[0].nodeValue
elif paramValue.nodeName == 'mandatory':
mandatory = paramValue.childNodes[0].nodeValue
elif paramValue.nodeName == 'defaultValue':
dValue = paramValue.childNodes[0].nodeValue
print('%-18s%-35s%-11s%-10s' % (id, label, mandatory, dValue))
else:
print(message)
return
app_usage()
return
def userAdd_usage():
print ( (_getmsg("useradd_usage") + "\n") )
def main_userAdd(argv):
username = ''
email = ''
roles = ''
try:
opts, args = getopt.getopt(argv, "hu:e:r:", ['help','username=','email=','role='])
except getopt.GetoptError:
userAdd_usage()
return
for opt, arg in opts:
if ((opt == "-h") | (opt == "--help")):
userAdd_usage()
return
elif ((opt == "-u") | (opt == "--username")):
username = arg
elif ((opt == "-e") | (opt == "--email")):
email = arg
elif ((opt == "-r") | (opt == "--role")):
roles = arg
unameValid = 'false'
if len(username) == 0:
username=input('username:')
if (len(username) == 0):
userAdd_usage()
return
else:
unameValid = 'true'
if (len(email) == 0) & (unameValid == "false"):
email=input('email:')
if (len(roles) == 0) & (unameValid == "false"):
roles=input('role[Normal User]:')
if (len(roles) == 0):
roles = 'Normal User'
status, message = addUser(username, email, roles)
if status == "ok":
if len(message) > 0:
xdoc = minidom.parseString(message)
error = xdoc.getElementsByTagName('message')
print(error[0].childNodes[0].nodeValue)
else:
print('User '+username+' added to IBM Spectrum LSF Application Center.')
else:
print(message)
return
def userDel_usage():
print ( (_getmsg("userdel_usage") + "\n") )
def main_userDel(argv):
username = ''
try:
opts, args = getopt.getopt(argv, "hu:", ['help','username='])
except getopt.GetoptError:
userDel_usage()
return
for opt, arg in opts:
if ((opt == "-h") | (opt == "--help")):
userDel_usage()
return
elif ((opt == "-u") | (opt == "--username")):
username = arg
if len(username) == 0:
username=input('username:')
if (len(username) == 0):
userDel_usage()
return
status, message = removeUser(username)
if status == "ok":
if len(message) > 0:
xdoc = minidom.parseString(message)
error = xdoc.getElementsByTagName('message')
print(error[0].childNodes[0].nodeValue)
else:
print('User '+username+' removed from IBM Spectrum LSF Application Center.')
else:
print(message)
return
def userUpdate_usage():
print ( (_getmsg("userupd_usage") + "\n") )
def main_userUpdate(argv):
if len(argv) == 0:
userUpdate_usage()
return
filepath = ''
try:
opts, args = getopt.getopt(argv, "hf:", ['help','file='])
except getopt.GetoptError:
userUpdate_usage()
return
for opt, arg in opts:
if ((opt == "-h") | (opt == "--help")):
userUpdate_usage()
return
elif ((opt == "-f") | (opt == "--file")):
filepath = arg
if os.path.isfile(filepath) == False:
print ( _getmsg("file_notfound").format(filepath) )
return
try:
with open(filepath, 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
for row in reader:
if len(row) < 2:
print ( _getmsg("invalid_file_format").format(reader.line_num, filepath) )
continue
username = row[0].strip()
email = row[1].strip()
if len (username) == 0 or len (email) == 0:
print ( _getmsg("invalid_file_format").format(reader.line_num, filepath) )
continue
status, message = updateUser(username, email)
if status == "ok":
if len(message) > 0:
xdoc = minidom.parseString(message)
error = xdoc.getElementsByTagName('message')
print ( _getmsg("invalid_line_value").format(reader.line_num, filepath, error[0].childNodes[0].nodeValue) )
else:
print ( _getmsg("user_updated").format(username) )
else:
print(message)
return
except IOError as e:
print(str(e))
return
return