Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
flamenco-worker-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
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
blender
flamenco-worker-python
Commits
d7423a95
Commit
d7423a95
authored
8 years ago
by
Sybren A. Stüvel
Browse files
Options
Downloads
Patches
Plain Diff
Worker: Moved loading of config to config module.
parent
63e5fc19
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/flamenco-worker-python/flamenco_worker/cli.py
+6
-37
6 additions, 37 deletions
packages/flamenco-worker-python/flamenco_worker/cli.py
packages/flamenco-worker-python/flamenco_worker/config.py
+39
-0
39 additions, 0 deletions
packages/flamenco-worker-python/flamenco_worker/config.py
with
45 additions
and
37 deletions
packages/flamenco-worker-python/flamenco_worker/cli.py
+
6
−
37
View file @
d7423a95
"""
Commandline interface entry points.
"""
import
argparse
import
collections
import
configparser
import
logging
import
logging.config
import
os
DEFAULT_CONFIG
=
{
'
flamenco-worker
'
:
collections
.
OrderedDict
([
(
'
manager_url
'
,
'
http://flamenco-manager/
'
),
(
'
job_types
'
,
'
sleep blender_render_simple
'
),
(
'
worker_id
'
,
''
),
(
'
worker_secret
'
,
''
),
])
}
def
main
():
...
...
@@ -61,40 +49,21 @@ def main():
log
.
debug
(
'
Starting
'
)
# Load configuration
confparser
=
configparser
.
ConfigParser
()
confparser
.
read_dict
(
DEFAULT_CONFIG
)
if
args
.
config
:
log
.
info
(
'
Loading configuration from %s
'
,
args
.
config
)
confparser
.
read
(
args
.
config
,
encoding
=
'
utf8
'
)
else
:
from
.
import
config
as
config_module
config_files
=
[
config_module
.
GLOBAL_CONFIG_FILE
,
config_module
.
HOME_CONFIG_FILE
]
log
.
info
(
'
Loading configuration from %s
'
,
'
,
'
.
join
(
config_files
))
confparser
.
read
(
config_files
,
encoding
=
'
utf8
'
)
from
.
import
config
from
.config
import
CONFIG_SECTION
if
args
.
verbose
:
import
sys
log
.
info
(
'
Effective configuration:
'
)
to_show
=
configparser
.
ConfigParser
()
to_show
.
read_dict
(
confparser
)
if
to_show
.
get
(
CONFIG_SECTION
,
'
worker_secret
'
):
to_show
.
set
(
CONFIG_SECTION
,
'
worker_secret
'
,
'
-hidden-
'
)
to_show
.
write
(
sys
.
stderr
)
confparser
=
config
.
load_config
(
args
.
config
,
args
.
verbose
)
from
.
import
worker
,
upstream
fmanager
=
upstream
.
FlamencoManager
(
manager_url
=
confparser
.
get
(
CONFIG_SECTION
,
'
manager_url
'
),
manager_url
=
confparser
.
get
(
config
.
CONFIG_SECTION
,
'
manager_url
'
),
)
fworker
=
worker
.
FlamencoWorker
(
manager
=
fmanager
,
job_types
=
confparser
.
get
(
CONFIG_SECTION
,
'
job_types
'
).
split
(),
worker_id
=
confparser
.
get
(
CONFIG_SECTION
,
'
worker_id
'
),
worker_secret
=
confparser
.
get
(
CONFIG_SECTION
,
'
worker_secret
'
),
job_types
=
confparser
.
get
(
config
.
CONFIG_SECTION
,
'
job_types
'
).
split
(),
worker_id
=
confparser
.
get
(
config
.
CONFIG_SECTION
,
'
worker_id
'
),
worker_secret
=
confparser
.
get
(
config
.
CONFIG_SECTION
,
'
worker_secret
'
),
)
try
:
fworker
.
startup
()
...
...
This diff is collapsed.
Click to expand it.
packages/flamenco-worker-python/flamenco_worker/config.py
+
39
−
0
View file @
d7423a95
"""
Writes configuration to a config file in the home directory.
"""
import
collections
import
configparser
import
os.path
import
logging
...
...
@@ -8,6 +9,15 @@ HOME_CONFIG_FILE = os.path.expanduser('~/.flamenco-worker.cfg')
GLOBAL_CONFIG_FILE
=
'
flamenco-worker.cfg
'
CONFIG_SECTION
=
'
flamenco-worker
'
DEFAULT_CONFIG
=
{
'
flamenco-worker
'
:
collections
.
OrderedDict
([
(
'
manager_url
'
,
'
http://flamenco-manager/
'
),
(
'
job_types
'
,
'
sleep blender_render_simple
'
),
(
'
worker_id
'
,
''
),
(
'
worker_secret
'
,
''
),
])
}
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -30,3 +40,32 @@ def merge_with_home_config(new_conf: dict):
os
.
replace
(
tmpname
,
HOME_CONFIG_FILE
)
log
.
info
(
'
Updated configuration file %s
'
,
HOME_CONFIG_FILE
)
def
load_config
(
config_file
:
str
=
None
,
show_effective_config
:
bool
=
False
)
->
configparser
.
ConfigParser
:
"""
Loads one or more configuration files.
"""
confparser
=
configparser
.
ConfigParser
()
confparser
.
read_dict
(
DEFAULT_CONFIG
)
if
config_file
:
log
.
info
(
'
Loading configuration from %s
'
,
config_file
)
loaded
=
confparser
.
read
(
config_file
,
encoding
=
'
utf8
'
)
else
:
config_files
=
[
GLOBAL_CONFIG_FILE
,
HOME_CONFIG_FILE
]
log
.
info
(
'
Loading configuration from %s
'
,
'
,
'
.
join
(
config_files
))
loaded
=
confparser
.
read
(
config_files
,
encoding
=
'
utf8
'
)
log
.
info
(
'
Succesfully loaded: %s
'
,
loaded
)
if
show_effective_config
:
import
sys
log
.
info
(
'
Effective configuration:
'
)
to_show
=
configparser
.
ConfigParser
()
to_show
.
read_dict
(
confparser
)
if
to_show
.
get
(
CONFIG_SECTION
,
'
worker_secret
'
):
to_show
.
set
(
CONFIG_SECTION
,
'
worker_secret
'
,
'
-hidden-
'
)
to_show
.
write
(
sys
.
stderr
)
return
confparser
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