Skip to content

Commit c43c1f2

Browse files
committed
adding check if CK is up-to-date ...
1 parent 3dc7b5a commit c43c1f2

File tree

7 files changed

+161
-27
lines changed

7 files changed

+161
-27
lines changed

CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
v0.1.140810, 2014-11-05 -- starting point
2-
v1.0.1214, 2014-12-14 -- stable pre-release for collaborators
2+
v1.0.1214.beta, 2014-12-14 -- stable pre-release for collaborators

ck/kernel.py

Lines changed: 90 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
"wiki_data_web":"https://github.com/ctuning/ck/wiki/Description",
2828
"api_web":"http://cknowledge.org/soft/docs/",
29+
"status_url":"http://cknowledge.org/soft/status/",
2930
"help_web":"More info: https://github.com/ctuning/ck",
3031
"ck_web":"https://github.com/ctuning/ck",
3132
"ck_web_wiki":"https://github.com/ctuning/ck/wiki",
@@ -138,6 +139,7 @@
138139
"actions":{
139140
"uid":{"desc":"generate UID", "for_web": "yes"},
140141
"version":{"desc":"print CK version", "for_web": "yes"},
142+
"status":{"desc":"check CK version status", "for_web": "yes"},
141143

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

2028-
try:
2029-
import urllib.request as urllib2
2030-
except:
2031-
import urllib2
2030+
try: import urllib.request as urllib2
2031+
except: import urllib2
20322032

2033-
try:
2034-
from urllib.parse import urlencode
2035-
except:
2036-
from urllib import urlencode
2033+
try: from urllib.parse import urlencode
2034+
except: from urllib import urlencode
20372035

20382036
rr={'return':0}
20392037

@@ -3148,6 +3146,90 @@ def version(i):
31483146

31493147
return r
31503148

3149+
############################################################
3150+
# Action: check CK status
3151+
3152+
def status(i):
3153+
"""
3154+
Input: {}
3155+
3156+
Output: {
3157+
outdated - if 'yes', newer version exists
3158+
3159+
return - return code = 0, if successful
3160+
> 0, if error
3161+
(error) - error text if return > 0
3162+
}
3163+
3164+
"""
3165+
3166+
outdated=''
3167+
3168+
o=i.get('out','')
3169+
3170+
try: import urllib.request as urllib2
3171+
except: import urllib2
3172+
3173+
try: from urllib.parse import urlencode
3174+
except: from urllib import urlencode
3175+
3176+
r=get_version({})
3177+
if r['return']>0: return r
3178+
version=r['version']
3179+
version_str=r['version_str']
3180+
3181+
lnk=cfg['status_url']+'latest.php'
3182+
3183+
page=''
3184+
try:
3185+
res=urllib2.urlopen(lnk)
3186+
page=res.read()
3187+
except urllib2.HTTPError as e:
3188+
return {'return':1, 'error':'Problem accessing server ('+format(e)+')'}
3189+
except urllib2.URLError as e:
3190+
return {'return':1, 'error':'Problem accessing server ('+format(e)+')'}
3191+
3192+
if page!='':
3193+
s1='<!-- START TEXT -->'
3194+
i1=page.find(s1)
3195+
if i1>0:
3196+
i2=page.find('<!-- STOP TEXT -->')
3197+
if i2>0:
3198+
text=page[i1+len(s1):i2].strip()
3199+
r=convert_json_str_to_dict({'str':text, 'skip_quote_replacement':'yes'})
3200+
if r['return']>0:
3201+
return {'return':1, 'error':'can\'t parse output from server with version'}
3202+
3203+
lversion=r['dict'].get('version',[])
3204+
if len(lversion)<3:
3205+
return {'return':1, 'error':'can\'t parse output from server with version'}
3206+
3207+
if int(lversion[0])>int(version[0]) or \
3208+
(int(lversion[0])==int(version[0]) and int(lversion[1])>int(version[1])) or \
3209+
(int(lversion[0])==int(version[0]) and int(lversion[1])==int(version[1]) and int(lversion[2])>int(version[2])) or \
3210+
(int(lversion[0])==int(version[0]) and int(lversion[1])==int(version[1]) and int(lversion[2])==int(version[2]) and \
3211+
len(version)>3 and version[3]!='' and (len(lversion)==3 or len(lversion)>3 and lversion[3]=='')):
3212+
3213+
outdated='yes'
3214+
3215+
lversion_str=''
3216+
for q in lversion:
3217+
if lversion_str!='': lversion_str+='.'
3218+
lversion_str+=q
3219+
3220+
if o=='con':
3221+
out('Your version is outdated: V'+version_str)
3222+
out('New available version : V'+lversion_str)
3223+
u=cfg.get('ck_web','')
3224+
if u!='':
3225+
out('')
3226+
out('Visit '+u+' for more details ...')
3227+
3228+
if o=='con' and outdated!='yes':
3229+
out('Your version is up-to-date: V'+version_str)
3230+
3231+
return {'return':0, 'outdated':outdated}
3232+
31513233
############################################################
31523234
# Convert info about entry to CID
31533235
# \n=======================================================

repo/module/kernel/.cm/info.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
2+
"backup_module_uid": "e9a4bb5e10b91e40",
23
"backup_module_uoa": "module",
34
"control": {
4-
"engine": "CK",
5-
"license": "See CK LICENSE.txt for licensing details",
6-
"iso_datetime": "2014-12-06T15:37:32.348000",
7-
"copyright": "See CK Copyright.txt for copyright details",
85
"author": "Grigori Fursin",
96
"author_email": "[email protected]",
7+
"author_webpage": "http://cTuning.org/lab/people/gfursin",
8+
"copyright": "See CK Copyright.txt for copyright details",
9+
"engine": "CK",
10+
"iso_datetime": "2014-12-06T15:37:32.348000",
11+
"license": "See CK LICENSE.txt for licensing details",
1012
"version": [
1113
"0",
1214
"9",
1315
"4113"
14-
],
15-
"author_webpage": "http://cTuning.org/lab/people/gfursin"
16+
]
1617
},
17-
"data_name": "kernel",
18-
"backup_module_uid": "e9a4bb5e10b91e40"
18+
"data_name": "kernel"
1919
}

