Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Sen2Chain
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
ESPACE-DEV
Sen2Chain
Commits
0252b34c
Commit
0252b34c
authored
5 years ago
by
pascal.mouquet_ird.fr
Browse files
Options
Downloads
Patches
Plain Diff
improve config.py to auto update config file and set default values
parent
c1361816
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sen2chain/config.py
+32
-53
32 additions, 53 deletions
sen2chain/config.py
with
32 additions
and
53 deletions
sen2chain/config.py
+
32
−
53
View file @
0252b34c
...
@@ -38,18 +38,35 @@ class Config:
...
@@ -38,18 +38,35 @@ class Config:
_TILES_TO_WATCH
=
_CONFIG_DIR
/
"
tiles_to_watch.csv
"
_TILES_TO_WATCH
=
_CONFIG_DIR
/
"
tiles_to_watch.csv
"
def
__init__
(
self
)
->
None
:
def
__init__
(
self
)
->
None
:
self
.
_config_params
=
{
"
temp_path
"
,
"
l1c_path
"
,
"
l2a_path
"
,
"
indices_path
"
,
"
time_series_path
"
,
"
sen2cor_bashrc_path
"
,
"
scihub_id
"
,
"
scihub_pwd
"
,
"
peps_config_path
"
,
"
proxy_http_url
"
,
"
proxy_https_url
"
}
self
.
cfg
=
None
self
.
config_dict
=
dict
()
if
not
self
.
_CONFIG_FILE
.
exists
():
self
.
_config_params
=
ConfigParser
()
self
.
_config_params
[
"
DATA PATHS
"
]
=
{
"
temp_path
"
:
""
,
"
l1c_path
"
:
""
,
"
l2a_path
"
:
""
,
"
indices_path
"
:
""
,
"
time_series_path
"
:
""
}
self
.
_config_params
[
"
SEN2COR PATH
"
]
=
{
"
sen2cor_bashrc_path
"
:
""
}
self
.
_config_params
[
"
HUBS LOGINS
"
]
=
{
"
scihub_id
"
:
""
,
"
scihub_pwd
"
:
""
,
"
peps_config_path
"
:
""
}
self
.
_config_params
[
"
PROXY SETTINGS
"
]
=
{
"
proxy_http_url
"
:
""
,
"
proxy_https_url
"
:
""
}
if
self
.
_CONFIG_FILE
.
exists
():
self
.
_config_params
.
read
(
str
(
self
.
_CONFIG_FILE
))
self
.
_config_params_disk
=
ConfigParser
()
self
.
_config_params_disk
.
read
(
str
(
self
.
_CONFIG_FILE
))
if
self
.
_config_params_disk
!=
self
.
_config_params
:
self
.
_create_config
()
else
:
self
.
_create_config
()
self
.
_create_config
()
self
.
config_dict
=
dict
()
for
section
in
self
.
_config_params
.
sections
():
for
key
in
self
.
_config_params
[
section
].
keys
():
self
.
config_dict
[
key
]
=
self
.
_config_params
[
section
][
key
]
self
.
_load_config
()
self
.
_check_data_paths
()
self
.
_check_data_paths
()
def
_create_config
(
self
)
->
None
:
def
_create_config
(
self
)
->
None
:
...
@@ -57,46 +74,9 @@ class Config:
...
@@ -57,46 +74,9 @@ class Config:
self
.
_USER_DIR
.
mkdir
(
exist_ok
=
True
)
self
.
_USER_DIR
.
mkdir
(
exist_ok
=
True
)
self
.
_CONFIG_DIR
.
mkdir
(
exist_ok
=
True
)
self
.
_CONFIG_DIR
.
mkdir
(
exist_ok
=
True
)
self
.
_DEFAULT_DATA_DIR
.
mkdir
(
exist_ok
=
True
)
self
.
_DEFAULT_DATA_DIR
.
mkdir
(
exist_ok
=
True
)
with
open
(
str
(
self
.
_CONFIG_FILE
),
"
w
"
)
as
cfg_file
:
with
open
(
str
(
self
.
_CONFIG_FILE
),
"
w
"
)
as
cfg_file
:
self
.
cfg
=
ConfigParser
()
self
.
_config_params
.
write
(
cfg_file
)
self
.
cfg
.
read
(
str
(
self
.
_CONFIG_FILE
))
self
.
cfg
.
add_section
(
"
DATA PATHS
"
)
self
.
cfg
.
add_section
(
"
SEN2COR PATH
"
)
self
.
cfg
.
add_section
(
"
HUBS LOGINS
"
)
self
.
cfg
.
add_section
(
"
PROXY SETTINGS
"
)
self
.
cfg
.
set
(
"
DATA PATHS
"
,
"
temp_path
"
,
""
)
self
.
cfg
.
set
(
"
DATA PATHS
"
,
"
l1c_path
"
,
""
)
self
.
cfg
.
set
(
"
DATA PATHS
"
,
"
l2a_path
"
,
""
)
self
.
cfg
.
set
(
"
DATA PATHS
"
,
"
indices_path
"
,
""
)
self
.
cfg
.
set
(
"
DATA PATHS
"
,
"
time_series_path
"
,
""
)
self
.
cfg
.
set
(
"
SEN2COR PATH
"
,
"
sen2cor_bashrc_path
"
,
""
)
self
.
cfg
.
set
(
"
HUBS LOGINS
"
,
"
peps_config_path
"
,
""
)
self
.
cfg
.
set
(
"
HUBS LOGINS
"
,
"
scihub_id
"
,
""
)
self
.
cfg
.
set
(
"
HUBS LOGINS
"
,
"
scihub_pwd
"
,
""
)
self
.
cfg
.
set
(
"
PROXY SETTINGS
"
,
"
proxy_http_url
"
,
""
)
self
.
cfg
.
set
(
"
PROXY SETTINGS
"
,
"
proxy_https_url
"
,
""
)
self
.
cfg
.
write
(
cfg_file
)
def
_load_config
(
self
)
->
None
:
"""
Loads configuration parameters in a dictionnary.
"""
self
.
cfg
=
ConfigParser
()
self
.
cfg
.
read
(
str
(
self
.
_CONFIG_FILE
))
# check if a parameter is missing in the config file
for
section
in
self
.
cfg
.
sections
():
for
key
in
self
.
cfg
[
section
].
keys
():
if
key
in
self
.
_config_params
:
self
.
config_dict
[
key
]
=
self
.
cfg
[
section
][
key
]
else
:
raise
ValueError
(
"
Invalid parameter:
"
,
key
)
if
self
.
_config_params
!=
set
(
self
.
config_dict
.
keys
()):
missing_params
=
self
.
_config_params
-
set
(
self
.
config_dict
.
keys
())
raise
ValueError
(
"
Parameter not found in config file: {}
"
.
format
(
missing_params
)
)
def
_check_data_paths
(
self
)
->
None
:
def
_check_data_paths
(
self
)
->
None
:
"""
"""
...
@@ -107,12 +87,11 @@ class Config:
...
@@ -107,12 +87,11 @@ class Config:
"""
"""
Update a setting in config.ini
Update a setting in config.ini
"""
"""
self
.
cfg
.
set
(
section
,
key
,
val
)
self
.
_config_params
.
set
(
section
,
key
,
val
)
with
open
(
str
(
self
.
_CONFIG_FILE
),
"
w
"
)
as
cfg_file
:
with
open
(
str
(
self
.
_CONFIG_FILE
),
"
w
"
)
as
cfg_file
:
self
.
cfg
.
write
(
cfg_file
)
self
.
_config_params
.
write
(
cfg_file
)
data_paths
=
[
"
temp_path
"
,
"
l1c_path
"
,
"
l2a_path
"
,
data_paths
=
[
option
for
option
in
self
.
_config_params
[
"
DATA PATHS
"
]]
"
indices_path
"
,
"
time_series_path
"
]
for
path
in
data_paths
:
for
path
in
data_paths
:
value
=
self
.
config_dict
[
path
]
value
=
self
.
config_dict
[
path
]
...
@@ -136,7 +115,7 @@ class Config:
...
@@ -136,7 +115,7 @@ class Config:
:param param: parameter.
:param param: parameter.
"""
"""
if
param
not
in
self
.
_
config_
params
:
if
param
not
in
self
.
config_
dict
:
raise
ValueError
(
"
Invalid parameter
"
,
param
)
raise
ValueError
(
"
Invalid parameter
"
,
param
)
return
self
.
config_dict
.
get
(
param
)
return
self
.
config_dict
.
get
(
param
)
...
...
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