Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Francesco Witz
Changelog Generator
Commits
47ce56b7
Commit
47ce56b7
authored
Feb 13, 2022
by
Francesco Witz
Browse files
feat: add json file copy during tool update
parent
ce9fd37b
Changes
1
Hide whitespace changes
Inline
Side-by-side
chlog.py
View file @
47ce56b7
#!/usr/bin/python3
import
os
from
posixpath
import
splitext
import
sys
import
shutil
import
subprocess
...
...
@@ -131,7 +132,8 @@ def update():
# Updating tool by copying python files
os
.
chdir
(
path
)
for
filename
in
os
.
listdir
(
'repo/'
):
if
filename
[
-
2
:]
==
"py"
:
ext
:
str
=
os
.
path
.
splitext
(
filename
)[
1
][
1
:]
if
ext
==
"py"
:
if
filename
==
"chlog.py"
:
os
.
remove
(
"chlog"
)
shutil
.
copy
(
"repo/chlog.py"
,
path
)
...
...
@@ -139,6 +141,26 @@ def update():
os
.
chmod
(
"chlog"
,
0o711
)
else
:
shutil
.
copy
(
os
.
path
.
join
(
"repo/"
,
filename
),
path
)
elif
ext
==
"json"
:
if
filename
==
"package.json"
:
# Update version in the installed tool package.json
with
open
(
"repo/package.json"
,
'r'
)
as
new_package
:
data
=
json
.
load
(
new_package
)
with
open
(
"package.json"
,
'r'
)
as
package
:
package_json
=
json
.
load
(
package
)
package_json
[
"chlog-version"
]
=
data
[
"chlog-version"
]
with
open
(
"package.json"
,
"w"
)
as
package
:
package
.
write
(
json
.
dumps
(
package_json
))
elif
filename
==
"config.json"
:
# First opening both actual and new config file
with
open
(
"config.json"
,
'r'
)
as
config_file
:
config
=
json
.
load
(
config_file
)
with
open
(
"repo/config.json"
,
'r'
)
as
new_config_file
:
new_config
=
json
.
load
(
new_config_file
)
# Then copying the new lines into the config file if their is any
for
k
,
v
in
new_config
.
items
():
if
not
k
in
config
:
config
[
k
]
=
v
print
(
"Tool updated ! ✨"
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment