aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ips/build.py47
-rw-r--r--ips/config.py19
-rw-r--r--ips/env.py32
-rw-r--r--ips/task.py39
-rw-r--r--ips/tpl/metadata.tpl7
-rw-r--r--ipsbuild-setuptree.py15
-rw-r--r--ipsbuild.py20
-rw-r--r--setup.py26
-rw-r--r--test.ips5
9 files changed, 170 insertions, 40 deletions
diff --git a/ips/build.py b/ips/build.py
index dad63b7..f402019 100644
--- a/ips/build.py
+++ b/ips/build.py
@@ -1,9 +1,25 @@
+# This file is part of ipsutils.
+
+# ipsutils is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# ipsutils is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ipsutils. If not, see <http://www.gnu.org/licenses/>.
+
from . import env, task
from pprint import pprint
import os
import shutil
import subprocess
import string
+from . import tpl
class Build(env.Environment):
@@ -12,7 +28,7 @@ class Build(env.Environment):
# Inherited members are used to populate package information
# as well as build tasks
super(Build, self).__init__(ipsfile)
-
+
os.chdir(self.env['IPSBUILD'])
# Create list of build tasks
ordered_tasks = ['prep', 'build', 'install']
@@ -30,28 +46,35 @@ class Build(env.Environment):
def exec_scripted_process(self, *p):
"""Execute script in .ips
This function needs to be rewritten BAD
+
+ p: tuple of function arguments
"""
+ # All execution occurs from within the build directory.
+ # This includes all installation-like tasks
os.chdir(self.env_pkg['BUILD'])
for t in map(list, p):
for i in t:
if not i:
continue
for e in i:
+ # Variable expansion occurs here. Unfortunately, env_pkg is NOT available
+ # from within the configuration class
t = string.Template(string.join(e))
e = t.safe_substitute(self.env_pkg)
print("+ {0:s}".format(e))
- output = subprocess.check_output(e)
+ # Using "shell" is dangerous, but we're in the business of danger... right?
+ output = subprocess.check_output(e, shell=True)
if output:
- print("+ {0:s}".format(output))
+ print("+ {0:s}".format(output).rstrip('\n'))
os.chdir(self.env['IPSBUILD'])
return True
-
+
def source_unpack(self, *p):
path = os.path.relpath(self.env_pkg['SOURCES'], self.env['IPSBUILD'])
if not os.path.exists(path):
print("{0:s}: does not exist".format(path))
return False
-
+
ext = {
'.tar': '{0:s} xf {1:s} -C {2:s}'.format(self.tool['tar'], path, self.env['BUILD']),
'.tar.gz': '{0:s} xfz {1:s} -C {2:s}'.format(self.tool['tar'], path, self.env['BUILD']),
@@ -71,6 +94,10 @@ class Build(env.Environment):
return True
def create_buildroot(self, *p):
+ """Destroy/Create BUILDROOT per execution to keep the envrionment stable
+
+ p: tuple of function arguments
+ """
path = self.env_pkg['BUILDROOT']
if os.path.exists(path):
shutil.rmtree(path)
@@ -88,7 +115,9 @@ class Build(env.Environment):
'info.source_url': self.key_dict['source_url'],
'info.classification': self.key_dict['classification']
}
- template = file('c:\\users\\jhunk\\documents\\projects\\aptana\\ipsbuild\\metadata.tpl', 'r')
+
+ # Perform manifest template mapping and expansion
+ template = file(tpl.metadata, 'r')
for line in template.readlines():
for k, v in meta_map.items():
if k in line:
@@ -106,8 +135,10 @@ class Build(env.Environment):
))
continue
# The rest of the value replacements are rather simple
- output.append(line.replace('{}', v))
-
+ output.append(line.replace('{}', v))
+ template.close()
+
+ # Generate intial IPS manifest file in buildroot
manifest = file(os.path.join(self.env_pkg['BUILDROOT'], self.complete_name + '.p5m.1'), 'w+')
for line in output:
manifest.writelines(line)
diff --git a/ips/config.py b/ips/config.py
index 45aa204..fe9adca 100644
--- a/ips/config.py
+++ b/ips/config.py
@@ -1,3 +1,17 @@
+# This file is part of ipsutils.
+
+# ipsutils is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# ipsutils is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ipsutils. If not, see <http://www.gnu.org/licenses/>.
import shlex
import string
@@ -31,7 +45,7 @@ class Config(object):
parts = shlex.split(line)
t = string.Template(parts)
expandable.append(t)
-
+
for key in key_dict:
for line in file(ipsfile).readlines():
parts = shlex.split(line)
@@ -40,7 +54,7 @@ class Config(object):
found_data = False
code_section = ['%build', '%prep', '%install']
-
+
for section in code_section:
for line in file(ipsfile).readlines():
if line.startswith('#'):
@@ -56,4 +70,3 @@ class Config(object):
self.key_dict = key_dict
self.script_dict = script_dict
- \ No newline at end of file
diff --git a/ips/env.py b/ips/env.py
index b7f611a..cd5695d 100644
--- a/ips/env.py
+++ b/ips/env.py
@@ -1,3 +1,18 @@
+# This file is part of ipsutils.
+
+# ipsutils is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# ipsutils is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ipsutils. If not, see <http://www.gnu.org/licenses/>.
+
import os
import sys
from . import config
@@ -6,12 +21,15 @@ from . import config
class Environment(config.Config):
def __init__(self, ipsfile):
super(Environment, self).__init__(ipsfile)
+
+ # Platform specific ipsbuild directory assignment
if sys.platform == 'linux2' \
or sys.platform == 'sunos5':
self.__basepath = os.path.join(os.environ['HOME'], 'ipsbuild')
else:
self.__basepath = os.path.join(os.environ['USERPROFILE'], 'ipsbuild')
-
+
+ # Dictionary of top-level directories
self.env = {
'IPSBUILD': self.pathgen(''),
'BUILDROOT': self.pathgen('BUILDROOT'),
@@ -21,8 +39,10 @@ class Environment(config.Config):
'PKGS': self.pathgen('PKGS'),
'SPKGS': self.pathgen('SPKGS')
}
-
+ # complete_name is required to build proper path names.
+ # The use of "self" in this case may be deprecated in the future.
self.complete_name = self.key_dict['name'] + '-' + self.key_dict['version']
+ # Dictionary of package-leve directories
self.env_pkg = {
'BUILDROOT': os.path.join(self.env['BUILDROOT'], self.complete_name),
'BUILD': os.path.join(self.env['BUILD'], self.complete_name),
@@ -31,6 +51,9 @@ class Environment(config.Config):
'SPKGS': os.path.join(self.env['SPKGS'], self.complete_name)
}
+ # Generic utility mapping for platform specific configuration.
+ # Note: This is mainly to test script functionality on different platforms
+ # even though this library is VERY VERY Solaris 11 specific
self.tool = {
'tar': 'tar',
'unzip': 'unzip',
@@ -38,8 +61,13 @@ class Environment(config.Config):
'bunzip': 'bunzip'
}
+ # Oracle tar is ancient. GNU tar is preferrred.
if sys.platform == 'sunos5':
self.tool['tar'] = 'gtar'
def pathgen(self, path):
+ """Simplify path generation based on "ipsbuild" base path
+
+ path: directory leaf of 'ipsbuild' directory (in $HOME)
+ """
return os.path.join(self.__basepath, path)
diff --git a/ips/task.py b/ips/task.py
index 6c84d51..1d8faeb 100644
--- a/ips/task.py
+++ b/ips/task.py
@@ -1,17 +1,18 @@
-# class TaskController(list):
-# def __init__(self):
-# super(TaskController, self).__init__()
-# self._store = []
-#
-# def task(self, task):
-# super(TaskController, self).append(task)
-#
-# def do_tasks(self):
-# for task in super(TaskController, self).__iter__():
-# retval = task.run()
-# if not retval:
-# exit(retval)
-
+# This file is part of ipsutils.
+
+# ipsutils is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# ipsutils is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ipsutils. If not, see <http://www.gnu.org/licenses/>.
+
class TaskController(object):
def __init__(self):
self.stack = []
@@ -21,20 +22,18 @@ class TaskController(object):
t: Task object
"""
self.stack.append(t)
-
+
def do_tasks(self):
""" FILO execution of tasks
"""
- #self.stack.reverse()
- for i in self.stack:
- i.run()
+ for stack_entry in self.stack:
+ stack_entry.run()
class NamedTask(object):
def __init__(self, name, func, *args):
self.name = name
self.task = func
self.task_args = args
- print("New task: {0:s} {1:s}".format(self.name, self.task))
def run(self):
print("Running task: {0:s}".format(self.name))
@@ -42,4 +41,4 @@ class NamedTask(object):
return status
class InternalTask(NamedTask):
- pass \ No newline at end of file
+ pass
diff --git a/ips/tpl/metadata.tpl b/ips/tpl/metadata.tpl
new file mode 100644
index 0000000..573fee3
--- /dev/null
+++ b/ips/tpl/metadata.tpl
@@ -0,0 +1,7 @@
+set name=pkg.fmri value={}
+set name=pkg.description value="{}"
+set name=pkg.summary value="{}"
+set name=variant.arch value={}
+set name=info.upstream_url value="{}"
+set name=info.source-url value="{}"
+set name=info.classification value="{}"
diff --git a/ipsbuild-setuptree.py b/ipsbuild-setuptree.py
index 0ad38a8..d0fd72e 100644
--- a/ipsbuild-setuptree.py
+++ b/ipsbuild-setuptree.py
@@ -1,3 +1,18 @@
+# This file is part of ipsutils.
+
+# ipsutils is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# ipsutils is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ipsutils. If not, see <http://www.gnu.org/licenses/>.
+
import os
import sys
diff --git a/ipsbuild.py b/ipsbuild.py
index 8f3088a..406fe77 100644
--- a/ipsbuild.py
+++ b/ipsbuild.py
@@ -1,14 +1,24 @@
#!/usr/bin/env python
+# This file is part of ipsutils.
+
+# ipsutils is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# ipsutils is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ipsutils. If not, see <http://www.gnu.org/licenses/>.
-# Solaris 11 IPS
-# Automate package creation
from pprint import pprint
import ips
testfile = "test.ips"
build = ips.build.Build(testfile)
-#build.show_summary()
-#build.source_unpack()
+build.show_summary()
build.controller.do_tasks()
-print("I made it to the end") \ No newline at end of file
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..84a5725
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+# This file is part of ipsutils.
+
+# ipsutils is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# ipsutils is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ipsutils. If not, see <http://www.gnu.org/licenses/>.
+
+from distutils.core import setup
+
+setup(name='IPS',
+ version='0.1',
+ description='Solaris 11 IPS packaging library',
+ author='Joseph Hunkeler',
+ author_email='jhunk@stsci.edu',
+ url='http://www.stsci.edu/~jhunk/ips',
+ packages=['ips'],
+ )
diff --git a/test.ips b/test.ips
index aceb91f..0e49af3 100644
--- a/test.ips
+++ b/test.ips
@@ -18,13 +18,14 @@ license: GPL
%end
%build
-python -m compileall -f .
+pwd
+python -m compileall -f *
#configure --prefix=/usr
#make
%end
%install
-mkdir $BUILDROOT/usr/bin
+mkdir -p $BUILDROOT/usr/bin
cp testpkg.pyc $BUILDROOT/usr/bin
#make install
%end \ No newline at end of file