forked from conan-io/conan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Basic profiles * Almost done * Tests passing * Fixed test for windows * Sorted env variables * Macos env test * Some fixes * Added profile to build * Remove nargs ?
- Loading branch information
1 parent
63f7364
commit 4a8c458
Showing
8 changed files
with
366 additions
and
7 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
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,88 @@ | ||
import copy | ||
from collections import OrderedDict | ||
from conans.util.config_parser import ConfigParser | ||
from conans.model.scope import Scopes, _root | ||
|
||
|
||
class Profile(object): | ||
'''A profile contains a set of setting (with values), environment variables | ||
and scopes''' | ||
|
||
def __init__(self): | ||
# Sections | ||
self.settings = OrderedDict() | ||
self.env = OrderedDict() | ||
self.scopes = Scopes() | ||
|
||
@staticmethod | ||
def loads(text): | ||
obj = Profile() | ||
doc = ConfigParser(text, allowed_fields=["settings", "env", "scopes"]) | ||
|
||
for setting in doc.settings.split("\n"): | ||
if setting: | ||
name, value = setting.split("=") | ||
obj.settings[name] = value | ||
|
||
if doc.scopes: | ||
obj.scopes = Scopes.from_list(doc.scopes.split("\n")) | ||
|
||
for env in doc.env.split("\n"): | ||
if env: | ||
varname, value = env.split("=") | ||
obj.env[varname] = value | ||
|
||
obj._order() | ||
return obj | ||
|
||
def dumps(self): | ||
self._order() # gets in order the settings | ||
|
||
result = ["[settings]"] | ||
for name, value in self.settings.items(): | ||
result.append("%s=%s" % (name, value)) | ||
|
||
result.append("[scopes]") | ||
if self.scopes[_root].get("dev", None): | ||
# FIXME: Ugly _root import | ||
del self.scopes[_root]["dev"] # Do not include dev | ||
scopes_txt = self.scopes.dumps() | ||
result.append(scopes_txt) | ||
|
||
result.append("[env]") | ||
for name, value in self.env.items(): | ||
result.append("%s=%s" % (name, value)) | ||
|
||
return "\n".join(result).replace("\n\n", "\n") | ||
|
||
def update_settings(self, new_settings): | ||
'''Mix the specified settings with the current profile. | ||
Specified settings are prioritized to profile''' | ||
# apply the current profile | ||
if new_settings: | ||
self.settings.update(new_settings) | ||
self._order() | ||
|
||
def update_scopes(self, new_scopes): | ||
'''Mix the specified settings with the current profile. | ||
Specified settings are prioritized to profile''' | ||
# apply the current profile | ||
if new_scopes: | ||
self.scopes.update(new_scopes) | ||
self._order() | ||
|
||
def _order(self): | ||
tmp_settings = copy.copy(self.settings) | ||
self.settings = OrderedDict() | ||
# Insert in a good order | ||
for func in [lambda x: "." not in x, # First the principal settings | ||
lambda x: "." in x]: | ||
for name, value in tmp_settings.items(): | ||
if func(name): | ||
self.settings[name] = value | ||
|
||
tmp_env = copy.copy(self.env) | ||
self.env = OrderedDict() | ||
for ordered_key in sorted(tmp_env): | ||
self.env[ordered_key] = tmp_env[ordered_key] | ||
|
Oops, something went wrong.