|
52 | 52 | import time |
53 | 53 | import shutil |
54 | 54 | import random |
55 | | -import requests |
| 55 | +try: |
| 56 | + import requests |
| 57 | +except ImportError as err: |
| 58 | + requests = None |
56 | 59 |
|
57 | 60 | from mig.shared import returnvalues |
58 | 61 | from mig.shared.base import client_id_dir, extract_field |
| 62 | +from mig.shared.conf import get_configuration_object |
59 | 63 | from mig.shared.defaults import session_id_bytes |
60 | 64 | from mig.shared.fileio import make_symlink, pickle, unpickle, write_file, \ |
61 | 65 | delete_symlink, delete_file |
|
68 | 72 | get_workflow_session_id |
69 | 73 |
|
70 | 74 |
|
| 75 | +def __bail_out_requests(*args, **kwargs): |
| 76 | + """Helper for dynamic bail out on actual use""" |
| 77 | + raise Exception("jupyter functions require requests") |
| 78 | + |
| 79 | + |
| 80 | +def __require_requests(func): |
| 81 | + """Internal helper to verify requests module availability on use""" |
| 82 | + if requests is None: |
| 83 | + return __bail_out_requests |
| 84 | + return func |
| 85 | + |
| 86 | + |
71 | 87 | def is_active(pickle_state, timeout=7200): |
72 | 88 | """ |
73 | 89 | :param pickle_state: expects a pickle object dictionary that |
@@ -212,7 +228,7 @@ def get_newest_mount(jupyter_mounts): |
212 | 228 | old_mounts.append(mount) |
213 | 229 | return latest, old_mounts |
214 | 230 |
|
215 | | - |
| 231 | +@__require_requests |
216 | 232 | def get_host_from_service(configuration, service, base_url=None): |
217 | 233 | """ |
218 | 234 | Returns a URL from one of the services available hosts, |
@@ -318,7 +334,7 @@ def signature(): |
318 | 334 | } |
319 | 335 | return ['', defaults] |
320 | 336 |
|
321 | | - |
| 337 | +@__require_requests |
322 | 338 | def main(client_id, user_arguments_dict): |
323 | 339 | """Main function used by front end""" |
324 | 340 | (configuration, logger, output_objects, op_name) = \ |
@@ -350,12 +366,7 @@ def main(client_id, user_arguments_dict): |
350 | 366 | {'object_type': 'error_text', 'text': |
351 | 367 | 'The required sftp service is not enabled on the system'}) |
352 | 368 | return (output_objects, returnvalues.SYSTEM_ERROR) |
353 | | - |
354 | | - if configuration.site_enable_sftp: |
355 | | - sftp_port = configuration.user_sftp_port |
356 | | - |
357 | | - if configuration.site_enable_sftp_subsys: |
358 | | - sftp_port = configuration.user_sftp_subsys_port |
| 369 | + sftp_port = configuration.user_sftp_show_port |
359 | 370 |
|
360 | 371 | requested_service = accepted['service'][-1] |
361 | 372 | service = {k: v for options in configuration.jupyter_services |
@@ -653,7 +664,6 @@ def main(client_id, user_arguments_dict): |
653 | 664 |
|
654 | 665 |
|
655 | 666 | if __name__ == "__main__": |
656 | | - from mig.shared.conf import get_configuration_object |
657 | 667 | if not os.environ.get('MIG_CONF', ''): |
658 | 668 | conf_path = os.path.join(os.path.dirname(sys.argv[0]), |
659 | 669 | '..', '..', 'server', 'MiGserver.conf') |
|
0 commit comments