def migrate(self) -> bool: """ Migrate the given LabBook to the most recent schema AND branch version. Returns: Boolean indicating whether a migration was performed (False if already up-to-date) """ if self.repository.schema == CURRENT_LABBOOK_SCHEMA: logger.info(f"{str(self.labbook)} already migrated.") return False if 'gm.workspace' not in BranchManager(self.labbook).active_branch: raise GitWorkflowException( 'Must be on a gm.workspace branch to migrate') im = InventoryManager(self.labbook.client_config.config_file) gitworkflows_utils.migrate_labbook_branches(self.labbook) self.repository = im.load_labbook_from_directory(self.labbook.root_dir) gitworkflows_utils.migrate_labbook_schema(self.labbook) self.repository = im.load_labbook_from_directory(self.labbook.root_dir) gitworkflows_utils.migrate_labbook_untracked_space(self.labbook) self.repository = im.load_labbook_from_directory(self.labbook.root_dir) # Pushes up the new master branch if self.repository.has_remote: self.sync(username='') return True
def check_projects(config: Configuration, username: str) -> Dict[str, Any]: """ Crawl through all projects to check for errors on loading or accessing imporant fields. Warning: This method may take a while. Args: config: Configuration to include root gigantum directory username: Active username - if none provided crawl for all users. Returns: Dictionary mapping a project path to errors Schema: { 'errors': { 'username/owner/labbooks/project-name': 'This is the error msg' }, '_collectionTimeSec': 2.0 } """ gigantum_root = config.app_workdir project_paths = glob.glob(f'{gigantum_root}/{username}/*/labbooks/*') inventory = InventoryManager(config.config_file) t0 = time.time() errors: Dict[str, Any] = {'errors': {}} for project_path in project_paths: try: # Try to load the labbook, and it's important fields. labbook = inventory.load_labbook_from_directory(project_path) _ = labbook.creation_date, labbook.modified_on, labbook.data except Exception as e: logger.error(e) errors['errors'][project_path.replace(gigantum_root, '')] = str(e) tfin = time.time() errors['_collectionTimeSec'] = float(f'{tfin - t0:.2f}') return errors
def test_query_owner_fail(self, mock_config_file): inv_manager = InventoryManager(mock_config_file[0]) lb = inv_manager.create_labbook("test", "test", "labbook1", description="my first labbook") new_location = shutil.move(lb.root_dir, '/tmp') try: lb = inv_manager.load_labbook_from_directory(new_location) with pytest.raises(InventoryException): inv_manager.query_owner(lb) finally: shutil.rmtree(new_location)
def test_should_migrate_on_old_project(self, mock_config_file): p = resource_filename('gtmcore', 'workflows') p2 = os.path.join(p, 'tests', 'lb-to-migrate-197b6a.zip') with tempfile.TemporaryDirectory() as tempdir: lbp = shutil.copyfile(p2, os.path.join(tempdir, 'lb-to-migrate.zip')) subprocess.run(f'unzip lb-to-migrate.zip'.split(), check=True, cwd=tempdir) im = InventoryManager(mock_config_file[0]) lb = im.load_labbook_from_directory( os.path.join(tempdir, 'lb-to-migrate')) wf = LabbookWorkflow(lb) assert wf.should_migrate() is True wf.migrate() assert wf.labbook.active_branch == 'master' assert wf.should_migrate() is False wf.labbook.git.checkout('gm.workspace') assert wf.should_migrate() is False