Skip to content

Commit

Permalink
fixed repo renaming (now updates .ckr.json and recache repo properly)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfursin committed Oct 12, 2017
1 parent f55ea00 commit 6ce482d
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions ck/repo/module/repo/.cm/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
},
Expand Down
122 changes: 122 additions & 0 deletions ck/repo/module/repo/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 6ce482d

Please sign in to comment.