repo/module/kernel/.cm/meta.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
{
2-
"license": "See CK LICENSE.txt for licensing details",
3-
"copyright": "See CK Copyright.txt for copyright details",
4-
"developer_email": "[email protected]",
52
"actions": {
63
"setup": {
74
"desc": "CK kernel setup"
5+
},
6+
"status": {
7+
"desc": "check CK version status"
88
}
99
},
10-
"developer_webpage": "http://cTuning.org/lab/people/gfursin",
10+
"copyright": "See CK Copyright.txt for copyright details",
1111
"desc": "managing CK kernel",
12-
"developer": "Grigori Fursin"
12+
"developer": "Grigori Fursin",
13+
"developer_email": "[email protected]",
14+
"developer_webpage": "http://cTuning.org/lab/people/gfursin",
15+
"license": "See CK LICENSE.txt for licensing details"
1316
}

repo/module/kernel/.cm/updates.json

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
11
{
22
"control": [
33
{
4+
"author": "Grigori Fursin",
5+
"author_email": "[email protected]",
6+
"author_webpage": "http://cTuning.org/lab/people/gfursin",
7+
"copyright": "See CK Copyright.txt for copyright details",
48
"engine": "CK",
5-
"license": "See CK LICENSE.txt for licensing details",
69
"iso_datetime": "2015-01-28T15:07:40.561000",
7-
"copyright": "See CK Copyright.txt for copyright details",
10+
"license": "See CK LICENSE.txt for licensing details",
11+
"version": [
12+
"1",
13+
"0",
14+
"1215",
15+
"beta"
16+
]
17+
},
18+
{
819
"author": "Grigori Fursin",
920
"author_email": "[email protected]",
21+
"author_webpage": "http://cTuning.org/lab/people/gfursin",
22+
"copyright": "See CK Copyright.txt for copyright details",
23+
"engine": "CK",
24+
"iso_datetime": "2015-02-02T10:04:39.877000",
25+
"license": "See CK LICENSE.txt for licensing details",
1026
"version": [
1127
"1",
1228
"0",
1329
"1215",
1430
"beta"
15-
],
16-
"author_webpage": "http://cTuning.org/lab/people/gfursin"
31+
]
1732
}
1833
]
1934
}

repo/module/kernel/module.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def setup(i):
4242
Input: {
4343
(group) - if !='', configure only this group:
4444
* install - install as python library
45+
* update - check for update
4546
* content - related to content
4647
* repos - related to repositories
4748
* editing - related to editing
@@ -68,6 +69,7 @@ def setup(i):
6869
if param=='':
6970
if i.get('content','')=='yes': param='content'
7071
elif i.get('install','')=='yes': param='install'
72+
elif i.get('update','')=='yes': param='update'
7173
elif i.get('editing','')=='yes': param='editing'
7274
elif i.get('repos','')=='yes': param='repos'
7375
elif i.get('writing','')=='yes': param='writing'
@@ -153,6 +155,18 @@ def setup(i):
153155
ck.out('')
154156
ck.out('CK was not installed as Python library.')
155157

158+
# Content authorship options
159+
if param=='' or param=='update':
160+
ck.out(sep)
161+
ck.out('*** Check latest version ***')
162+
163+
ck.out('')
164+
r=ck.inp({'text': 'Would you like to check if your version is up-to-date (Y/n): '})
165+
x=r['string'].lower()
166+
if x!='n' and x!='no':
167+
ck.out('')
168+
ck.status({'out':'con'})
169+
156170
# Content authorship options
157171
if param=='' or param=='content':
158172
ck.out(sep)
@@ -326,3 +340,23 @@ def setup(i):
326340
ck.out('Configuration successfully recorded to '+fc+' ...')
327341

328342
return {'return':0}
343+
344+
##############################################################################
345+
# check CK version status
346+
347+
def status(i):
348+
"""
349+
Input: {
350+
}
351+
352+
Output: {
353+
return - return code = 0, if successful
354+
> 0, if error
355+
(error) - error text if return > 0
356+
}
357+
358+
"""
359+
360+
print ('check CK version status')
361+
362+
return {'return':0}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
license='BSD 3-clause',
1515
author='Grigori Fursin and the cTuning foundation',
1616
author_email='[email protected]',
17-
description='lightweight knowledge manager to perserve, systematize and cross-link code and data',
17+
description='lightweight knowledge manager to preserve, systematize, cross-link and share code and data',
1818
packages=['ck']
1919
)

0 commit comments

Comments
 (0)