Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pycalibration
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
calibration
pycalibration
Commits
0e959ab5
Commit
0e959ab5
authored
1 year ago
by
Karim Ahmed
Browse files
Options
Downloads
Patches
Plain Diff
Add path arg, warn for existing Rep folder, and an extra check
parent
cb4fd7f5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!884
[Webservice] Use leading zeros in usr/Reports folders
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
webservice/useful_scripts/rename_report_folders.py
+35
-15
35 additions, 15 deletions
webservice/useful_scripts/rename_report_folders.py
with
35 additions
and
15 deletions
webservice/useful_scripts/rename_report_folders.py
+
35
−
15
View file @
0e959ab5
import
argparse
import
argparse
import
os
from
pathlib
import
Path
from
pathlib
import
Path
# Update runs into 4 digits integers e.g. r2 to r0002.
# Update runs into 4 digits integers e.g. r2 to r0002.
def
rename_report_folders_for_instrument
(
directory_path
,
really
):
def
rename_report_folders_for_instrument
(
directory_path
,
really
):
for
folder_name
in
directory_path
.
glob
(
"
*/*/usr/Reports/*
"
):
for
folder_name
in
directory_path
.
glob
(
"
*/usr/Reports/*
"
):
if
folder_name
.
name
.
startswith
(
'
r
'
)
and
folder_name
.
name
[
1
:].
isdigit
():
if
(
new_folder_name
=
'
r
'
+
folder_name
.
name
[
1
:].
zfill
(
4
)
folder_name
.
name
.
startswith
(
"
r
"
)
and
folder_name
.
name
[
1
:].
isdigit
()
and
len
(
folder_name
.
name
[
1
:])
==
1
):
new_folder_name
=
"
r
"
+
folder_name
.
name
[
1
:].
zfill
(
4
)
new_path
=
folder_name
.
parent
.
joinpath
(
new_folder_name
)
new_path
=
folder_name
.
parent
.
joinpath
(
new_folder_name
)
if
really
:
if
really
:
folder_name
.
rename
(
new_path
)
folder_name
.
rename
(
new_path
)
print
(
f
'
Renamed
{
folder_name
}
to
{
new_folder_name
}
'
)
print
(
f
"
Renamed
{
folder_name
}
to
{
new_folder_name
}
"
)
else
:
else
:
print
(
f
'
Will rename
{
folder_name
}
to
{
new_folder_name
}
'
)
if
new_path
.
exists
():
# For Testing
print
(
f
"
{
new_folder_name
}
exists!.
"
)
else
:
print
(
f
"
Will rename
{
folder_name
}
to
{
new_folder_name
}
.
"
"
Use --really to go through with renaming.
"
)
parser
=
argparse
.
ArgumentParser
(
parser
=
argparse
.
ArgumentParser
(
description
=
'
Instrument to change the report folders for.
'
)
description
=
"
Instrument to change the report folders for.
"
)
parser
.
add_argument
(
parser
.
add_argument
(
'
--
instrument
'
,
"
--
path
"
,
type
=
str
,
type
=
str
,
help
=
'
instrument name
'
,
help
=
"
Main path for Instruments
"
,
default
=
"
/gpfs/exfel/exp/{instrument}/{cycle}
"
)
parser
.
add_argument
(
"
--instrument
"
,
type
=
str
,
help
=
"
instrument name
"
,
required
=
True
,
)
parser
.
add_argument
(
"
--cycle
"
,
type
=
str
,
help
=
"
cycle name
"
,
required
=
True
,
required
=
True
,
)
)
parser
.
add_argument
(
parser
.
add_argument
(
'
--really
'
,
action
=
'
store_true
'
,
"
--really
"
,
action
=
"
store_true
"
,
help
=
"
Actually make changes (otherwise dry-run)
"
)
help
=
"
Actually make changes (otherwise dry-run)
"
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
path
=
args
.
path
instrument
=
args
.
instrument
instrument
=
args
.
instrument
cycle
=
args
.
cycle
rename_report_folders_for_instrument
(
path
=
"
/gpfs/exfel/exp/{instrument}
"
Path
(
path
.
format
(
instrument
=
instrument
,
cycle
=
cycle
)),
args
.
really
)
rename_report_folders_for_instrument
(
Path
(
path
.
format
(
instrument
=
instrument
)),
args
.
really
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment