fix folder archival

This commit is contained in:
bpinsard 2024-01-26 11:56:49 -05:00
parent 6f01d16af5
commit b53e89bb67
1 changed files with 15 additions and 9 deletions

View File

@ -192,6 +192,7 @@ def setup_gitlab_repos(
) -> None: ) -> None:
gitlab_conn = connect_gitlab(gitlab_url) gitlab_conn = connect_gitlab(gitlab_url)
# generate gitlab group/repo paths
gitlab_group_path = gitlab_group_template.format(**session_metas) gitlab_group_path = gitlab_group_template.format(**session_metas)
dicom_sourcedata_path = "/".join([gitlab_group_path, "sourcedata/dicoms"]) dicom_sourcedata_path = "/".join([gitlab_group_path, "sourcedata/dicoms"])
dicom_session_path = "/".join( dicom_session_path = "/".join(
@ -199,17 +200,23 @@ def setup_gitlab_repos(
) )
dicom_study_path = "/".join([dicom_sourcedata_path, "study"]) dicom_study_path = "/".join([dicom_sourcedata_path, "study"])
# create repo (should not exists unless rerun)
dicom_session_repo = get_or_create_gitlab_project(gitlab_conn, dicom_session_path) dicom_session_repo = get_or_create_gitlab_project(gitlab_conn, dicom_session_path)
dicom_session_ds.siblings( dicom_session_ds.siblings(
action="configure", # allow to overwrite existing config action="configure", # allow to overwrite existing config
name=GITLAB_REMOTE_NAME, name=GITLAB_REMOTE_NAME,
url=dicom_session_repo._attrs["ssh_url_to_repo"], url=dicom_session_repo._attrs["ssh_url_to_repo"],
) )
dicom_session_ds.repo.checkout("dev", ["-b"]) # and push
dicom_session_ds.push(to=GITLAB_REMOTE_NAME, force="gitpush") dicom_session_ds.push(to=GITLAB_REMOTE_NAME)
# add maint permissions for the dicom bot user on the study repos
study_group = get_or_create_gitlab_group(gitlab_conn, gitlab_group_path) study_group = get_or_create_gitlab_group(gitlab_conn, gitlab_group_path)
bot_user = gitlab_conn.users.list(username=GITLAB_BOT_USERNAME)[0] bot_user = gitlab_conn.users.list(username=GITLAB_BOT_USERNAME).get(0, None)
if not bot_user:
raise RuntimeError(
f"bot_user: {GITLAB_BOT_USERNAME} does not exists in gitlab instance"
)
if not any(m.id == bot_user.id for m in study_group.members.list()): if not any(m.id == bot_user.id for m in study_group.members.list()):
study_group.members.create( study_group.members.create(
{ {
@ -243,7 +250,7 @@ def setup_gitlab_repos(
) )
# Push to gitlab # Push to gitlab
dicom_study_ds.push(to="origin") dicom_study_ds.push(to="origin", force="gitpush")
def init_bids( def init_bids(
@ -319,17 +326,16 @@ def import_local_data(
dicom_session_ds: dlad.Dataset, dicom_session_ds: dlad.Dataset,
input_path: pathlib.Path, input_path: pathlib.Path,
sort_series: bool = True, sort_series: bool = True,
p7z_opts: str = "-mx5", p7z_opts: str = "-mx5 -ms=off",
): ):
dest = input_path.name dest = input_path.name
if input_path.is_dir(): if input_path.is_dir():
dest = dest + ".7z" dest = dest + ".7z"
# create 7z archive with 1block/file parameters # create 7z archive with 1block/file parameters
subprocess.run( cmd = ["7z", "u", str(dest), str(input_path)] + p7z_opts.split()
["7z", "u", str(dest), "."] + p7z_opts.split(), print(cmd)
cwd=dicom_session_ds.path, subprocess.run(cmd, cwd=dicom_session_ds.path)
)
elif input_path.is_file(): elif input_path.is_file():
dest = dicom_session_ds.pathobj / dest dest = dicom_session_ds.pathobj / dest
try: # try hard-linking to avoid copying try: # try hard-linking to avoid copying