Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
4a338dfd
Commit
4a338dfd
authored
Dec 05, 2014
by
John Jarvis
Committed by
Zia Fazal
Apr 07, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moving the convert_tokens function to a common file
parent
4fc764f0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
32 deletions
+32
-32
cms/envs/yaml_config.py
+3
-16
common/djangoapps/util/config_parse.py
+26
-0
lms/envs/yaml_config.py
+3
-16
No files found.
cms/envs/yaml_config.py
View file @
4a338dfd
...
@@ -18,6 +18,7 @@ import yaml
...
@@ -18,6 +18,7 @@ import yaml
from
.common
import
*
from
.common
import
*
from
logsettings
import
get_logger_config
from
logsettings
import
get_logger_config
from
util.config_parse
import
convert_tokens
import
os
import
os
from
path
import
path
from
path
import
path
...
@@ -35,20 +36,6 @@ def construct_yaml_str(self, node):
...
@@ -35,20 +36,6 @@ def construct_yaml_str(self, node):
Loader
.
add_constructor
(
u'tag:yaml.org,2002:str'
,
construct_yaml_str
)
Loader
.
add_constructor
(
u'tag:yaml.org,2002:str'
,
construct_yaml_str
)
SafeLoader
.
add_constructor
(
u'tag:yaml.org,2002:str'
,
construct_yaml_str
)
SafeLoader
.
add_constructor
(
u'tag:yaml.org,2002:str'
,
construct_yaml_str
)
def
convert_tokens
(
tokens
):
"""
This function is called on the token
dictionary, at the top level it converts
all strings containing 'None' to a literal
None due to a bug in Ansible which creates
the yaml files
"""
for
k
,
v
in
tokens
.
iteritems
():
if
v
==
'None'
:
tokens
[
k
]
=
None
# SERVICE_VARIANT specifies name of the variant used, which decides what YAML
# SERVICE_VARIANT specifies name of the variant used, which decides what YAML
# configuration files are read during startup.
# configuration files are read during startup.
SERVICE_VARIANT
=
os
.
environ
.
get
(
'SERVICE_VARIANT'
,
None
)
SERVICE_VARIANT
=
os
.
environ
.
get
(
'SERVICE_VARIANT'
,
None
)
...
@@ -134,7 +121,7 @@ CELERY_QUEUES = {
...
@@ -134,7 +121,7 @@ CELERY_QUEUES = {
with
open
(
CONFIG_ROOT
/
CONFIG_PREFIX
+
"env.yaml"
)
as
env_file
:
with
open
(
CONFIG_ROOT
/
CONFIG_PREFIX
+
"env.yaml"
)
as
env_file
:
ENV_TOKENS
=
yaml
.
load
(
env_file
)
ENV_TOKENS
=
yaml
.
load
(
env_file
)
convert_tokens
(
ENV_TOKENS
)
ENV_TOKENS
=
convert_tokens
(
ENV_TOKENS
)
##########################################
##########################################
# Merge settings from common.py
# Merge settings from common.py
...
@@ -225,7 +212,7 @@ MICROSITE_ROOT_DIR = path(MICROSITE_ROOT_DIR)
...
@@ -225,7 +212,7 @@ MICROSITE_ROOT_DIR = path(MICROSITE_ROOT_DIR)
with
open
(
CONFIG_ROOT
/
CONFIG_PREFIX
+
"auth.yaml"
)
as
auth_file
:
with
open
(
CONFIG_ROOT
/
CONFIG_PREFIX
+
"auth.yaml"
)
as
auth_file
:
AUTH_TOKENS
=
yaml
.
load
(
auth_file
)
AUTH_TOKENS
=
yaml
.
load
(
auth_file
)
convert_tokens
(
AUTH_TOKENS
)
AUTH_TOKENS
=
convert_tokens
(
AUTH_TOKENS
)
vars
()
.
update
(
AUTH_TOKENS
)
vars
()
.
update
(
AUTH_TOKENS
)
...
...
common/djangoapps/util/config_parse.py
0 → 100644
View file @
4a338dfd
"""
Helper functions for configuration parsing
"""
import
collections
def
convert_tokens
(
tokens
):
"""
This function is called on the token
dictionary that is imported from a yaml file.
It returns a new dictionary where
all strings containing 'None' are converted
to a literal None due to a bug in Ansible
"""
if
tokens
==
'None'
:
return
None
elif
isinstance
(
tokens
,
basestring
)
or
(
not
isinstance
(
tokens
,
collections
.
Iterable
)):
return
tokens
elif
isinstance
(
tokens
,
dict
):
return
{
convert_tokens
(
k
):
convert_tokens
(
v
)
for
k
,
v
in
tokens
.
items
()
}
else
:
return
[
convert_tokens
(
v
)
for
v
in
tokens
]
lms/envs/yaml_config.py
View file @
4a338dfd
...
@@ -14,6 +14,7 @@ import yaml
...
@@ -14,6 +14,7 @@ import yaml
from
.common
import
*
from
.common
import
*
from
logsettings
import
get_logger_config
from
logsettings
import
get_logger_config
from
util.config_parse
import
convert_tokens
import
os
import
os
from
path
import
path
from
path
import
path
...
@@ -29,20 +30,6 @@ def construct_yaml_str(self, node):
...
@@ -29,20 +30,6 @@ def construct_yaml_str(self, node):
Loader
.
add_constructor
(
u'tag:yaml.org,2002:str'
,
construct_yaml_str
)
Loader
.
add_constructor
(
u'tag:yaml.org,2002:str'
,
construct_yaml_str
)
SafeLoader
.
add_constructor
(
u'tag:yaml.org,2002:str'
,
construct_yaml_str
)
SafeLoader
.
add_constructor
(
u'tag:yaml.org,2002:str'
,
construct_yaml_str
)
def
convert_tokens
(
tokens
):
"""
This function is called on the token
dictionary, at the top level it converts
all strings containing 'None' to a literal
None due to a bug in Ansible which creates
the yaml files
"""
for
k
,
v
in
tokens
.
iteritems
():
if
v
==
'None'
:
tokens
[
k
]
=
None
# SERVICE_VARIANT specifies name of the variant used, which decides what YAML
# SERVICE_VARIANT specifies name of the variant used, which decides what YAML
# configuration files are read during startup.
# configuration files are read during startup.
SERVICE_VARIANT
=
os
.
environ
.
get
(
'SERVICE_VARIANT'
,
None
)
SERVICE_VARIANT
=
os
.
environ
.
get
(
'SERVICE_VARIANT'
,
None
)
...
@@ -150,7 +137,7 @@ with open(CONFIG_ROOT / CONFIG_PREFIX + "env.yaml") as env_file:
...
@@ -150,7 +137,7 @@ with open(CONFIG_ROOT / CONFIG_PREFIX + "env.yaml") as env_file:
ENV_TOKENS
=
yaml
.
load
(
env_file
)
ENV_TOKENS
=
yaml
.
load
(
env_file
)
# Works around an Ansible bug
# Works around an Ansible bug
convert_tokens
(
ENV_TOKENS
)
ENV_TOKENS
=
convert_tokens
(
ENV_TOKENS
)
##########################################
##########################################
# Merge settings from common.py
# Merge settings from common.py
...
@@ -251,7 +238,7 @@ with open(CONFIG_ROOT / CONFIG_PREFIX + "auth.yaml") as auth_file:
...
@@ -251,7 +238,7 @@ with open(CONFIG_ROOT / CONFIG_PREFIX + "auth.yaml") as auth_file:
AUTH_TOKENS
=
yaml
.
load
(
auth_file
)
AUTH_TOKENS
=
yaml
.
load
(
auth_file
)
# Works around an Ansible bug
# Works around an Ansible bug
convert_tokens
(
AUTH_TOKENS
)
AUTH_TOKENS
=
convert_tokens
(
AUTH_TOKENS
)
vars
()
.
update
(
AUTH_TOKENS
)
vars
()
.
update
(
AUTH_TOKENS
)
...
...
Write
Preview
Markdown
is supported
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