|
25 | 25 | import json
|
26 | 26 | import os
|
27 | 27 | import logging
|
| 28 | +import shutil |
| 29 | +import stat |
28 | 30 |
|
29 | 31 | import deployer_utils
|
30 | 32 | from plugins.base_creator import Creator
|
@@ -67,25 +69,34 @@ def create_component(self, staged_component_path, application_name, user_name, c
|
67 | 69 | ## Create local git repo for application_user if not exist.
|
68 | 70 | repo_path = '{}/jupyter-{}'.format(self._config['git_repos_root'], application_user)
|
69 | 71 | if os.path.isdir(repo_path) == False:
|
70 |
| - os.system('mkdir -p {}'.format(repo_path)) |
| 72 | + os.makedirs(repo_path) |
71 | 73 | 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) |
75 | 76 | this_dir = os.path.dirname(os.path.realpath(__file__))
|
76 |
| - os.system('cp {}/jupyter_README.md {}/README.md'.format(this_dir, repo_path)) |
77 |
| - os.system('cd {0} && git add README.md && git commit -m "Initial commit"'.format(repo_path)) |
| 77 | + shutil.copyfile(this_dir+'/jupyter_README.ipynb',repo_path+'/README.ipynb') |
| 78 | + os.system('cd {0} && git add README.ipynb && git commit -m "Initial commit"'.format(repo_path)) |
78 | 79 | ## add notebooks to application_user github repo.
|
79 |
| - notebook_install_path = '{}/{}/'.format(repo_path, application_name) |
80 |
| - os.system('mkdir -p {}'.format(notebook_install_path)) |
| 80 | + notebook_install_path = '{}/{}'.format(repo_path, application_name) |
| 81 | + os.makedirs('{}'.format(notebook_install_path)) |
81 | 82 | file_list = component['component_detail']
|
82 | 83 | for file_name in file_list:
|
83 |
| - if file_name.endswith(r'.ipynb'): |
84 |
| - self._fill_properties('%s/%s' % (staged_component_path, file_name), properties) |
85 |
| - |
86 |
| - logging.debug('Copying {} to {}'.format(file_name, notebook_install_path)) |
87 |
| - os.system('cp {}/{} {}'.format( staged_component_path, file_name, notebook_install_path )) |
88 |
| - # update local github repo: |
| 84 | + # We copy all files in package to jupyter folder to let the user work with all kind of files/datasets. |
| 85 | + #if file_name.endswith(r'.ipynb'): |
| 86 | + if file_name != 'properties.json': |
| 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)) |
| 95 | + # Create a properties.json file in notebooks to access application jupyter component properties. |
| 96 | + with open('{}/properties.json'.format(notebook_install_path), 'w') as prop_file: |
| 97 | + prop_dict = { k.replace('component_',''): v for k, v in properties.items() if k.startswith('component_')} |
| 98 | + json.dump(prop_dict, prop_file) |
| 99 | + # update local github repo: |
89 | 100 |
|
90 | 101 | os.system('cd {0} && git add {1} && git commit -m "added {1} app notebooks"'.format(repo_path, application_name))
|
91 | 102 | delete_commands.append('rm -rf {}\n'.format( notebook_install_path))
|
|
0 commit comments