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
Sylvaine Ferrachat
make_script
Commits
11e254ab
Commit
11e254ab
authored
Mar 07, 2019
by
Sylvaine Ferrachat
Browse files
Added minimalistic user-defined config file handling for `mk_script.py`
parent
5b9da5ac
Changes
1
Hide whitespace changes
Inline
Side-by-side
mk_script.py
View file @
11e254ab
...
...
@@ -33,6 +33,8 @@ YYYY_MM = '{:%Y-%m}'.format(datetime.date.today())
tmpl_dir
=
resource_filename
(
__name__
,
'templates'
)
tmpl_ext
=
'.tmpl'
config_header
=
'# Configure file for {}
\n
'
.
format
(
os
.
path
.
basename
(
sys
.
argv
[
0
]))
config_file
=
os
.
path
.
join
(
os
.
path
.
expanduser
(
'~'
),
'.mk_script.cfg'
)
#------------------------------------------
#-- Classes
...
...
@@ -89,7 +91,7 @@ class Script:
#-- Main
@
begin
.
start
(
cmd_delim
=
'--'
,
config_file
=
'.mk_script.cfg'
,
config_file
=
config_file
,
)
@
begin
.
logging
def
run
(
...
...
@@ -107,6 +109,19 @@ def run(
based on template.
"""
#-- User-config handling
if
author
==
None
:
author
=
input
(
u
'Author name is not yet set. Please enter author name.
\n
'
)
logging
.
info
(
'Writing author name to config file {}'
.
format
(
config_file
))
config
=
begin
.
cmdline
.
configparser
.
ConfigParser
()
config
[
'run'
]
=
{}
config
[
'run'
][
'author'
]
=
author
with
open
(
config_file
,
'w'
)
as
f
:
f
.
write
(
config_header
)
config
.
write
(
f
)
f
.
close
()
#-- Filename handling
fn_decomp
=
filename
.
split
(
'.'
)
if
len
(
fn_decomp
)
==
1
:
basename
=
filename
...
...
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