-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get west and manifest revisions from a configuration file
Add configuration file support via the standard Python configparser module, which uses a Git-like .ini format. Use it to save the west and manifest revisions specified when running 'west init', and use the saved revisions when updating the west and manifest repositories. Configuration file paths are based on Git, for consistency with the Git-like commands. See the FILES section in git-config(1). Mac OS and Windows paths were checked by Carles Cufi with 'git config --list --show-origin'. Add some new shorthands to _expand_shorthands() in project.py to factor out some logic while removing the hardcoding of the west and manifest upstream branches. The qual-* versions of shorthands give the full path to refs (refs/heads/foo, remotes/origin/bar, etc.) Fixes: #63 Fixes: #67 Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
- Loading branch information
Showing
4 changed files
with
112 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
''' | ||
Configuration file handling, using the standard configparser module. | ||
''' | ||
|
||
import configparser | ||
import os | ||
import platform | ||
|
||
from west.util import west_dir | ||
|
||
def read_config(): | ||
''' | ||
Reads all configuration files, making the configuration values available as | ||
a configparser.ConfigParser object in config.config. This object works | ||
similarly to a dictionary: config.config['foo']['bar'] gets the value for | ||
key 'bar' in section 'foo'. | ||
''' | ||
|
||
global config | ||
|
||
# | ||
# Gather (potential) configuration file paths, roughly following Git | ||
# conventions. | ||
# | ||
# See the FILES section in git-config(1). | ||
# | ||
|
||
# System-wide | ||
|
||
if platform.system() == 'Linux': | ||
files = ['/etc/westconfig'] | ||
elif platform.system() == 'Darwin': # Mac OS | ||
# This was seen on Carles' machine ($(prefix) = /usr/local) | ||
files = ['/usr/local/etc/westconfig'] | ||
elif platform.system() == 'Windows': | ||
# Seen on Carles' machine. Not sure how it got derived though. | ||
files = [os.path.expandvars('%PROGRAMDATA%\\west\\config')] | ||
|
||
# Probably doesn't hurt to check $XDG_CONFIG_HOME on all systems | ||
files.append(os.path.expandvars('$XDG_CONFIG_HOME/git/config') | ||
if 'XDG_CONFIG_HOME' in os.environ else | ||
os.path.expanduser('~/.config/git/config')) | ||
|
||
# User-specific and repository-specific | ||
|
||
files.append(os.path.expanduser('~/.westconfig')) | ||
files.append(os.path.join(west_dir(), 'config')) | ||
|
||
# | ||
# Parse all existing configuration files. Also give any defaults. | ||
# | ||
|
||
config = configparser.ConfigParser(defaults={"revision": "master"}) | ||
config.read(files, encoding='utf-8') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters