we are currently in the process of moving our cryosparc data from 3 different space to one single storage space. For that I’d lilke to move individual Projects slowly to the new storage. While this works great for the the project file (archive / move / unarchive). I have trouble finding the correct script for changing all symlinks in a particular project.
I thought the easiest way would be to run through all jobs of a project but I don’t find any way to list all jobs from particular project (like get_jobs_by_project().
My second attempt was to alter the existing script, which iterates over all jobs and only skip those not in my Project:
failed_jobs =
for job in jobs:
# skip jobs not in our target projects
if job.get(“project_uid”) not in P:
continue
try:
print("Repairing %s %s" % (job["project_uid"], job["uid"]))
modified_count = cli.job_import_replace_symlinks(
job["project_uid"],
job["uid"],
old,
new,
)
...
To my surpise this failed with “NameError: name ‘jobs’ is not defined” - although this script is nearly literally from the documentation:
What do I miss? Do I have to populate the “job” variable - I assumed it would be present in an cryosparc-cli…
However, the script form the documentation should change all jobs in all projects… with get_job you only get a specific job and not a list if all jobs (from a specific project) as far as I understand….
I think I managed. It feels a little bit clunky, as I couldn’t find the correct methods, and the job object seem not to be descibred somewhere (?); but it works:
### Settings
ProjectID = "P14"
old= "/mnt/Data/CryoEM_Data"
new= "/mnt/CryoEM-Data"
failed_jobs = []
CRYOSPARC_DONE = [
"completed", "failed", "killed", "aborted"
]
jobs = cli.get_project_jobs_by_status(ProjectID,None,CRYOSPARC_DONE)
for job in jobs:
try:
print("Repairing %s %s" % (ProjectID, job["uid"]))
modified_count = cli.job_import_replace_symlinks(
ProjectID,
job["uid"],
old,
new,
)
print("Finished. Modified %d links." % (modified_count))
except Exception as e:
failed_jobs.append((ProjectID, job.get("uid")))
print("Failed to repair %s %s: %s" % (job.get("project_uid"), job.get("uid"), str(e)))
symlinks = cli.get_project_symlinks (ProjectID)
broken_links = 0
total_links = 0
for link in symlinks:
total_links = total_links+1
if link["exists"] != True:
broken_links = broken_links+1
print (broken_links, "broken symlinks out off ",total_links," total links.")
failed_jobs