diff --git a/CHANGES.txt b/CHANGES.txt index f61b1bd433..4be3090c2d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -3,6 +3,7 @@ * fixed issue #81 (when renaming entry with data_name==data_alias, change it to the new alias) * added flag --name (duplicate of --show_name) to "ck ls" * fixed issue #82 (detecting name of repo from the zip filename) + * fixed repo renaming (now updates .ckr.json and recache repo properly) * V1.9.2 * added "ck cd {CK entry}" to open a new shell in a given CK entry diff --git a/ck/repo/module/repo/.cm/meta.json b/ck/repo/module/repo/.cm/meta.json index d68f52bbb9..6e09fd6b46 100644 --- a/ck/repo/module/repo/.cm/meta.json +++ b/ck/repo/module/repo/.cm/meta.json @@ -39,6 +39,12 @@ "remove": { "desc": "remove repository from CK" }, + "ren": { + "desc": "rename repo" + }, + "rename": { + "desc": "rename repo" + }, "renew": { "desc": "renew repository (remove fully and pull again)" }, diff --git a/ck/repo/module/repo/module.py b/ck/repo/module/repo/module.py index e88e347c9c..7ebcf6fd16 100644 --- a/ck/repo/module/repo/module.py +++ b/ck/repo/module/repo/module.py @@ -2445,3 +2445,125 @@ def reset(i): i['reset']='yes' return show(i) + +############################################################################## +# rename repo + +def ren(i): + """ + Input: { + data_uoa - repo UOA + + (new_data_uoa) + or + xcids[0] - {'data_uoa'} - new data UOA + } + + Output: { + return - return code = 0, if successful + > 0, if error + (error) - error text if return > 0 + } + + """ + + o=i.get('out','') + + duoa=i.get('data_uoa','') + + if duoa=='': + return {'return':1, 'error':'repo is not defined'} + + r=ck.access({'action':'load', + 'module_uoa':work['self_module_uid'], + 'data_uoa':duoa}) + if r['return']>0: return r + + dd=r['dict'] + dp=r['path'] + duoa_real=r['data_uoa'] + dname=r['data_name'] + + nduoa=i.get('new_data_uoa','') + + if nduoa=='': + xcids=i.get('xcids',[]) + if len(xcids)>0: + xcid=xcids[0] + nduoa=xcid.get('data_uoa','') + + if nduoa=='': + xcids=i.get('cids',[]) + if len(xcids)>0: + nduoa=xcids[0] + + if nduoa=='': + return {'return':1, 'error':'new repo name is not defined'} + + if nduoa=='': + return {'return':1, 'error':'new repo name is not defined'} + + if nduoa=='local' or nduoa=='default': + return {'return':1, 'error':'new repo name already exists'} + + # Check if such repo doesn't exist + r=ck.access({'action':'load', + 'module_uoa':work['self_module_uid'], + 'data_uoa':nduoa}) + if r['return']==0: + return {'return':1, 'error':'repo already exists'} + + # Update .ckr.json + dpp=dd.get('path','') + if dpp!='': + pckr=os.path.join(dpp,ck.cfg['repo_file']) + + r=ck.load_json_file({'json_file':pckr}) + if r['return']>0: return r + + dckr=r['dict'] + + x=dckr.get('data_uoa','') + if x!='' and x==duoa_real: dckr['data_uoa']=nduoa + + x=dckr.get('data_alias','') + if x!='' and x==duoa_real: dckr['data_alias']=nduoa + + x=dckr.get('data_name','') + if x!='' and x==duoa_real: dckr['data_name']=nduoa + + r=ck.save_json_to_file({'json_file':pckr, 'dict':dckr}) + if r['return']>0: return r + + # Rename repo entry using internal command + r=ck.access({'action':'ren', + 'module_uoa':work['self_module_uid'], + 'data_uoa':duoa, + 'new_data_uoa':nduoa, + 'common_func':'yes'}) + if r['return']>0: return r + + # Recache repos + r1=recache({'out':o}) + if r1['return']>0: return r1 + + return r + +############################################################################## +# rename repo + +def rename(i): + """ + Input: { + See "ck ren repo --help" + } + + Output: { + return - return code = 0, if successful + > 0, if error + (error) - error text if return > 0 + } + + """ + + return ren(i)