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
a35f27a5
Commit
a35f27a5
authored
1 year ago
by
Karim Ahmed
Browse files
Options
Downloads
Patches
Plain Diff
Add logging, fix old run number length check and move to cycle year instead of 1 cycle
parent
0e959ab5
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
+53
-35
53 additions, 35 deletions
webservice/useful_scripts/rename_report_folders.py
with
53 additions
and
35 deletions
webservice/useful_scripts/rename_report_folders.py
+
53
−
35
View file @
a35f27a5
import
argparse
import
argparse
import
logging
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.
# Configure logging
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
"
%(asctime)s - %(levelname)s - %(message)s
"
,
handlers
=
[
logging
.
StreamHandler
(),
logging
.
FileHandler
(
'
rename_reports.log
'
)]
)
def
rename_report_folders_for_instrument
(
directory_path
,
really
):
def
rename_report_folders_for_instrument
(
directory_path
,
cycle_year
,
really
):
for
folder_name
in
directory_path
.
glob
(
"
*/usr/Reports/*
"
):
logging
.
info
(
f
"
Starting the script for
{
directory_path
}
and
{
cycle_year
}
.
"
)
for
folder_name
in
directory_path
.
glob
(
f
"
{
cycle_year
}
/**/*/usr/Reports/*
"
):
if
(
if
(
folder_name
.
name
.
startswith
(
"
r
"
)
and
folder_name
.
name
.
startswith
(
"
r
"
)
and
folder_name
.
name
[
1
:].
isdigit
()
and
folder_name
.
name
[
1
:].
isdigit
()
and
len
(
folder_name
.
name
[
1
:])
==
1
len
(
folder_name
.
name
[
1
:])
<
4
):
):
new_folder_name
=
"
r
"
+
folder_name
.
name
[
1
:].
zfill
(
4
)
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
}
"
)
logging
.
info
(
f
"
Renamed
{
folder_name
}
to
{
new_folder_name
}
"
)
else
:
else
:
if
new_path
.
exists
():
if
new_path
.
exists
():
# For Testing
# For Testing
pr
in
t
(
f
"
{
new_folder_name
}
exists!.
"
)
logging
.
warn
in
g
(
f
"
{
new_folder_name
}
exists!.
"
)
else
:
else
:
print
(
logging
.
info
(
f
"
Will rename
{
folder_name
}
to
{
new_folder_name
}
.
"
f
"
Will rename
{
folder_name
}
to
{
new_folder_name
}
.
"
"
Use --really to go through with renaming.
"
)
"
Use --really to go through with renaming.
"
)
logging
.
info
(
"
Renaming done .
"
)
logging
.
info
(
"
.
"
)
logging
.
info
(
"
.
"
)
logging
.
info
(
"
.
"
)
def
main
():
parser
=
argparse
.
ArgumentParser
(
description
=
"
Instrument to change the report folders for.
"
)
parser
.
add_argument
(
"
--path
"
,
type
=
str
,
help
=
"
Main path for Instruments
"
,
default
=
"
/gpfs/exfel/exp/{instrument}
"
)
parser
.
add_argument
(
"
--instrument
"
,
type
=
str
,
help
=
"
instrument name
"
,
required
=
True
,
)
parser
.
add_argument
(
"
--cycle-year
"
,
type
=
str
,
help
=
"
Cycle year number
"
,
required
=
True
,
)
parser
.
add_argument
(
"
--really
"
,
action
=
"
store_true
"
,
help
=
"
Actually make changes (otherwise dry-run)
"
)
args
=
parser
.
parse_args
()
path
=
args
.
path
instrument
=
args
.
instrument
cycle_year
=
args
.
cycle_year
parser
=
argparse
.
ArgumentParser
(
rename_report_folders_for_instrument
(
description
=
"
Instrument to change the report folders for.
"
)
Path
(
path
.
format
(
instrument
=
instrument
)),
cycle_year
,
args
.
really
)
parser
.
add_argument
(
"
--path
"
,
type
=
str
,
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
,
)
parser
.
add_argument
(
"
--really
"
,
action
=
"
store_true
"
,
help
=
"
Actually make changes (otherwise dry-run)
"
)
args
=
parser
.
parse_args
()
path
=
args
.
path
instrument
=
args
.
instrument
cycle
=
args
.
cycle
rename_report_folders_for_instrument
(
if
__name__
==
"
__main__
"
:
Path
(
path
.
format
(
instrument
=
instrument
,
cycle
=
cycle
)),
args
.
really
)
main
(
)
\ No newline at end of file
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