00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 import sys
00012 import os
00013 import subprocess
00014 import json
00015 import copy
00016 import re
00017 import platform
00018 import getpass
00019
00020 cmx_error='cMX error: '
00021
00022
00023 def convert_relaxed_classes_to_uids(i):
00024 """
00025 Convert relaxed classes to UIDs
00026
00027 Input: {
00028 cm_list - list with classes (wildcards * and ? can be used)
00029 }
00030
00031 Output: {
00032 cm_return = 0 - no errors
00033 cm_error - error text if cm_return>0
00034 cm_list_uids - updated list of UIDs
00035 cm_list_match - match of classes, i.e. {"value from cm_list":{"cm_uid","alias"}}
00036 }
00037
00038 """
00039
00040
00041 jj={'cm_run_module_uoa':'class',
00042 'cm_action':'list',
00043 'cm_console':'json'}
00044 r1=cm_access(jj)
00045 if r1['cm_return']>0: return r1
00046
00047
00048 classes=[]
00049 match={}
00050
00051 for w in i.get('cm_list',[]):
00052 if is_uid(w):
00053 classes.append(w)
00054 else:
00055
00056 w1=w.replace('*','.*')
00057 w1=w1.replace('?','.?')
00058 w2='.*'+w1+'$'
00059 found=False
00060 for q in r1['cm_mixed']:
00061 k=q.get('cm_display_as_alias','')
00062 k1=q.get('cm_uoa','')
00063 if (k!='' and re.match(w2,k)) or (k1!='' and re.match(w2,k1)):
00064 classes.append(q['cm_uid'])
00065 match[w]={'cm_uid':q['cm_uid'], 'alias':k}
00066 found=True
00067 break
00068 if not found:
00069 return {'cm_return':1, 'cm_error':'class "'+w+'" not found'}
00070
00071 return {'cm_return':0, 'cm_list_uids':classes, 'cm_list_match':match}
00072
00073
00074 def find_and_separate_flags(i):
00075 """
00076 Find flag of format flag=a(,b,c)
00077 and return list of values [a(,b,c)]
00078
00079 Input: {
00080 cm_list - list with flags
00081 flags - list of flags to match
00082 (to support equivalent flags like -c and --classes)
00083 }
00084
00085 Output: {
00086 cm_return = 0 (for compatibility with cM)
00087 cm_found - False, if not found
00088 True, if found
00089 cm_values - List of values
00090 }
00091
00092 """
00093
00094 l=i.get('cm_list',[])
00095 f=i.get('flags',[])
00096
00097 rr={'cm_return':0, 'cm_found':False}
00098
00099 for q in l:
00100 found=''
00101 for k in f:
00102 if q.startswith(k):
00103 found=q[len(k):]
00104 break
00105
00106 if found!='':
00107 v=found.split(',')
00108 v1=[]
00109 for w in v:
00110 if w!='': v1.append(w)
00111 rr['cm_found']=True
00112 rr['cm_values']=v1
00113
00114 return rr
00115
00116
00117 def is_windows():
00118 """
00119 Is Windows?
00120
00121 Input: None
00122
00123 Output: True if Windows
00124 """
00125
00126 win=False
00127
00128 if platform.system().lower().startswith('win'):
00129 win=True
00130
00131 return win
00132
00133
00134 def gen_tmp_with_json(i):
00135 """
00136 Generate tmp file and put array as json there
00137
00138 Input: array
00139
00140 Output: filename
00141 """
00142
00143 import tempfile
00144
00145 nf,f = tempfile.mkstemp(suffix='.json')
00146 nf1=os.fdopen(nf,'wt')
00147 nf1.write(json.dumps(i))
00148 nf1.close()
00149
00150 return f
00151
00152
00153 def merge_array(a,b):
00154 """
00155 Add params from array b (in form x=y) to array a
00156
00157 Input: a=original array
00158 b=array with params (in form x=y)
00159
00160 Output:
00161 """
00162
00163 first=True
00164 for p in b:
00165 if p.startswith("@@"):
00166 jd=p[2:]
00167 if len(jd)<2:
00168 return {'cm_return':1, 'cm_error':'can\'t parse command line option '+p, 'cm_console':con}
00169 je=check_cm_json({'cm_json':jd})
00170
00171 r=merge_arrays({'cm_array':a, 'cm_array1':je})
00172 a=r['cm_array']
00173
00174 elif p.startswith("@"):
00175 name=p[1:]
00176 if len(name)<2:
00177 return {'cm_return':1, 'cm_error':'can\'t parse command line option '+p, 'cm_console':con}
00178
00179 y=load_json_file({'cm_filename':name})
00180 if y['cm_return']==0:
00181 if name.endswith('.tmp'):
00182 os.remove(name)
00183 r=merge_arrays({'cm_array':a, 'cm_array1':y['cm_array']})
00184 a=r['cm_array']
00185 else:
00186 p1=p
00187 p2=''
00188 q=p.find("=")
00189 if q>0:
00190 p1=p[0:q]
00191 if len(p)>q:
00192 p2=p[q+1:]
00193
00194 a[p1]=p2
00195
00196 return
00197
00198
00199 def list2str(a):
00200 """
00201 Convert list to string
00202
00203 Input: list
00204
00205 Output: string
00206 """
00207
00208 r=''
00209 for x in a:
00210 if r!='': r+=' '
00211 r+=x
00212
00213 return r
00214
00215
00216 def is_uid(str):
00217 """
00218 Check if string is cM UID
00219
00220 Input: string to check
00221
00222 Output: True if UID, otherwise False
00223 """
00224
00225 if len(str)!=16:
00226 return False
00227
00228 pattern = r'[^\.a-f0-9]'
00229 if re.search(pattern, str.lower()):
00230 return False
00231
00232 return True
00233
00234
00235 def cid2array(i):
00236 """
00237 Convert cid to array
00238 Note that this function is different from
00239
00240 Input: {
00241 cid - in format (REPO_UOA:)KEY_UOA:DATA_UOA
00242 (prefix) - add prefic to output variables (<prefix>_repo_uoa:...)
00243 }
00244
00245 Output: {
00246 prefix+'_repo_uoa' - repo UOA
00247 prefix+'_module_uoa' - module UOA
00248 prefix+'_data_uoa' - data UOA
00249 }
00250 """
00251
00252 prefix='cm'
00253 if 'prefix' in i and i['prefix']!='': prefix=i['prefix']
00254
00255 array={}
00256 if 'cid' in i and i['cid']!='':
00257 id=i['cid'].split(":")
00258 if (len(id)<2):
00259 array[prefix+'_data_uoa']=id[0]
00260 elif (len(id)<3):
00261 array[prefix+'_module_uoa']=id[0]
00262 array[prefix+'_data_uoa']=id[1]
00263 elif (len(id)<4):
00264 array[prefix+'_repo_uoa']=id[0]
00265 array[prefix+'_module_uoa']=id[1]
00266 array[prefix+'_data_uoa']=id[2]
00267 return array
00268
00269
00270 def return_flags(i):
00271 """
00272 Separate argv to flags (starting from '-' and the rest)
00273
00274 Input: {
00275 argv
00276 }
00277
00278 Output: {
00279 flags - array with flags
00280 cmd - "clean from flags" argv
00281 }
00282 """
00283
00284 ii=copy.deepcopy(i)
00285
00286 flags=[]
00287 for x in range(0, len(i)):
00288 y=i[x]
00289 if y.startswith('-'):
00290 flags.append(y)
00291 ii[x]='to_delete'
00292
00293 ii1=[]
00294 for x in ii:
00295 if x!='to_delete':
00296 ii1.append(x)
00297
00298 return {'cm_return':0, 'flags':flags, 'cmd':ii1}
00299
00300
00301 def error_if_no_cur_repo(i):
00302 """
00303 If current path does not belong to repository, while command needs it,
00304 print error
00305
00306 Input: {}
00307
00308 Output: {}
00309 """
00310
00311 print cmx_error+'this command requires current path to belong to some repository!'
00312
00313 return {'cm_return':0}
00314
00315
00316 def check_cm_json(i):
00317 """
00318 Check if 'cm_json' exist in array and decode it
00319
00320 Input: {
00321 cm_json - array to check
00322 }
00323
00324 Output: {...} - returned array where cm_json is decoded
00325 """
00326
00327 ii={}
00328 ii.update(i)
00329
00330 if 'cm_json' in i:
00331 s=i['cm_json']
00332 s=s.replace('^22^', '"')
00333 s=s.replace('%22', '"')
00334 s=s.replace('%26quot;', '"')
00335 s=s.replace('"', '"')
00336 success=False
00337 try:
00338 j=json.loads(s)
00339 success=True
00340 except:
00341 pass
00342 if success:
00343 del (ii['cm_json'])
00344 ii.update(j)
00345
00346 return ii
00347
00348
00349 def load_json_file(i):
00350 """
00351 Load json from file
00352
00353 Input: {
00354 cm_filename - file name with json
00355 }
00356
00357 Output: {
00358 cm_return - return code = 0 if successful
00359 cm_array - array from json file
00360 }
00361 """
00362
00363 if 'cm_filename' not in i:
00364 return {'cm_return':1, 'cm_error':'parameter "cm_filename" is not defined'}
00365
00366 try:
00367 f=file(i['cm_filename'])
00368 except Exception as e:
00369 return {'cm_return':1, 'cm_error':format(e)}
00370
00371 try:
00372 array=json.loads(f.read())
00373 except Exception as e:
00374 f.close()
00375 return {'cm_return':1, 'cm_error':'problem loading array from file='+i['cm_filename']+' ('+format(e)+')'}
00376
00377 f.close()
00378
00379 return {'cm_return':0, 'cm_array': array}
00380
00381
00382 def merge_arrays(i):
00383 """
00384 Intelligently merge cm_array with cm_array1
00385
00386 Input: {
00387 cm_array - merge this array with cm_array1 (will be directly modified!)
00388 cm_array1 - cM array
00389
00390 Output: {
00391 cm_return - return code = 0 if successful
00392 cm_array - output array
00393 }
00394 """
00395
00396 if 'cm_array' not in i: return {'cm_return':1, 'cm_error':'"cm_array" is not defined in "cm_kernel merge_arrays"'}
00397 if 'cm_array1' not in i: return {'cm_return':1, 'cm_error':'"cm_array1" is not defined in "cm_kernel merge_arrays"'}
00398
00399 a=i['cm_array']
00400 b=i['cm_array1']
00401
00402 for k in b:
00403 v=b[k]
00404 if type(v) is dict:
00405 if k not in a:
00406 a.update({k:b[k]})
00407 elif type(a[k])==dict:
00408 merge_arrays({'cm_array':a[k], 'cm_array1':b[k]})
00409 else:
00410 a[k]=b[k]
00411 elif type(v) is list:
00412
00413
00414 a[k]=[]
00415 for y in v:
00416 a[k].append(y)
00417 else:
00418 a[k]=b[k]
00419
00420 return {'cm_return':0, 'cm_array':a}
00421
00422
00423 def array2cm(a):
00424 """
00425 Convert list to cm array
00426
00427 cm_module_uoa cm_action A=B C=D ... @file1.json E=F ... -- <unparsed arguments>
00428
00429 if extension of @file is .tmp, it will be deleted after read!
00430
00431 Input: input array
00432
00433 Output: {
00434 cm_return - return code = 0 if successful
00435 cm_array - array
00436 cm_console - if 'cm_console' in array, set it to the value of 'cm_console' parameter
00437 }
00438 """
00439 obj={}
00440 con=''
00441
00442 la=len(a)
00443
00444 obj['cm_run_module_uoa']=cm_module_default
00445 obj['cm_action']=cm_action_default
00446
00447 if la>0: obj['cm_run_module_uoa']=a[0]
00448
00449
00450 for x in range(1, len(a)):
00451 p=a[x].rstrip()
00452 if p==cm_unparsed_sep:
00453
00454 obj['cm_unparsed']=a[x+1:]
00455 break
00456
00457 elif p.startswith("@@"):
00458 jd=p[2:]
00459 if len(jd)<2:
00460 return {'cm_return':1, 'cm_error':'can\'t parse command line option '+p, 'cm_console':con}
00461 je=check_cm_json({'cm_json':jd})
00462 obj.update(je)
00463
00464 elif p.startswith("@"):
00465 name=p[1:]
00466 if len(name)<2:
00467 return {'cm_return':1, 'cm_error':'can\'t parse command line option '+p, 'cm_console':con}
00468
00469 y=load_json_file({'cm_filename':name})
00470 if y['cm_return']>0:
00471
00472 ii={}; ii.update(y); ii.update({'cm_console':con})
00473 return ii
00474
00475 if name.endswith('.tmp'):
00476 os.remove(name)
00477
00478 merge_arrays({'cm_array':obj, 'cm_array1':y['cm_array']})
00479 else:
00480 if x==1:
00481 obj['cm_action']=p
00482 else:
00483 p1=p
00484 p2=''
00485 q=p.find("=")
00486 if q>0:
00487 p1=p[0:q]
00488 if len(p)>q:
00489 p2=p[q+1:]
00490
00491 obj[p1]=p2
00492 if p1=='cm_console': con=p2
00493
00494 return {'cm_return':0, 'cm_array':obj, 'cm_console':con}
00495
00496
00497 def str2cm(i):
00498 """
00499 Convert string to cM array
00500
00501 Input: string
00502
00503 Output: {
00504 cm_return - return code = 0 if successful
00505 cm_array - array
00506 }
00507 """
00508 a=i.split(' ')
00509 return array2cm(a)
00510
00511
00512 def access_fe_as_string(s):
00513 """
00514 Front-end to single entry 'access' function as string (if someone finds it easier).
00515
00516 Input: string that will be converted to array (See "access" function).
00517 Output: See "access" function.
00518 """
00519
00520 r=str2cm(s)
00521 if r['cm_return']>0: return r
00522
00523 return cm_access(r['cm_array'])
00524
00525
00526 def cm_access(i):
00527 """
00528 Call external cm and return json
00529
00530 Input: {
00531 cm_run_module_uoa - module UOA
00532 cm_action - action (function) from the module
00533
00534 cm_unparsed - unparsed list to add to command line ...
00535
00536 Set of parameters depending on the called module and action (function)
00537 }
00538
00539 Output: {
00540 cm_return - return code = 0 if successful
00541 > 0 if error
00542 99 - if couldn't process json from output
00543 < 0 if warning (rarely used at this moment)
00544 (cm_error) - error text, if cm_return > 0
00545 (cm_stdout) - if no error, raw output
00546 (cm_stderr) - raw output of error stream
00547
00548 Set of output parameters depending on the called module and action (function)
00549 }
00550 """
00551
00552
00553 if 'cm_run_module_uoa' not in i:
00554 return {'cm_return':1, 'cm_error':'no module specified'}
00555 module=i['cm_run_module_uoa']
00556
00557
00558 if 'cm_action' not in i:
00559 return {'cm_return':1, 'cm_error':'no action specified for module '+i['cm_run_module_uoa']}
00560
00561 cm_stdout=''
00562 cm_stderr=''
00563
00564 del (i['cm_run_module_uoa'])
00565
00566 rr={};
00567 rr['cm_return']=0
00568 rr['cm_stdout']=''
00569 rr['cm_stderr']=''
00570
00571
00572 tf=gen_tmp_with_json(i)
00573 q='@'+tf
00574
00575
00576 cmd=["cm", module, q]
00577
00578 if 'cm_unparsed' in i:
00579 for k in i['cm_unparsed']:
00580 cmd.append(k)
00581
00582 if i.get('cm_console','')=='txt':
00583 qq=''
00584 for k in cmd:
00585 if qq!='': qq+=' '
00586 qq+=k
00587 os.system(qq)
00588
00589 else:
00590 if is_windows():
00591 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
00592 else:
00593 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
00594
00595 (stdout, stderr) = proc.communicate()
00596 if stdout!=None: stdout=stdout.strip()
00597 if stderr!=None: stderr=stderr.strip()
00598
00599 rr['cm_stdout']=stdout
00600 rr['cm_stderr']=stderr
00601
00602 cur={}
00603
00604 err=False
00605 if stdout==None or stdout=='':
00606 err=True
00607 else:
00608 try:
00609 cur=json.loads(stdout)
00610 except Exception as e:
00611 err=True
00612
00613 if os.path.isfile(tf):
00614 os.remove(tf)
00615
00616 if err:
00617 rr['cm_return']=99
00618 rr['cm_error']='can\'t process cM output:\n'
00619 if stdout!=None: rr['cm_error']+='STDOUT:\n'+stdout+'\n'
00620 if stderr!=None: rr['cm_error']+='STDERR:\n'+stderr+'\n'
00621 else:
00622 rr.update(cur)
00623
00624 return rr
00625
00626
00627 if __name__ == "__main__":
00628
00629 '''
00630 cM user friendly command line module
00631
00632 '''
00633
00634
00635 x=return_flags(sys.argv[1:])
00636 argv=x['cmd']
00637 il=len(argv)
00638 flags=x['flags']
00639
00640 if '-?' in flags or '-h' in flags or '--help' in flags or (il>0 and argv[0]=='help'):
00641 print "cM simplified and user friendly command line module to deal with cM repositories"
00642 print ""
00643 print " cmx test - test cM functionality (alpha)"
00644 print ""
00645 print " cmx repo add/create (repo name) - create repo in the current directory (.cmr)"
00646 print " or import existing one;"
00647 print " cmx repo rm/del/delete (-f) (entry name) - delete repository reference"
00648 print " cmx repo mv/move/ren/rename (old entry name) (new entry name) - rename repository reference"
00649 print " cmx repo update/co/checkout (repo name) - update shared repository"
00650 print " cmx repo share/commit (repo name) - commit to shared repository"
00651 print " cmx repo download (repo name) - download repo from the web"
00652 print ""
00653 print " cmx add <entry name>/CID (param1=value1 ... @file1.json ...) - add entry to current repository/module"
00654 print " local repository by default"
00655 print " cmx update <entry name>/CID (param1=value1 ... @file1.json ...) - add entry to current repository/module"
00656 print " local repository by default"
00657 print " cmx rm/del/delete (-f) <entry name>/CID - delete entry from the current repository/module"
00658 print " local repository by default"
00659 print " cmx svnrm/svndel/svndelete <entry name>/CID - delete entry from the current repository/module using SVN"
00660 print " local repository by default"
00661 print " cmx ren/rename <old entry name> <new entry name> - rename entry in the current repository/module"
00662 print " local repository by default"
00663 print " cmx mv/move <old CID> <new CID> - move entry"
00664 print " local repository by default"
00665 print " cmx cp/copy <old CID> <new CID> - copy entry"
00666 print " -k - keep old UID"
00667 print " cmx clean alias1 alias2 ... - remove orphaned aliases"
00668 print ""
00669 print " cmx info/load (CID) - show all info about entry (in json)"
00670 print " global repository by default"
00671 print " cmx find (CID) - show path to the entry"
00672 print " global repository by default"
00673 print " cmx list <module> - list data for a given module"
00674 print " global repository by default"
00675 print " -u - show only UID"
00676 print " cmx index (info) - show status of indexing server"
00677 print " cmx index on - turn on usage of indexing by cM"
00678 print " cmx index off - turn off usage of indexing by cM"
00679 print " cmx index test - test indexing server"
00680 print " cmx index flush - clear the whole index"
00681 print " cmx index clean - clear index for a given repo/module and possibly data"
00682 print " cmx index CID - index entry or entries"
00683 print " local repository by default"
00684 print " data can include patterns * and ?"
00685 print " cmx search (CID key1=value1 value2 ...) - search data"
00686 print " if indexing server is on, use it,"
00687 print " otherwise very slow"
00688 print " if indexing is on, can use wildcards * and ?"
00689 print " -s turns on progress for internal slow search"
00690 print " -t=timeout - sets timeout for local slow search"
00691 print " cmx web_view/wv (CID) - view entry in cM web front-end"
00692 print " cmx web_update/wu (CID) - update entry in cM web front-end"
00693 print ""
00694 print " cmx uid - generate cM UID"
00695 print ""
00696 print " cmx restore_uid_from_alias <alias> - restore UID from alias file"
00697 print ""
00698 print " cmx password - prepare cM SHA1 password"
00699 print " (if -s or --short, output only SHA1 password)"
00700 print ""
00701 print " cmx - print current CID"
00702 print " global repository by default"
00703 print " cmx cv - print current CID in CV format"
00704 print ""
00705 print " cmx help - help"
00706 print ""
00707 print " Additional flags:"
00708 print " -h, --help, -? - this help"
00709 print " (otherwise global by default)"
00710 print " -g, --global - apply command to global repository"
00711 print " -l, --local - apply command to local repository"
00712 print " (otherwise global by default)"
00713 print " -c, --class=class1,class2,... - use classes for the command"
00714 print " for example, add or list"
00715 print " (it can be both UID or alias)"
00716 print " (all classes should be present in an entry)"
00717 print " (alias can include wild cards * and ?)"
00718 print " -q, --quiet - quiet mode when deleting files, etc"
00719 print " -f, --full - add repo to CID if needed"
00720 print " -j, --json - return json if applicable"
00721
00722 exit(0)
00723 else:
00724
00725 globl=False
00726 if '-g' in flags or '--global' in flags:
00727 globl=True
00728
00729 local=False
00730 if '-l' in flags or '--local' in flags:
00731 local=True
00732 globl=False
00733
00734
00735 quiet=False
00736 if '-q' in flags or '--quiet' in flags:
00737 quiet=True
00738
00739
00740 jsn=False
00741 if '-j' in flags or '--json' in flags:
00742 jsn=True
00743
00744
00745 c=''
00746 if il>0:
00747 c=argv[0]
00748 del(argv[0])
00749 il=len(argv)
00750
00751
00752 if c=='uid':
00753 q='cm core gen_uid'
00754 os.system(q)
00755 exit(0)
00756
00757
00758 if c=='restore_uid_from_alias':
00759 if il<1:
00760 print cmx_error+'alias file is not specified!'
00761 exit(1)
00762
00763 af=argv[0]
00764 del(argv[0])
00765 il=len(argv)
00766
00767 if not af.startswith('alias-a-'):
00768 print cmx_error+'file name is not alias!'
00769 exit(1)
00770
00771 f=open(af, 'r')
00772 uid=f.readline().strip()
00773 f.close()
00774
00775 alias=af[8:]
00776
00777 f=open('alias-u-'+uid, 'w')
00778 f.write(alias)
00779 f.close()
00780
00781 print 'Added '+uid+' <- '+alias
00782
00783 exit(0)
00784
00785
00786
00787 r=cm_access({'cm_run_module_uoa':'core',
00788 'cm_action':'get_info_about_full_hosts',
00789 'cm_console':'json'})
00790 if r['cm_return']>0:
00791 print cmx_error+'can\'t get info about web and index hosts ('+r['cm_error']+')'
00792 exit(1)
00793
00794 web_host=r['cm_web_host']
00795 index_host=r['cm_index_host']
00796
00797
00798 r9=cm_access({'cm_run_module_uoa':'core',
00799 'cm_action':'get_info_about_current_path',
00800 'cm_get_uid':'yes',
00801 'cm_console':'json'})
00802 if r9['cm_return']==99:
00803 print cmx_error+'can\'t get info about web and index hosts '+r9['cm_error']
00804 exit(1)
00805
00806
00807 pp=r9.get('cm_path','')
00808 m=r9.get('cm_module_uoa','')
00809 md=r9.get('cm_module_uid','')
00810 d=r9.get('cm_data_uoa','')
00811 dd=r9.get('cm_data_uid','')
00812 rp=r9.get('cm_repo_uoa','')
00813 rpd=r9.get('cm_repo_uid','')
00814
00815
00816 if c=='':
00817 if m=='' or d=='':
00818 print 'Can\'t detect current CID - current directory does not belong to a cM entry ...'
00819 exit(1)
00820
00821 cid=md+':'+dd
00822 if ('-f' in flags or '--flags' in flags) and rpd!='': cid=rpd+':'+cid
00823
00824 if jsn:
00825 r9['cid']=cid
00826 print json.dumps(r9, indent=2, sort_keys=True)
00827 exit(0)
00828 else:
00829 print cid
00830
00831
00832 from Tkinter import Tk
00833 try:
00834 r = Tk()
00835 r.withdraw()
00836 r.clipboard_clear()
00837 r.clipboard_append(md+':'+dd)
00838 r.destroy()
00839 except Exception, e:
00840 print 'Copying to clipboard seems not to be supported by OS ('+format(e)+') ...'
00841
00842 exit(0)
00843
00844 elif c=='cv':
00845 if m=='' or d=='':
00846 print 'Can\'t detect current CID - current directory does not belong to a cM entry ...'
00847 exit(1)
00848
00849 cv='$#cm_'+md+'_'+dd+'#$'
00850 print cv
00851
00852
00853 from Tkinter import Tk
00854 try:
00855 r = Tk()
00856 r.withdraw()
00857 r.clipboard_clear()
00858 r.clipboard_append(md+':'+dd)
00859 r.destroy()
00860 except Exception, e:
00861 print 'Copying to clipboard seems not to be supported by OS ('+format(e)+') ...'
00862
00863 exit(0)
00864
00865
00866
00867
00868 if c=='repo':
00869 c1=''
00870 if il>0:
00871 c1=argv[0]
00872 del(argv[0])
00873 il=len(argv)
00874
00875
00876 if c1=='' or c1=='info':
00877 if jsn:
00878 print json.dumps({'cm_path':pp, 'cm_repo_uoa':rp, 'cm_repo_uid':rpd}, indent=2, sort_keys=True)
00879 exit(0)
00880 else:
00881 print 'Repo path: '+pp
00882 print 'Repo UOA: '+rp
00883 print 'Repo UID: '+rpd
00884
00885 elif c1=='update' or c1=='co' or c1=='checkout':
00886 dn=''
00887 if il>0:
00888 dn=argv[0]
00889
00890 if dn=='': dn=rpd
00891
00892 q='cm repo co'
00893 if dn!='': q+=' cm_repo_uoa='+dn
00894
00895 os.system(q)
00896 exit(0)
00897
00898 elif c1=='commit' or c1=='share':
00899 dn=''
00900 if il>0:
00901 dn=argv[0]
00902
00903 if dn=='': dn=rpd
00904
00905 q='cm repo commit'
00906 if dn!='': q+=' cm_repo_uoa='+dn
00907
00908 os.system(q)
00909 exit(0)
00910
00911 elif c1=='download':
00912 dn=''
00913 if il>0:
00914 dn=argv[0]
00915
00916 if dn=='': dn=rpd
00917
00918 q='cm repo download'
00919 if dn!='': q+=' web_repo_uoa='+dn
00920
00921 os.system(q)
00922 exit(0)
00923
00924 elif c1=='rm' or c1=='del' or c1=='delete':
00925 print 'Note that only the rererence to a repository will be deleted, not repository itself!'
00926 dn=''
00927 if il>0:
00928 dn=argv[0]
00929
00930 q='cm repo delete'
00931 if dn!='':
00932 q+=' cm_data_uoa="'+dn+'"'
00933 elif rpd!='':
00934 q+=' cm_data_uoa='+rpd
00935
00936 os.system(q)
00937 exit(0)
00938
00939 elif c1=='mv' or c1=='ren' or c1=='rename' or c1=='move':
00940 dn1=''
00941 if rpd!='':
00942 dn=rpd
00943 if il>0: dn1=argv[0]
00944 elif il>0:
00945 dn=argv[0]
00946 if il>1: dn1=argv[1]
00947
00948 ii={'cm_run_module_uoa':'core',
00949 'cm_action':'rename',
00950 'orig_module_uoa':'repo',
00951 'orig_data_uoa':dn,
00952 'cm_console':'json'}
00953
00954 update_data=False
00955 if dn1!='':
00956 if is_uid(dn1):
00957 ii['new_data_uid']=dn1
00958 else:
00959 ii['new_data_alias']=dn1
00960 update_data=True
00961
00962 r=cm_access(ii)
00963 if r['cm_return']>0:
00964 print cmx_error+r['cm_error']
00965 exit(1)
00966
00967 if update_data:
00968 ii={'cm_run_module_uoa':'repo',
00969 'cm_action':'update',
00970 'cm_data_uoa':dn1,
00971 'cm_console':'txt',
00972 'cm_array':{'cm_display_as_alias':dn1}}
00973
00974 r=cm_access(ii)
00975 if r['cm_return']>0:
00976 print cmx_error+r['cm_error']
00977 exit(1)
00978
00979 exit(0)
00980
00981 elif c1=='add' or c1=='create':
00982 dn=''
00983 if il>0:
00984 dn=argv[0]
00985 del(argv[0])
00986 il=len(argv)
00987
00988 ii={'cm_run_module_uoa':'repo',
00989 'cm_action':'add',
00990 'cm_data_uoa':dn,
00991 'path_type':'absolute',
00992 'cm_array':{'cm_display_as_alias':dn},
00993 'cm_add_default':'yes',
00994 'cm_console':'txt'}
00995
00996 if len(argv)>0:
00997 merge_array(ii['cm_array'],argv)
00998
00999 if local:
01000 if rp!='': ii['cm_repo_uoa']=rp
01001
01002 r=cm_access(ii)
01003 if r['cm_return']>0:
01004 print cmx_error+r['cm_error']
01005 exit(1)
01006
01007 else:
01008 print cmx_error+'subcommand "'+c1+'" is not recognized for command "repo"'
01009 exit(1)
01010
01011
01012
01013 elif c=='index':
01014 c1=''
01015 if il>0:
01016 c1=argv[0]
01017 del(argv[0])
01018 il=len(argv)
01019
01020
01021 if c1=='' or c1=='info':
01022
01023 r=cm_access({'cm_run_module_uoa':'core',
01024 'cm_action':'load_default_kernel',
01025 'cm_console':'json'})
01026 if r['cm_return']>0:
01027 print cmx_error+r['cm_error']
01028 exit(1)
01029
01030 use_indexing=r['cm_data_obj']['cfg'].get('use_indexing','')
01031
01032 if use_indexing=='yes':
01033 print 'cM indexing is ON'
01034 else:
01035 print 'cM indexing is OFF'
01036
01037 exit(0)
01038
01039
01040 elif c1=='on':
01041
01042 r=cm_access({'cm_run_module_uoa':'core',
01043 'cm_action':'update_default_kernel',
01044 'cm_array':{'use_indexing':'yes'},
01045 'cm_skip_update_info':'yes',
01046 'cm_console':'json'})
01047 if r['cm_return']>0:
01048 print cmx_error+r['cm_error']
01049 exit(1)
01050
01051 print 'cM indexing is TURNED ON. Don\'t forget to start indexing server (cm index server)!'
01052
01053 exit(0)
01054
01055
01056 elif c1=='off':
01057
01058 r=cm_access({'cm_run_module_uoa':'core',
01059 'cm_action':'update_default_kernel',
01060 'cm_array':{'use_indexing':'no'},
01061 'cm_skip_update_info':'yes',
01062 'cm_console':'json'})
01063 if r['cm_return']>0:
01064 print cmx_error+r['cm_error']
01065 exit(1)
01066
01067 print 'cM indexing is TURNED OFF.'
01068
01069 exit(0)
01070
01071
01072 elif c1=='flush':
01073
01074 r=cm_access({'cm_run_module_uoa':'index',
01075 'cm_action':'flush',
01076 'cm_console':'txt'})
01077 if r['cm_return']>0:
01078 print cmx_error+r['cm_error']
01079 exit(1)
01080
01081 print ""
01082
01083 exit(0)
01084
01085 elif c1=='test':
01086
01087 r=cm_access({'cm_run_module_uoa':'index',
01088 'cm_action':'test',
01089 'cm_console':'txt'})
01090 if r['cm_return']>0:
01091 print cmx_error+r['cm_error']
01092 exit(1)
01093
01094 exit(0)
01095
01096
01097 elif c1=='rm' or c1=='del' or c1=='delete' or c1=='add':
01098 mode='delete'
01099 if c1=='add': mode='add'
01100
01101 dn=''
01102
01103 if il>0:
01104 cid=cid2array({'cid':argv[0], 'prefix':'cm'})
01105 if cid.get('cm_repo_uoa','')!='': rp=cid['cm_repo_uoa']
01106 if cid.get('cm_module_uoa','')!='': m=cid['cm_module_uoa']
01107 if cid.get('cm_data_uoa','')!='': dn=cid['cm_data_uoa']
01108
01109 del(argv[0])
01110 il=len(argv)
01111
01112 if dn=='': dn=dd
01113
01114 if rp=='':
01115 print cmx_error+'repository should be defined for this operation!'
01116 exit(1)
01117
01118 if dn=='':
01119 print cmx_error+'entry name is not specified!'
01120 exit(1)
01121
01122 if m=='':
01123 print cmx_error+'module name is not specified!'
01124 exit(1)
01125
01126 ii={'cm_run_module_uoa':'index',
01127 'cm_action':'delete',
01128 'cm_repo_uoa':rp,
01129 'cm_module_uoa':m,
01130 'cm_data_uoa':dn,
01131 'mode':mode,
01132 'cm_console':'txt'}
01133
01134 r=cm_access(ii)
01135 if r['cm_return']>0:
01136 print cmx_error+r['cm_error']
01137 exit(1)
01138
01139 exit(0)
01140
01141 elif c1=='clean':
01142 dn=''
01143
01144 if il>0:
01145 cid=cid2array({'cid':argv[0], 'prefix':'cm'})
01146 if cid.get('cm_repo_uoa','')!='': rp=cid['cm_repo_uoa']
01147 if cid.get('cm_module_uoa','')!='': m=cid['cm_module_uoa']
01148 if cid.get('cm_data_uoa','')!='': dn=cid['cm_data_uoa']
01149
01150 del(argv[0])
01151 il=len(argv)
01152
01153 if dn=='': dn=dd
01154
01155 if rp=='':
01156 print cmx_error+'repository should be defined for this operation!'
01157 exit(1)
01158
01159 if m=='':
01160 print cmx_error+'module name is not specified!'
01161 exit(1)
01162
01163 ii={'cm_run_module_uoa':'index',
01164 'cm_action':'clean',
01165 'index_repo_uoa':rp,
01166 'index_module_uoa':m,
01167 'cm_console':'txt'}
01168 if dn!='': ii['index_data_uoa']=dn
01169
01170 r=cm_access(ii)
01171 if r['cm_return']>0:
01172 print cmx_error+r['cm_error']
01173 exit(1)
01174
01175 exit(0)
01176 else:
01177 dn=''
01178
01179 cid=cid2array({'cid':c1, 'prefix':'cm'})
01180 if cid.get('cm_repo_uoa','')!='': rp=cid['cm_repo_uoa']
01181 if cid.get('cm_module_uoa','')!='': m=cid['cm_module_uoa']
01182 if cid.get('cm_data_uoa','')!='': dn=cid['cm_data_uoa']
01183
01184 if dn=='': dn=dd
01185 if dn=='': dn='*'
01186
01187 ii={'cm_run_module_uoa':'index',
01188 'cm_action':'all',
01189 'index_data_uoa':dn,
01190 'delay':'0',
01191 'cm_console':'txt'}
01192
01193 if m!='': ii['index_module_uoa']=m
01194
01195 if not globl:
01196 if rp!='': ii['index_repo_uoa']=rp
01197
01198 r=cm_access(ii)
01199 if r['cm_return']>0:
01200 print cmx_error+r['cm_error']
01201 exit(1)
01202
01203 exit(0)
01204
01205
01206
01207
01208 elif c=='search':
01209 dn=''
01210
01211 if il>0:
01212 cid=cid2array({'cid':argv[0], 'prefix':'cm'})
01213 if cid.get('cm_repo_uoa','')!='': rp=cid['cm_repo_uoa']
01214 if cid.get('cm_module_uoa','')!='': m=cid['cm_module_uoa']
01215 if cid.get('cm_data_uoa','')!='': dn=cid['cm_data_uoa']
01216
01217 del(argv[0])
01218 il=len(argv)
01219
01220 if dn=='': dn=dd
01221
01222 if m=='':
01223 print cmx_error+'module name is not specified'
01224 exit(1)
01225
01226 ii={'cm_run_module_uoa':'core',
01227 'cm_action':'search',
01228 'cm_console':'txt'}
01229
01230 if m!='*':
01231 ii['module_selection']=[m]
01232
01233 if not globl:
01234 if rp!='': ii['repo_selection']=[rp]
01235
01236
01237 qx=1
01238 for q in argv:
01239 key='key_'+str(qx)
01240 value='value_'+str(qx)
01241 qx+=1
01242
01243 qq=q.split('=')
01244 if len(qq)<2:
01245 ii[value]=qq[0]
01246 else:
01247 ii[key]=qq[0]
01248 ii[value]=qq[1]
01249
01250 if '-s' in flags: ii['show_search_progress']='yes'
01251
01252
01253 for q in flags:
01254 if q.startswith('-t='):
01255 ii['timeout']=q[3:]
01256
01257 if jsn:
01258 ii['cm_console']='json_with_indent'
01259
01260 r=cm_access(ii)
01261 if r['cm_return']>0:
01262 print cmx_error+r['cm_error']
01263 exit(1)
01264
01265 print r['cm_stdout']
01266
01267 exit(0)
01268
01269
01270
01271
01272 elif c=='clean':
01273 dn=''
01274
01275 lc=[]
01276
01277 if il>0:
01278 for q in range(0,il):
01279 lc.append(argv[q])
01280
01281
01282 for q in lc:
01283 if q.startswith('alias-a-'):
01284 l=''
01285
01286 try:
01287 f=open(q, 'r')
01288 l=f.readline()
01289 l=l.strip()
01290 f.close()
01291 except:
01292 pass
01293
01294 if os.path.exists(q):
01295 print q+' was removed ...'
01296 os.remove(q)
01297
01298 if l!='':
01299 q1='alias-u-'+l
01300
01301 if os.path.exists(q1):
01302 os.remove(q1)
01303 print q1+' was removed ...'
01304
01305
01306
01307 exit(0)
01308
01309
01310
01311
01312 elif c=='info' or c=='load':
01313 dn=''
01314
01315 if il>0:
01316 cid=cid2array({'cid':argv[0], 'prefix':'cm'})
01317 if cid.get('cm_repo_uoa','')!='': rp=cid['cm_repo_uoa']
01318 if cid.get('cm_module_uoa','')!='': m=cid['cm_module_uoa']
01319 if cid.get('cm_data_uoa','')!='': dn=cid['cm_data_uoa']
01320
01321 if dn=='': dn=dd
01322
01323 if dn=='':
01324 print cmx_error+'entry name is not specified'
01325 exit(1)
01326
01327 ii={'cm_run_module_uoa':'core',
01328 'cm_action':'find_path_to_data',
01329 'cm_module_uoa':m,
01330 'cm_data_uoa':dn,
01331 'cm_console':'json_with_indent'}
01332
01333 if local:
01334 if rp!='': ii['cm_repo_uoa']=rp
01335 else:
01336 error_if_no_cur_repo({})
01337 exit(1)
01338
01339 r=cm_access(ii)
01340 if r['cm_return']>0:
01341 print cmx_error+r['cm_error']
01342 exit(1)
01343
01344 print r['cm_stdout']
01345 exit(0)
01346
01347
01348 elif c=='find':
01349 dn=''
01350
01351 if il>0:
01352 cid=cid2array({'cid':argv[0], 'prefix':'cm'})
01353 if cid.get('cm_repo_uoa','')!='': rp=cid['cm_repo_uoa']
01354 if cid.get('cm_module_uoa','')!='': m=cid['cm_module_uoa']
01355 if cid.get('cm_data_uoa','')!='': dn=cid['cm_data_uoa']
01356
01357 if dn=='': dn=dd
01358
01359 if dn=='':
01360 print cmx_error+'entry name is not specified'
01361 exit(1)
01362
01363 ii={'cm_run_module_uoa':'core',
01364 'cm_action':'find_path_to_data',
01365 'cm_module_uoa':m,
01366 'cm_data_uoa':dn,
01367 'cm_console':'json_with_indent'}
01368
01369 if local:
01370 if rp!='': ii['cm_repo_uoa']=rp
01371 else:
01372 error_if_no_cur_repo({})
01373 exit(1)
01374
01375 r=cm_access(ii)
01376 if r['cm_return']>0:
01377 print cmx_error+r['cm_error']
01378 exit(1)
01379
01380 print r['cm_path']
01381 exit(0)
01382
01383
01384 elif c=='web_view' or c=='wv':
01385 dn=''
01386
01387 if il>0:
01388 cid=cid2array({'cid':argv[0], 'prefix':'cm'})
01389 if cid.get('cm_repo_uoa','')!='': rp=cid['cm_repo_uoa']
01390 if cid.get('cm_module_uoa','')!='': m=cid['cm_module_uoa']
01391 if cid.get('cm_data_uoa','')!='': dn=cid['cm_data_uoa']
01392
01393 if dn=='': dn=dd
01394
01395 if dn=='':
01396 print cmx_error+'entry name is not specified'
01397 exit(1)
01398
01399 cid=m+':'+dn
01400
01401 q='cm_browser "'+web_host+'view_cid='
01402
01403 if local:
01404 if rp!='': cid=rp+':'+cid
01405 else:
01406 error_if_no_cur_repo({})
01407 exit(1)
01408
01409 q+=cid+'"'
01410 os.system(q)
01411
01412 elif c=='web_update' or c=='wu':
01413 dn=''
01414
01415 if il>0:
01416 cid=cid2array({'cid':argv[0], 'prefix':'cm'})
01417 if cid.get('cm_repo_uoa','')!='': rp=cid['cm_repo_uoa']
01418 if cid.get('cm_module_uoa','')!='': m=cid['cm_module_uoa']
01419 if cid.get('cm_data_uoa','')!='': dn=cid['cm_data_uoa']
01420
01421 if dn=='': dn=dd
01422
01423 if dn=='':
01424 print cmx_error+'entry name is not specified'
01425 exit(1)
01426
01427 cid=m+':'+dn
01428 q='cm_browser "'+web_host+'cm_menu=browse&cm_subaction_update&browse_cid='
01429
01430 if local:
01431 if rp!='': cid=rp+':'+cid
01432 else:
01433 error_if_no_cur_repo({})
01434 exit(1)
01435
01436 q+=cid+'"'
01437 os.system(q)
01438
01439 elif c=='add':
01440 dn=''
01441
01442 if il>0:
01443 cid=cid2array({'cid':argv[0], 'prefix':'cm'})
01444 if cid.get('cm_repo_uoa','')!='': rp=cid['cm_repo_uoa']
01445 if cid.get('cm_module_uoa','')!='': m=cid['cm_module_uoa']
01446 if cid.get('cm_data_uoa','')!='': dn=cid['cm_data_uoa']
01447
01448 del(argv[0])
01449 il=len(argv)
01450
01451 if dn=='': dn=dd
01452
01453 if dn=='*':dn=''
01454
01455 if m=='':
01456 print cmx_error+'module name is not specified'
01457 exit(1)
01458
01459 ii={'cm_run_module_uoa':m,
01460 'cm_action':'add',
01461 'cm_data_uoa':dn,
01462 'cm_array':{'cm_display_as_alias':dn},
01463 'cm_add_default':'yes',
01464 'cm_console':'txt'}
01465
01466
01467 if len(argv)>0:
01468 merge_array(ii['cm_array'],argv)
01469
01470
01471 if not globl:
01472 if rp!='': ii['cm_repo_uoa']=rp
01473
01474
01475 r=find_and_separate_flags({'cm_list':flags, 'flags':['-c=','--class=']})
01476 if r['cm_found']:
01477
01478
01479 r1=convert_relaxed_classes_to_uids({'cm_list':r['cm_values']})
01480 if r1['cm_return']>0:
01481 print cmx_error+r1['cm_error']
01482 exit(1)
01483
01484 ww=r1['cm_list_match']
01485 for w in ww:
01486 print 'Class "'+w+'" converted to "'+ww[w].get('alias','')+'" ('+ww[w].get('cm_uid','')+') ...'
01487
01488 ii['cm_array']['cm_classes_uoa']=r1['cm_list_uids']
01489
01490
01491
01492 r=cm_access(ii)
01493 if r['cm_return']>0:
01494 print cmx_error+r['cm_error']
01495 exit(1)
01496
01497 exit(0)
01498
01499
01500 elif c=='rm' or c=='del' or c=='delete':
01501 dn=''
01502
01503 if il>0:
01504 cid=cid2array({'cid':argv[0], 'prefix':'cm'})
01505 if cid.get('cm_repo_uoa','')!='': rp=cid['cm_repo_uoa']
01506 if cid.get('cm_module_uoa','')!='': m=cid['cm_module_uoa']
01507 if cid.get('cm_data_uoa','')!='': dn=cid['cm_data_uoa']
01508
01509 del(argv[0])
01510 il=len(argv)
01511
01512 if dn=='': dn=dd
01513
01514 if dn=='':
01515 print cmx_error+'entry name is not specified'
01516 exit(1)
01517
01518 if m=='':
01519 print cmx_error+'module name is not specified'
01520 exit(1)
01521
01522 while dn!='':
01523 print ''
01524 ii={'cm_run_module_uoa':m,
01525 'cm_action':'delete',
01526 'cm_data_uoa':dn,
01527 'cm_console':'txt'}
01528
01529 if quiet: ii['cm_force_delete']='yes'
01530
01531 if not globl:
01532 if rp!='': ii['cm_repo_uoa']=rp
01533
01534 r=cm_access(ii)
01535 if r['cm_return']>0:
01536 print cmx_error+r['cm_error']
01537 exit(1)
01538
01539 if il>0:
01540 dn=argv[0]
01541 del(argv[0])
01542 il=len(argv)
01543 else:
01544 dn=''
01545
01546 exit(0)
01547
01548
01549 elif c=='svnrm' or c=='svndel' or c=='svndelete':
01550 dn=''
01551
01552 if il>0:
01553 cid=cid2array({'cid':argv[0], 'prefix':'cm'})
01554 if cid.get('cm_repo_uoa','')!='': rp=cid['cm_repo_uoa']
01555 if cid.get('cm_module_uoa','')!='': m=cid['cm_module_uoa']
01556 if cid.get('cm_data_uoa','')!='': dn=cid['cm_data_uoa']
01557
01558 del(argv[0])
01559 il=len(argv)
01560
01561 if dn=='': dn=dd
01562
01563 if dn=='':
01564 print cmx_error+'entry name is not specified'
01565 exit(1)
01566
01567 if m=='':
01568 print cmx_error+'module name is not specified'
01569 exit(1)
01570
01571 print ''
01572
01573 ii={'cm_run_module_uoa':'core',
01574 'cm_action':'find_path_to_data',
01575 'cm_module_uoa':m,
01576 'cm_data_uoa':dn,
01577 'cm_console':'json_with_indent'}
01578 if rp!='': ii['cm_repo_uoa']=rp
01579
01580 r=cm_access(ii)
01581 if r['cm_return']>0:
01582 print cmx_error+r['cm_error']
01583 exit(1)
01584
01585 p=r['cm_path']
01586
01587 x=os.path.abspath(os.curdir)
01588 os.chdir(os.path.join(p,'..'))
01589
01590 if not is_uid(dn):
01591 p1=os.path.join('.cm','alias-a-'+dn)
01592 if os.path.isfile(p1):
01593 f=open(p1,'r')
01594 uid=f.read().strip()
01595 f.close()
01596 os.system('svn rm --force '+p1)
01597
01598 p2=os.path.join('.cm','alias-u-'+uid)
01599 if os.path.isfile(p2):
01600 os.system('svn rm --force '+p2)
01601
01602 os.system('svn rm --force '+dn)
01603
01604 os.chdir(x)
01605
01606 exit(0)
01607
01608
01609 elif c=='update':
01610 dn=''
01611
01612 if il>0:
01613 cid=cid2array({'cid':argv[0], 'prefix':'cm'})
01614 if cid.get('cm_repo_uoa','')!='': rp=cid['cm_repo_uoa']
01615 if cid.get('cm_module_uoa','')!='': m=cid['cm_module_uoa']
01616 if cid.get('cm_data_uoa','')!='': dn=cid['cm_data_uoa']
01617
01618 del(argv[0])
01619 il=len(argv)
01620
01621 if dn=='': dn=dd
01622
01623 if dn=='':
01624 print cmx_error+'entry name is not specified'
01625 exit(1)
01626
01627 if m=='':
01628 print cmx_error+'module name is not specified'
01629 exit(1)
01630
01631 ii={'cm_run_module_uoa':m,
01632 'cm_action':'update',
01633 'cm_data_uoa':dn,
01634 'cm_array':{},
01635 'cm_console':'txt'}
01636
01637 if len(argv)>0:
01638 merge_array(ii['cm_array'],argv)
01639
01640 if not globl:
01641 if rp!='': ii['cm_repo_uoa']=rp
01642
01643 r=cm_access(ii)
01644 if r['cm_return']>0:
01645 print cmx_error+r['cm_error']
01646 exit(1)
01647
01648 exit(0)
01649
01650
01651 elif c=='ren' or c=='rename':
01652 dn=''
01653
01654 if il>0:
01655 cid=cid2array({'cid':argv[0], 'prefix':'cm'})
01656 if cid.get('cm_repo_uoa','')!='': rp=cid['cm_repo_uoa']
01657 if cid.get('cm_module_uoa','')!='': m=cid['cm_module_uoa']
01658 if cid.get('cm_data_uoa','')!='': dn=cid['cm_data_uoa']
01659
01660 del(argv[0])
01661 il=len(argv)
01662
01663 if dn=='': dn=dd
01664
01665 if dn=='':
01666 print cmx_error+'entry name is not specified'
01667 exit(1)
01668
01669 if m=='':
01670 print cmx_error+'module name is not specified'
01671 exit(1)
01672
01673 ii={'cm_run_module_uoa':'core',
01674 'cm_action':'rename',
01675 'orig_module_uoa':m,
01676 'orig_data_uoa':dn,
01677 'cm_console':'json'}
01678
01679 if not globl:
01680 if rp!='': ii['orig_repo_uoa']=rp
01681
01682 dn1=''
01683 if il>0:
01684 dn1=argv[0]
01685
01686 update_data=False
01687 if dn1!='':
01688 if is_uid(dn1):
01689 ii['new_data_uid']=dn1
01690 else:
01691 ii['new_data_alias']=dn1
01692 update_data=True
01693
01694 r=cm_access(ii)
01695 if r['cm_return']>0:
01696 print cmx_error+r['cm_error']
01697 exit(1)
01698
01699 if update_data:
01700 ii={'cm_run_module_uoa':m,
01701 'cm_action':'update',
01702 'cm_data_uoa':dn1,
01703 'cm_console':'txt',
01704 'cm_array':{'cm_display_as_alias':dn1}}
01705
01706 r=cm_access(ii)
01707 if r['cm_return']>0:
01708 print cmx_error+r['cm_error']
01709 exit(1)
01710
01711 exit(0)
01712
01713 elif c=='cp' or c=='copy' or c=='mv' or c=='move':
01714 move=False
01715 if c=='mv' or c=='move': move=True
01716
01717 dn=''
01718
01719 if il>0:
01720 cid=cid2array({'cid':argv[0], 'prefix':'cm'})
01721 if cid.get('cm_repo_uoa','')!='': rp=cid['cm_repo_uoa']
01722 if cid.get('cm_module_uoa','')!='': m=cid['cm_module_uoa']
01723 if cid.get('cm_data_uoa','')!='': dn=cid['cm_data_uoa']
01724
01725 del(argv[0])
01726 il=len(argv)
01727
01728 if dn=='': dn=dd
01729
01730 if dn=='':
01731 print cmx_error+'entry name is not specified'
01732 exit(1)
01733
01734 if m=='':
01735 print cmx_error+'module name is not specified'
01736 exit(1)
01737
01738 ii={'cm_run_module_uoa':'core',
01739 'cm_action':'copy',
01740 'orig_module_uoa':m,
01741 'orig_data_uoa':dn,
01742 'cm_console':'json'}
01743
01744 if not globl:
01745 if rp!='': ii['orig_repo_uoa']=rp
01746
01747 rp1=''
01748 dn1=''
01749
01750 if il>0:
01751 cid=cid2array({'cid':argv[0], 'prefix':'cm'})
01752 if cid.get('cm_repo_uoa','')!='': rp1=cid['cm_repo_uoa']
01753 if cid.get('cm_data_uoa','')!='': dn1=cid['cm_data_uoa']
01754
01755 del(argv[0])
01756 il=len(argv)
01757
01758 if dn1=='*': dn1=dn
01759
01760 if rp1!='': ii['target_repo_uoa']=rp1
01761 if dn1!='': ii['target_data_uoa']=dn1
01762
01763 if move: ii['move']='yes'
01764
01765 if '-k' not in flags: ii['generate_new_uid']='yes'
01766
01767 r=cm_access(ii)
01768 if r['cm_return']>0:
01769 print cmx_error+r['cm_error']
01770 exit(1)
01771
01772 if not is_uid(dn1):
01773 ii={'cm_run_module_uoa':m,
01774 'cm_action':'update',
01775 'cm_data_uoa':dn1,
01776 'cm_console':'txt',
01777 'cm_array':{'cm_display_as_alias':dn1}}
01778
01779 r=cm_access(ii)
01780 if r['cm_return']>0:
01781 print cmx_error+r['cm_error']
01782 exit(1)
01783
01784 exit(0)
01785
01786
01787 elif c=='list':
01788 dn=''
01789 if il>0:
01790 m=argv[0]
01791 del(argv[0])
01792 il=len(argv)
01793
01794 if m=='':
01795 print cmx_error+'module name is not specified'
01796 exit(1)
01797
01798 ii={'cm_run_module_uoa':'core',
01799 'cm_action':'list',
01800 'cm_module_uoa':m,
01801 'cm_console':'txt'}
01802
01803 if local:
01804 if rp!='': ii['cm_repo_uoa']=rp
01805
01806 if '-u' not in flags: ii['show_display_as_alias']='yes'
01807
01808
01809 r=find_and_separate_flags({'cm_list':flags, 'flags':['-c=','--class=']})
01810 if r['cm_found']:
01811
01812 r1=convert_relaxed_classes_to_uids({'cm_list':r['cm_values']})
01813 if r1['cm_return']>0:
01814 print cmx_error+r1['cm_error']
01815 exit(1)
01816
01817 ww=r1['cm_list_match']
01818
01819
01820
01821
01822
01823
01824 ii['cm_classes_uoa']=r1['cm_list_uids']
01825
01826 if jsn:
01827 ii['cm_console']='json_with_indent'
01828
01829 r=cm_access(ii)
01830 if r['cm_return']>0:
01831 print cmx_error+r['cm_error']
01832 exit(1)
01833
01834 print r['cm_stdout']
01835
01836 exit(0)
01837
01838
01839 elif c=='test':
01840 q='cm test all'
01841 os.system(q)
01842
01843 exit(0)
01844
01845
01846 elif c=='password':
01847 password=getpass.getpass('Enter password: ')
01848
01849 if password!='':
01850 ii={'cm_run_module_uoa':'core',
01851 'cm_action':'convert_str_to_sha1',
01852 'cm_string':password,
01853 'cm_console':'json'}
01854 r=cm_access(ii)
01855 if r['cm_return']>0:
01856 print cmx_error+r['cm_error']
01857 exit(1)
01858
01859 if '-s' in flags or '--short' in flags:
01860 print r['cm_string_sha1_base64']
01861 else:
01862 print ''
01863 print 'cM password hash (BASE64(SHA1) compatible with .htpasswd format):'
01864 print ''
01865 print r['cm_string_sha1_base64']
01866
01867 print ''
01868 print 'Note, you can use CM_USER_PASSWORD1 environment variable'
01869 print ' to set this password and automate login!'
01870
01871 exit(0)
01872
01873
01874 else:
01875 print cmx_error+'command '+c+' is not recognized!'
01876 exit(1)
01877
01878 exit(0)