Skip to content

Commit

Permalink
adding check if CK is up-to-date ...
Browse files Browse the repository at this point in the history
  • Loading branch information
gfursin committed Feb 2, 2015
1 parent 3dc7b5a commit c43c1f2
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
v0.1.140810, 2014-11-05 -- starting point
v1.0.1214, 2014-12-14 -- stable pre-release for collaborators
v1.0.1214.beta, 2014-12-14 -- stable pre-release for collaborators
98 changes: 90 additions & 8 deletions ck/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

"wiki_data_web":"https://github.com/ctuning/ck/wiki/Description",
"api_web":"http://cknowledge.org/soft/docs/",
"status_url":"http://cknowledge.org/soft/status/",
"help_web":"More info: https://github.com/ctuning/ck",
"ck_web":"https://github.com/ctuning/ck",
"ck_web_wiki":"https://github.com/ctuning/ck/wiki",
Expand Down Expand Up @@ -138,6 +139,7 @@
"actions":{
"uid":{"desc":"generate UID", "for_web": "yes"},
"version":{"desc":"print CK version", "for_web": "yes"},
"status":{"desc":"check CK version status", "for_web": "yes"},

"help":{"desc":"<CID> print help about data (module) entry"},
"webhelp":{"desc":"<CID> open browser with online help (description) for a data (module) entry"},
Expand Down Expand Up @@ -2025,15 +2027,11 @@ def perform_remote_action(i):
# Import modules compatible with Python 2.x and 3.x
import urllib

try:
import urllib.request as urllib2
except:
import urllib2
try: import urllib.request as urllib2
except: import urllib2

try:
from urllib.parse import urlencode
except:
from urllib import urlencode
try: from urllib.parse import urlencode
except: from urllib import urlencode

rr={'return':0}

Expand Down Expand Up @@ -3148,6 +3146,90 @@ def version(i):

return r

############################################################
# Action: check CK status

def status(i):
"""
Input: {}
Output: {
outdated - if 'yes', newer version exists
return - return code = 0, if successful
> 0, if error
(error) - error text if return > 0
}
"""

outdated=''

o=i.get('out','')

try: import urllib.request as urllib2
except: import urllib2

try: from urllib.parse import urlencode
except: from urllib import urlencode

r=get_version({})
if r['return']>0: return r
version=r['version']
version_str=r['version_str']

lnk=cfg['status_url']+'latest.php'

page=''
try:
res=urllib2.urlopen(lnk)
page=res.read()
except urllib2.HTTPError as e:
return {'return':1, 'error':'Problem accessing server ('+format(e)+')'}
except urllib2.URLError as e:
return {'return':1, 'error':'Problem accessing server ('+format(e)+')'}

if page!='':
s1='<!-- START TEXT -->'
i1=page.find(s1)
if i1>0:
i2=page.find('<!-- STOP TEXT -->')
if i2>0:
text=page[i1+len(s1):i2].strip()
r=convert_json_str_to_dict({'str':text, 'skip_quote_replacement':'yes'})
if r['return']>0:
return {'return':1, 'error':'can\'t parse output from server with version'}

lversion=r['dict'].get('version',[])
if len(lversion)<3:
return {'return':1, 'error':'can\'t parse output from server with version'}

if int(lversion[0])>int(version[0]) or \
(int(lversion[0])==int(version[0]) and int(lversion[1])>int(version[1])) or \
(int(lversion[0])==int(version[0]) and int(lversion[1])==int(version[1]) and int(lversion[2])>int(version[2])) or \
(int(lversion[0])==int(version[0]) and int(lversion[1])==int(version[1]) and int(lversion[2])==int(version[2]) and \
len(version)>3 and version[3]!='' and (len(lversion)==3 or len(lversion)>3 and lversion[3]=='')):

outdated='yes'

lversion_str=''
for q in lversion:
if lversion_str!='': lversion_str+='.'
lversion_str+=q

if o=='con':
out('Your version is outdated: V'+version_str)
out('New available version : V'+lversion_str)
u=cfg.get('ck_web','')
if u!='':
out('')
out('Visit '+u+' for more details ...')

if o=='con' and outdated!='yes':
out('Your version is up-to-date: V'+version_str)

return {'return':0, 'outdated':outdated}

############################################################
# Convert info about entry to CID
# \n=======================================================
Expand Down
16 changes: 8 additions & 8 deletions repo/module/kernel/.cm/info.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"backup_module_uid": "e9a4bb5e10b91e40",
"backup_module_uoa": "module",
"control": {
"engine": "CK",
"license": "See CK LICENSE.txt for licensing details",
"iso_datetime": "2014-12-06T15:37:32.348000",
"copyright": "See CK Copyright.txt for copyright details",
"author": "Grigori Fursin",
"author_email": "[email protected]",
"author_webpage": "http://cTuning.org/lab/people/gfursin",
"copyright": "See CK Copyright.txt for copyright details",
"engine": "CK",
"iso_datetime": "2014-12-06T15:37:32.348000",
"license": "See CK LICENSE.txt for licensing details",
"version": [
"0",
"9",
"4113"
],
"author_webpage": "http://cTuning.org/lab/people/gfursin"
]
},
"data_name": "kernel",
"backup_module_uid": "e9a4bb5e10b91e40"
"data_name": "kernel"
}
13 changes: 8 additions & 5 deletions repo/module/kernel/.cm/meta.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"license": "See CK LICENSE.txt for licensing details",
"copyright": "See CK Copyright.txt for copyright details",
"developer_email": "[email protected]",
"actions": {
"setup": {
"desc": "CK kernel setup"
},
"status": {
"desc": "check CK version status"
}
},
"developer_webpage": "http://cTuning.org/lab/people/gfursin",
"copyright": "See CK Copyright.txt for copyright details",
"desc": "managing CK kernel",
"developer": "Grigori Fursin"
"developer": "Grigori Fursin",
"developer_email": "[email protected]",
"developer_webpage": "http://cTuning.org/lab/people/gfursin",
"license": "See CK LICENSE.txt for licensing details"
}
23 changes: 19 additions & 4 deletions repo/module/kernel/.cm/updates.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
{
"control": [
{
"author": "Grigori Fursin",
"author_email": "[email protected]",
"author_webpage": "http://cTuning.org/lab/people/gfursin",
"copyright": "See CK Copyright.txt for copyright details",
"engine": "CK",
"license": "See CK LICENSE.txt for licensing details",
"iso_datetime": "2015-01-28T15:07:40.561000",
"copyright": "See CK Copyright.txt for copyright details",
"license": "See CK LICENSE.txt for licensing details",
"version": [
"1",
"0",
"1215",
"beta"
]
},
{
"author": "Grigori Fursin",
"author_email": "[email protected]",
"author_webpage": "http://cTuning.org/lab/people/gfursin",
"copyright": "See CK Copyright.txt for copyright details",
"engine": "CK",
"iso_datetime": "2015-02-02T10:04:39.877000",
"license": "See CK LICENSE.txt for licensing details",
"version": [
"1",
"0",
"1215",
"beta"
],
"author_webpage": "http://cTuning.org/lab/people/gfursin"
]
}
]
}
34 changes: 34 additions & 0 deletions repo/module/kernel/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def setup(i):
Input: {
(group) - if !='', configure only this group:
* install - install as python library
* update - check for update
* content - related to content
* repos - related to repositories
* editing - related to editing
Expand All @@ -68,6 +69,7 @@ def setup(i):
if param=='':
if i.get('content','')=='yes': param='content'
elif i.get('install','')=='yes': param='install'
elif i.get('update','')=='yes': param='update'
elif i.get('editing','')=='yes': param='editing'
elif i.get('repos','')=='yes': param='repos'
elif i.get('writing','')=='yes': param='writing'
Expand Down Expand Up @@ -153,6 +155,18 @@ def setup(i):
ck.out('')
ck.out('CK was not installed as Python library.')

# Content authorship options
if param=='' or param=='update':
ck.out(sep)
ck.out('*** Check latest version ***')

ck.out('')
r=ck.inp({'text': 'Would you like to check if your version is up-to-date (Y/n): '})
x=r['string'].lower()
if x!='n' and x!='no':
ck.out('')
ck.status({'out':'con'})

# Content authorship options
if param=='' or param=='content':
ck.out(sep)
Expand Down Expand Up @@ -326,3 +340,23 @@ def setup(i):
ck.out('Configuration successfully recorded to '+fc+' ...')

return {'return':0}

##############################################################################
# check CK version status

def status(i):
"""
Input: {
}
Output: {
return - return code = 0, if successful
> 0, if error
(error) - error text if return > 0
}
"""

print ('check CK version status')

return {'return':0}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
license='BSD 3-clause',
author='Grigori Fursin and the cTuning foundation',
author_email='[email protected]',
description='lightweight knowledge manager to perserve, systematize and cross-link code and data',
description='lightweight knowledge manager to preserve, systematize, cross-link and share code and data',
packages=['ck']
)

0 comments on commit c43c1f2

Please sign in to comment.