def test_daris_download(): daris_uid = 'subject01' latest_pull_mtime = 0 token = Tokens() token, url, project_cid = token.read_token_or_get_input('daris') dst_zipfile = 'tmp.zip' daris_download(daris_uid, latest_pull_mtime, token, project_cid, url, dst_zipfile) tmpdir = tf.mkdtemp(dir='.', prefix='.') with zipfile.ZipFile(dst_zipfile, 'r') as zip_ref: zip_ref.extractall(tmpdir) nfiles_in_dirs = [] for root, dirs, files in os.walk(tmpdir): for directory in dirs: os.chmod(os.path.join(root, directory), 0o0755) for f in files: os.chmod(os.path.join(root, f), 0o0755) nfiles_in_dirs.append(len(files)) # if there is any new file downloaded save timestamp if any([x > 1 for x in nfiles_in_dirs]): print('Downloaded') else: print('No file downloaded') os.remove(dst_zipfile) shutil.rmtree(tmpdir)
def update_for_xnat(self, study): token = Tokens() url, username, password = token.read_token_or_get_input('xnat') self.keyring[f'xnat.hcpep'] = {} self.keyring[f'xnat.hcpep']['URL'] = url self.keyring[f'xnat.hcpep']['USERNAME'] = username self.keyring[f'xnat.hcpep']['PASSWORD'] = password self.write_keyring_and_encrypt()
def __init__(self, tmp_dir): super().__init__(tmp_dir) token = Tokens() token, url, project_cid = token.read_token_or_get_input('daris') self.keyring['daris.StudyA']['TOKEN'] = token self.keyring['daris.StudyA']['URL'] = url self.keyring['daris.StudyA']['PROJECT_CID'] = project_cid self.write_keyring_and_encrypt()
def update_for_box(self, study): token = Tokens() client_id, client_secret, api_token = \ token.read_token_or_get_input('box') self.keyring[f'box.{study}'] = {} self.keyring[f'box.{study}']['CLIENT_ID'] = client_id self.keyring[f'box.{study}']['CLIENT_SECRET'] = client_secret self.keyring[f'box.{study}']['API_TOKEN'] = api_token self.write_keyring_and_encrypt()
def __init__(self, tmp_dir): super().__init__(tmp_dir) token = Tokens() host, username, password, path_in_host, port = \ token.read_token_or_get_input('transfer') self.keyring['lochness_sync']['HOST'] = host self.keyring['lochness_sync']['USERNAME'] = username self.keyring['lochness_sync']['PASSWORD'] = password self.keyring['lochness_sync']['PATH_IN_HOST'] = path_in_host self.keyring['lochness_sync']['PORT'] = port self.write_keyring_and_encrypt()
def test_lamp_modules(): token = Tokens() mindlamp_token, access_key, secret_key, api_url = \ token.read_token_or_get_input('mindlamp') LAMP.connect(access_key, secret_key) study_id, study_name = get_study_lamp(LAMP) subject_ids = get_participants_lamp(LAMP, study_id) for subject_id in subject_ids: if subject_id == 'U7045332804': print(subject_id) # activity_dicts = get_activities_lamp(LAMP, subject_id) activity_dicts = get_activity_events_lamp(LAMP, subject_id) sensor_dicts = get_sensor_events_lamp(LAMP, subject_id)
def __init__(self, tmp_dir): super().__init__(tmp_dir) token = Tokens() mindlamp_token, access_key, secret_key, api_url = \ token.read_token_or_get_input('mindlamp') # mindlamp_token, access_key, secret_key, api_url = \ # token.get_mindlamp_token() self.keyring['mindlamp.StudyA'] = {} self.keyring['mindlamp.StudyA']['ACCESS_KEY'] = access_key self.keyring['mindlamp.StudyA']['SECRET_KEY'] = secret_key self.keyring['mindlamp.StudyA']['URL'] = api_url self.write_keyring_and_encrypt()
def test_sftp(): tokens = Tokens(test_dir / 'lochness_test' / 'transfer') host, username, password, path_in_host, port = \ tokens.read_token_or_get_input() file_to_send = 'hoho.txt' with open(file_to_send, 'w') as f: f.write('hahahah') transport = paramiko.Transport((host, int(port))) transport.connect(username=username, password=password) sftp = paramiko.SFTPClient.from_transport(transport) sftp.put(file_to_send, str(Path(path_in_host) / Path(file_to_send).name)) sftp.close() transport.close() os.remove('hoho.txt')