Typo in command to update Project Dir locations

On this page:

https://guide.cryosparc.com/processing-data/tutorials-and-case-studies/tutorial-migrating-your-cryosparc-instance

Under Step Two - Modify One or Many Project Directories

There are a number of typos in the following code block; for example, this line:

new_project_dir = os.path.join(new_parent_dir, os.path.basename(project['project_dir'])

is missing a closing parenthesis.

There are enough typos that I’ll just post a corrected code block here:

>>> failed_projects = []
>>> new_parent_dir = '/cryoem/cryosparc_projects'
>>> for project in projects:
           new_project_dir = os.path.join(new_parent_dir, os.path.basename(project['project_dir']))
           try:
               print ("Modifying project directory for %s: %s --> %s" % (project['uid'], project['project_dir'], new_project_dir))
               cli.update_project(project['uid'], {'project_dir' : new_project_dir})
           except Exception as e:
               failed_projects.append(project['uid'])
               print ("Failed to update %s: %s" % (project['uid'], str(e)))
...
>>> failed_projects
[]

Also, we have our projects in subfolders by user, and this script strips off the entire parent directory, leaving only the project name. I’ll post an updated code block to handle that case tomorrow.

UPDATE: I think it’s a pretty common use case to have projects segregated by teams or users. If you remove the code prefaced by --- below from the preceding and add the code prefaced by +++ at the same location where the immediately preceding --- was, this should be a fairly flexible way of modifying the project paths.

--- new_parent_dir = '/cryoem/cryosparc_projects'
--- new_project_dir = os.path.join(new_parent_dir, os.path.basename(project['project_dir']))
+++ parent_dir = os.path.dirname(project['project_dir'])
+++ user_folder = os.path.basename(parent_dir)
+++ new_project_dir = os.path.join("/cryosparc", user_folder, os.path.basename(project['project_dir']))
1 Like

Hi @pgoetz, thanks so much for these suggestions. The latest guide has now been corrected to fix the typos.