aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2013-06-03 22:50:00 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2013-06-03 22:50:00 -0400
commit76377687dd84d8e9ef4cc5788bd5b594c1c966ed (patch)
treed76d9059e3248ce96a022bb23dc758cb0c9d650a
parent0dbdfbcccd74f9c61bcfcef5cd3b0800959c9620 (diff)
downloadipsutils-76377687dd84d8e9ef4cc5788bd5b594c1c966ed.tar.gz
Keyword variable expansion implemented
-rw-r--r--ipsutils.ips4
-rw-r--r--ipsutils/config.py29
2 files changed, 25 insertions, 8 deletions
diff --git a/ipsutils.ips b/ipsutils.ips
index 4bd9a39..ca3bfbf 100644
--- a/ipsutils.ips
+++ b/ipsutils.ips
@@ -2,8 +2,8 @@ name: ipsutils
version: 0.4.0
release: 1
maintainer: "Joseph Hunkeler <jhunk@stsci.edu>"
-upstream_url: http://localhost/ipsutils-0.4.0.tar.gz
-source_url: http://localhost/ipsutils-0.4.0.tar.gz
+upstream_url: http://localhost/$name-$version.tar.gz
+source_url: http://localhost/$name-$version.tar.gz
description: "Python IPS library"
summary: "A python based IPS library"
group: developer
diff --git a/ipsutils/config.py b/ipsutils/config.py
index 42a354d..41400a3 100644
--- a/ipsutils/config.py
+++ b/ipsutils/config.py
@@ -14,6 +14,7 @@
# along with ipsutils. If not, see <http://www.gnu.org/licenses/>.
import shlex
import string
+import StringIO
class Config(object):
def __init__(self, ipsfile):
@@ -42,14 +43,29 @@ class Config(object):
'files': []
}
- expandable = []
+ #Initial key_dict population with raw values taken from ips file
+ for key in key_dict:
+ for line in file(ipsfile).readlines():
+ parts = shlex.split(line)
+ if key + ":" in parts:
+ key_dict[key] = parts[1]
+
+ #Drop using the original file in favor of a StringIO buffer
+ #Because we need room to breathe without rewriting the file
+ #every time we run a build... that's a no-go.
+ ipsfile_input = StringIO.StringIO()
for line in file(ipsfile).readlines():
- parts = shlex.split(line)
- t = string.Template(parts)
- expandable.append(t)
+ t = string.Template(line)
+ new_line = t.safe_substitute(key_dict)
+ ipsfile_input.writelines(new_line)
+
+ #Turn our input buffer into an output buffer then ditch the original.
+ ipsfile_output = StringIO.StringIO(ipsfile_input.getvalue()).readlines()
+ ipsfile_input.close()
+ # Populate key_dict with expanded values
for key in key_dict:
- for line in file(ipsfile).readlines():
+ for line in ipsfile_output:
parts = shlex.split(line)
if key + ":" in parts:
key_dict[key] = parts[1]
@@ -58,7 +74,7 @@ class Config(object):
code_section = ['%build', '%prep', '%install', '%transforms']
for section in code_section:
- for line in file(ipsfile).readlines():
+ for line in ipsfile_output:
if not line:
continue
if line.startswith('#'):
@@ -72,5 +88,6 @@ class Config(object):
if found_data:
script_dict[section.strip('%')].append(parts)
+ #Assign completed dictionaries to global class scope
self.key_dict = key_dict
self.script_dict = script_dict