|
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,29 @@ 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.ipynb {}/README.ipynb'.format(this_dir, repo_path)) |
| 77 | + shutil.copyfile(this_dir+'/jupyter_README.ipynb',repo_path+'/README.ipynb') |
77 | 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 | 80 | notebook_install_path = '{}/{}'.format(repo_path, application_name)
|
80 |
| - os.system('mkdir -p {}'.format(notebook_install_path)) |
| 81 | + os.makedirs('{}'.format(notebook_install_path)) |
81 | 82 | file_list = component['component_detail']
|
82 | 83 | for file_name in file_list:
|
83 | 84 | # We copy all files in package to jupyter folder to let the user work with all kind of files/datasets.
|
84 | 85 | #if file_name.endswith(r'.ipynb'):
|
85 | 86 | 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)) |
89 | 95 | # Create a properties.json file in notebooks to access application jupyter component properties.
|
90 | 96 | with open('{}/properties.json'.format(notebook_install_path), 'w') as prop_file:
|
91 | 97 | prop_dict = { k.replace('component_',''): v for k, v in properties.items() if k.startswith('component_')}
|
|
0 commit comments