Skip to content

Commit 034f1a8

Browse files
committed
Support directories in jupyter component application
1 parent 9da4230 commit 034f1a8

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

api/src/main/resources/plugins/jupyter.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import json
2626
import os
2727
import logging
28+
import shutil
29+
import stat
2830

2931
import deployer_utils
3032
from plugins.base_creator import Creator
@@ -67,25 +69,29 @@ def create_component(self, staged_component_path, application_name, user_name, c
6769
## Create local git repo for application_user if not exist.
6870
repo_path = '{}/jupyter-{}'.format(self._config['git_repos_root'], application_user)
6971
if os.path.isdir(repo_path) == False:
70-
os.system('mkdir -p {}'.format(repo_path))
72+
os.makedirs(repo_path)
7173
os.system('git init {}'.format(repo_path))
72-
os.system('cp {}/.git/hooks/post-update.sample {}/.git/hooks/post-update'.format(repo_path,repo_path))
73-
os.system('chmod a+x {}/.git/hooks/post-update'.format(repo_path))
74-
os.system('chmod a+w {} -R'.format(repo_path))
74+
shutil.copyfile(repo_path+'/.git/hooks/post-update.sample', repo_path+'/.git/hooks/post-update')
75+
os.chmod(repo_path+'/.git/hooks/post-update',0o755)
7576
this_dir = os.path.dirname(os.path.realpath(__file__))
76-
os.system('cp {}/jupyter_README.ipynb {}/README.ipynb'.format(this_dir, repo_path))
77+
shutil.copyfile(this_dir+'/jupyter_README.ipynb',repo_path+'/README.ipynb')
7778
os.system('cd {0} && git add README.ipynb && git commit -m "Initial commit"'.format(repo_path))
7879
## add notebooks to application_user github repo.
7980
notebook_install_path = '{}/{}'.format(repo_path, application_name)
80-
os.system('mkdir -p {}'.format(notebook_install_path))
81+
os.makedirs('{}'.format(notebook_install_path))
8182
file_list = component['component_detail']
8283
for file_name in file_list:
8384
# We copy all files in package to jupyter folder to let the user work with all kind of files/datasets.
8485
#if file_name.endswith(r'.ipynb'):
8586
if file_name != 'properties.json':
86-
self._fill_properties('%s/%s' % (staged_component_path, file_name), properties)
87-
logging.debug('Copying {} to {}'.format(file_name, notebook_install_path))
88-
os.system('cp {}/{} {}'.format( staged_component_path, file_name, notebook_install_path ))
87+
if os.path.isfile('{}/{}'.format(staged_component_path,file_name)):
88+
self._fill_properties('%s/%s' % (staged_component_path, file_name), properties)
89+
logging.debug('Copying {} to {}'.format(file_name, notebook_install_path))
90+
shutil.copyfile('{}/{}'.format(staged_component_path, file_name),
91+
'{}/{}'.format(notebook_install_path, file_name ))
92+
else:
93+
logging.debug('creating {}/{} folder'.format(notebook_install_path, file_name))
94+
os.makedirs('{}/{}'.format(notebook_install_path, file_name))
8995
# Create a properties.json file in notebooks to access application jupyter component properties.
9096
with open('{}/properties.json'.format(notebook_install_path), 'w') as prop_file:
9197
prop_dict = { k.replace('component_',''): v for k, v in properties.items() if k.startswith('component_')}

0 commit comments

Comments
 (0)