Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.extension
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
bob
bob.extension
Commits
e649bd37
Commit
e649bd37
authored
6 years ago
by
Theophile GENTILHOMME
Browse files
Options
Downloads
Patches
Plain Diff
Add function dump_config
parent
a934e17a
No related branches found
No related tags found
1 merge request
!86
Dump config file
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
bob/extension/config.py
+25
-1
25 additions, 1 deletion
bob/extension/config.py
bob/extension/scripts/click_helper.py
+2
-23
2 additions, 23 deletions
bob/extension/scripts/click_helper.py
doc/py_api.rst
+1
-0
1 addition, 0 deletions
doc/py_api.rst
with
28 additions
and
24 deletions
bob/extension/config.py
+
25
−
1
View file @
e649bd37
...
@@ -5,10 +5,12 @@
...
@@ -5,10 +5,12 @@
'''
'''
import
imp
import
imp
import
pkg_resources
import
pkgutil
import
pkgutil
import
time
from
os.path
import
isfile
from
os.path
import
isfile
import
logging
import
logging
import
pkg_resources
import
click
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -211,3 +213,25 @@ def mod_to_context(mod):
...
@@ -211,3 +213,25 @@ def mod_to_context(mod):
"""
"""
return
{
k
:
v
for
k
,
v
in
mod
.
__dict__
.
items
()
return
{
k
:
v
for
k
,
v
in
mod
.
__dict__
.
items
()
if
not
(
k
.
startswith
(
'
__
'
)
and
k
.
endswith
(
'
__
'
))}
if
not
(
k
.
startswith
(
'
__
'
)
and
k
.
endswith
(
'
__
'
))}
def
dump_config
(
params
,
ctx
):
config_file
=
open
(
ctx
.
params
.
get
(
'
dump_config
'
),
'
w
'
)
logger
.
debug
(
"
Generating configuration file `%s
'
...
"
,
config_file
)
config_file
.
write
(
'
## Configuration file automatically generated at %s
'
'
for %s.
\n\n\n
'
%
(
time
.
strftime
(
"
%d/%m/%Y
"
),
ctx
.
command_path
))
for
param
in
params
:
if
param
.
name
not
in
ctx
.
params
or
param
.
name
==
'
dump_config
'
:
continue
if
not
isinstance
(
param
,
click
.
Option
):
continue
config_file
.
write
(
'
## %s.
\n
'
%
param
.
help
)
config_file
.
write
(
'
## Option: %s [default: %s]
\n
'
%
(
'
,
'
.
join
(
param
.
opts
),
str
(
param
.
default
)
)
)
config_file
.
write
(
'
# %s = %s
\n\n
'
%
(
param
.
name
,
str
(
ctx
.
params
[
param
.
name
])))
config_file
.
write
(
'
\n\n\n
'
)
This diff is collapsed.
Click to expand it.
bob/extension/scripts/click_helper.py
+
2
−
23
View file @
e649bd37
from
..log
import
set_verbosity_level
from
..log
import
set_verbosity_level
from
..config
import
load
,
mod_to_context
from
..config
import
load
,
mod_to_context
,
dump_config
import
time
import
click
import
click
import
logging
import
logging
...
@@ -205,30 +204,10 @@ class ConfigCommand(click.Command):
...
@@ -205,30 +204,10 @@ class ConfigCommand(click.Command):
# make sure to set this back to False for future invocations
# make sure to set this back to False for future invocations
param
.
required
=
False
param
.
required
=
False
if
ctx
.
params
.
get
(
'
dump_config
'
)
is
not
None
:
if
ctx
.
params
.
get
(
'
dump_config
'
)
is
not
None
:
self
.
dump_config
(
ctx
)
dump_config
(
self
.
params
,
ctx
)
return
super
(
ConfigCommand
,
self
).
invoke
(
ctx
)
return
super
(
ConfigCommand
,
self
).
invoke
(
ctx
)
def
dump_config
(
self
,
ctx
):
config_file
=
open
(
ctx
.
params
.
get
(
'
dump_config
'
),
'
w
'
)
config_file
.
write
(
'
## Configuration file automatically generated at %s
'
'
for %s.
\n\n\n
'
%
(
time
.
strftime
(
"
%d/%m/%Y
"
),
ctx
.
command_path
))
for
param
in
self
.
params
:
if
param
.
name
not
in
ctx
.
params
or
param
.
name
==
'
dump_config
'
:
continue
if
not
isinstance
(
param
,
click
.
Option
):
continue
config_file
.
write
(
'
## %s.
\n
'
%
param
.
help
)
config_file
.
write
(
'
## Option: %s [default: %s]
\n
'
%
(
'
,
'
.
join
(
param
.
opts
),
str
(
param
.
default
)
)
)
config_file
.
write
(
'
# %s = %s
\n\n
'
%
(
param
.
name
,
str
(
ctx
.
params
[
param
.
name
])))
config_file
.
write
(
'
\n\n\n
'
)
class
ResourceOption
(
click
.
Option
):
class
ResourceOption
(
click
.
Option
):
"""
A click.Option that is aware if the user actually provided this option
"""
A click.Option that is aware if the user actually provided this option
...
...
This diff is collapsed.
Click to expand it.
doc/py_api.rst
+
1
−
0
View file @
e649bd37
...
@@ -58,6 +58,7 @@ Configuration
...
@@ -58,6 +58,7 @@ Configuration
bob.extension.rc_config.ENVNAME
bob.extension.rc_config.ENVNAME
bob.extension.rc_config.RCFILENAME
bob.extension.rc_config.RCFILENAME
bob.extension.config.load
bob.extension.config.load
bob.extension.config.dump_config
Stacked Processors
Stacked Processors
^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^
...
...
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