FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
MontePy/.github/scripts/copy_url_diff.py at develop · idaholab/MontePy · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
idaholab
/
MontePy
Public
Notifications
You must be signed in to change notification settings
Fork
27
Star
66
Code
Issues
103
Pull requests
2
Discussions
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
MontePy
/
.github
/
scripts
/
copy_url_diff.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
50 lines (41 loc) · 1.4 KB
Breadcrumbs
MontePy
/
.github
/
scripts
/
copy_url_diff.py
Copy path
File metadata and controls
50 lines (41 loc) · 1.4 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import
collections
as
co
import
glob
import
os
import
re
import
shutil
import
sys
URL_FINDER
=
re
.
compile
(
r'("(https://.+?)\\"|\((https://.+?)\))'
)
REMOVE_FINDER
=
re
.
compile
(
r"^-"
)
ADD_FINDER
=
re
.
compile
(
r"^\+"
)
def
map_urls
(
patch_file
):
urls
=
{}
queue
=
co
.
deque
()
with
open
(
patch_file
,
"r"
)
as
fh
:
for
line
in
fh
:
# removed line
if
REMOVE_FINDER
.
match
(
line
):
for
match
in
URL_FINDER
.
finditer
(
line
):
groups
=
[
g
for
g
in
match
.
groups
()
if
g
is
not
None
]
queue
.
append
(
groups
[
-
1
])
# get url
# add line that will be replacements
elif
ADD_FINDER
.
match
(
line
):
for
match
in
URL_FINDER
.
finditer
(
line
):
groups
=
[
g
for
g
in
match
.
groups
()
if
g
is
not
None
]
urls
[
queue
.
popleft
()]
=
groups
[
-
1
]
return
urls
def
replace_urls
(
urls
,
path
):
shutil
.
copy
(
path
,
f"
{
path
}
.bak"
)
with
open
(
f"
{
path
}
.bak"
,
"r"
)
as
in_fh
,
open
(
path
,
"w"
)
as
out_fh
:
for
line
in
in_fh
:
old_line
=
line
for
old_url
,
new_url
in
urls
.
items
():
line
=
line
.
replace
(
old_url
,
new_url
)
out_fh
.
write
(
line
)
os
.
remove
(
f"
{
path
}
.bak"
)
def
main
():
urls
=
map_urls
(
sys
.
argv
[
1
])
for
path
in
glob
.
glob
(
"demo/answers/*.ipynb"
):
print
(
path
)
replace_urls
(
urls
,
path
)
if
__name__
==
"__main__"
:
main
()
Back
|
FazBrowse Home
|
New Git URL