def update_study(study_id, config, skip_delete=False, delete_all=False): """Update all settings stored in the database for the given study. Args: study_id (str): The ID of the study to update. config (:obj:`datman.config.config`): a Datman config object. skip_delete (bool, optional): Don't prompt the user and skip deletion of any records no longer defined in the config files. delete_all (bool, optional): Don't prompt the user and delete any records no longer defined in the config files. """ try: config.set_study(study_id) except Exception as e: logger.error(f"Can't access config for {study_id}. Reason - {e}") return try: ignore = config.get_key("DbIgnore") except UndefinedSetting: ignore = False if ignore: return study = dashboard.queries.get_studies(study_id, create=True)[0] update_setting(study, "description", config, "Description") update_setting(study, "name", config, "FullName") update_setting(study, "is_open", config, "IsOpen") update_redcap(config) try: sites = config.get_sites() except UndefinedSetting: logger.error(f"No sites defined for {study_id}") return undefined = [site_id for site_id in study.sites if site_id not in sites] delete_records( undefined, prompt=("Site {} will be deleted from study " f"{study.id}. Any records referencing this study/site pair " "will be removed."), delete_func=lambda x: study.delete_site(x), skip_delete=skip_delete, delete_all=delete_all) for site_id in sites: update_site(study, site_id, config, skip_delete=skip_delete, delete_all=delete_all)
def get_projects(config): """Find all XNAT projects and the list of scan sites uploaded to each one. Args: config (:obj:`datman.config.config`): The config for a study Returns: dict: A map of XNAT project names to the URL(s) of the server holding that project. """ projects = {} for site in config.get_sites(): xnat_project = config.get_key("XNAT_Archive", site=site) projects.setdefault(xnat_project, set()).add(site) return projects
def main(): global DRYRUN arguments = docopt(__doc__) xnat_project = arguments['<project>'] xnat_server = arguments['<server>'] username = arguments['<username>'] password = arguments['<password>'] destination = arguments['<destination>'] study = arguments['<study>'] given_site = arguments['--site'] use_server = arguments['--log-to-server'] DRYRUN = arguments['--dry-run'] if arguments['--debug']: logger.setLevel(logging.DEBUG) elif arguments['--verbose']: logger.setLevel(logging.INFO) elif arguments['--quiet']: logger.setLevel(logging.ERROR) if not study: with datman.xnat.xnat(xnat_server, username, password) as xnat: download_subjects(xnat, xnat_project, destination) return config = datman.config.config(study=study) if use_server: add_server_handler(config) sites = [given_site] if given_site else config.get_sites() for site in sites: try: credentials_file, server, project, destination = get_xnat_config( config, site) except KeyError as e: logger.error("{}".format(e)) continue username, password = get_credentials(credentials_file) with datman.xnat.xnat(server, username, password) as xnat: download_subjects(xnat, project, destination)
def main(): global DRYRUN arguments = docopt(__doc__) xnat_project = arguments['<project>'] xnat_server = arguments['<server>'] username = arguments['<username>'] password = arguments['<password>'] destination = arguments['<destination>'] study = arguments['<study>'] given_site = arguments['--site'] use_server = arguments['--log-to-server'] DRYRUN = arguments['--dry-run'] if arguments['--debug']: logger.setLevel(logging.DEBUG) elif arguments['--verbose']: logger.setLevel(logging.INFO) elif arguments['--quiet']: logger.setLevel(logging.ERROR) if not study: with datman.xnat.xnat(xnat_server, username, password) as xnat: get_sessions(xnat, xnat_project, destination) return config = datman.config.config(study=study) if use_server: add_server_handler(config) sites = [given_site] if given_site else config.get_sites() for site in sites: try: credentials_file, server, project, destination = get_xnat_config( config, site) except KeyError as e: logger.error("{}".format(e.message)) continue username, password = get_credentials(credentials_file) with datman.xnat.xnat(server, username, password) as xnat: get_sessions(xnat, project, destination)
def test_updating_study_calls_update_site_for_configured_sites( self, mock_update, config, db_study): pc.update_study("SPINS", config, skip_delete=True) assert mock_update.call_count == len(config.get_sites())