Skip to content

Commit

Permalink
added CK kernel functions save_state(), restore_state, reinit to let …
Browse files Browse the repository at this point in the history
…multiple CK instances co-exist
  • Loading branch information
gfursin committed Sep 13, 2019
1 parent 25a7e8a commit faab793
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"index_modules":[list of module UIDs and aliases]
* removed AUTHORS.txt as non-standard (leaving CONTRIBUTIONS.txt)
* added possibility to skip SSL certificate check for remote repositories
* added CK kernel functions save_state(), restore_state, reinit
to let multiple CK instances co-exist

* V1.10.3
* fixed major bug with kernel version checking
Expand Down
93 changes: 89 additions & 4 deletions ck/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,90 @@
type_long=None # In Python 3 -> int, in Python 2 -> long
string_io=None # StringIO, which is imported differently in Python 2 and 3

##############################################################################
# Save CK state
#
# TARGET: end users

def save_state():
"""
Input: None
Output: dict with state
"""

import copy
import os

r={}

r['cfg']=copy.deepcopy(cfg)
r['paths_repos']=copy.deepcopy(paths_repos)

r['cache_repo_init']=cache_repo_init
r['paths_repos_all']=copy.deepcopy(paths_repos_all)
r['cache_repo_uoa']=copy.deepcopy(cache_repo_uoa)
r['cache_repo_info']=copy.deepcopy(cache_repo_info)

r['os.environ']=copy.deepcopy(os.environ)

return r

##############################################################################
# Restore CK state
#
# TARGET: end users

def restore_state(r):
"""
Input: dict with state
Output: output from "init" function
"""

global initialized, cfg, paths_repos, cache_repo_init, paths_repos_all, cache_repo_uoa, cache_repo_info

import copy
import os

cfg=r['cfg']
paths_repos=r['paths_repos']

cache_repo_init=r['cache_repo_init']
paths_repos_all=r['paths_repos_all']
cache_repo_uoa=r['cache_repo_uoa']
cache_repo_info=r['cache_repo_info']

os.environ=r['os.environ']

initialized=False

return init({})

##############################################################################
# Reinitialize CK
#
# TARGET: end users

def reinit():
"""
Input: None
Output: output from "init" function
"""

global initialized, paths_repos, cache_repo_init, paths_repos_all, cache_repo_uoa, cache_repo_info

initialized=False
paths_repos=[]

cache_repo_init=False
paths_repos_all=[]
cache_repo_uoa={}
cache_repo_info={}

return init({})

##############################################################################
# Universal print of unicode string in utf8 that supports Python 2.x and 3.x
#
Expand Down Expand Up @@ -5529,12 +5613,13 @@ def short_help(i):

h+='\nPython version used by CK: '+r['version'].replace('\n','\n ')+'\n'

h+='\nPath to the default repo: '+work['dir_default_repo_path']+'\n'
h+= 'Path to CK repositories: '+work['dir_repos']+'\n'
h+='\nPath to the default repo: '+work['dir_default_repo']+'\n'
h+= 'Path to the local repo: '+work['dir_local_repo']+'\n'
h+= 'Path to CK repositories: '+work['dir_repos']+'\n'

h+='\n'+cfg['help_web'].replace('\n','').strip().replace(' ','')+'\n'
h+='\n'+cfg['help_web'].replace('\n','').strip()+'\n' #.replace(' ','')+'\n'

h+='CK Google group: https://bit.ly/ck-google-group\n'
h+='CK Google group: https://bit.ly/ck-google-group\n'
h+='CK Slack channel: https://bit.ly/ck-slack'

if o=='con':
Expand Down

0 comments on commit faab793

Please # to comment.