summaryrefslogtreecommitdiffstats
path: root/modules/cabal.py
diff options
context:
space:
mode:
authorYaakov M. Nemoy <loupgaroublond@gmail.com>2008-12-29 23:11:55 -0500
committerYaakov M. Nemoy <loupgaroublond@gmail.com>2008-12-29 23:11:55 -0500
commit0cb6e545b308e79a5d4aa6c36b7366f2b0fc30fd (patch)
tree8c30624c6191a3d7a138b8229ef829a8406b9aa0 /modules/cabal.py
parent3d02771f3e2376cd459e9a4d0edf2ff0c0f22b2c (diff)
downloadfedora-devshell-0cb6e545b308e79a5d4aa6c36b7366f2b0fc30fd.tar.gz
fedora-devshell-0cb6e545b308e79a5d4aa6c36b7366f2b0fc30fd.tar.xz
fedora-devshell-0cb6e545b308e79a5d4aa6c36b7366f2b0fc30fd.zip
Mass commit, i should be cleaner in the future.
Diffstat (limited to 'modules/cabal.py')
-rw-r--r--modules/cabal.py132
1 files changed, 132 insertions, 0 deletions
diff --git a/modules/cabal.py b/modules/cabal.py
new file mode 100644
index 0000000..81f4b68
--- /dev/null
+++ b/modules/cabal.py
@@ -0,0 +1,132 @@
+from __future__ import with_statement
+
+from os import listdir, getcwd
+from os.path import expanduser, expandvars, abspath
+
+from re import compile, DOTALL
+
+from subprocess import Popen
+
+from urllib import urlopen, urlretrieve
+
+from base.base import log
+from base.module import Module
+from base.exceptions import ExecutionException
+from base.util import pwd, one
+from base.vars import orig_src_dir, haskell_compiler
+
+from modules.package import Package
+
+class Cabal(Module):
+ def __init__(self, name, root='~/haskell'):
+ self.name = name
+ self.root = expanduser(root)
+ with pwd(self.root):
+ self.package = Package(name)
+ self.original = orig_src_dir
+ self.compiler = haskell_compiler
+
+ def copy_in(self, tarball):
+ tarball = abspath(tarball)
+ with pwd(self.root):
+ self.package.add_sourceball(tarball)
+
+ def find_setup(self, original=False):
+ setup_re = compile("Setup\.l?hs")
+ with pwd(self.source_dir(original)):
+ setup_f = one(listdir(getcwd()), setup_re.search)
+ log.debug(setup_f)
+ return setup_f
+
+ def compile_setup(self, original=False):
+ with pwd(self.pkg.code_dir):
+ with file('ghc.log', 'a') as ghc_out:
+ with pwd(self.source_dir(original)):
+ setup_f = self.find_setup(original)
+ p = Popen([self.compiler, '--make', setup_f],
+ stdout = ghc_out, stderr = ghc_out)
+ log.info('Building %s, please wait...' % setup_f)
+ p.wait()
+
+ def configure(self, target='home', original=False):
+ user = True if target == 'home' else False
+ self.compile_setup(original)
+ with pwd(self.pkg.code_dir):
+ with file('cabal.log', 'a') as cabal_out:
+ with pwd(self.source_dir(original)):
+ args = [abspath('Setup'), 'configure'] + \
+ (['--user', '--prefix=' + expanduser('~')] if user else [])
+ p = Popen(args, stdout=cabal_out, stderr=cabal_out)
+ log.info('Configuring %s, please wait...' % self.name)
+ p.wait()
+
+ def build(self, original=False):
+ '''This is not safe to run on an unconfigured source dir'''
+ self.compile_setup(original)
+ with pwd(self.pkg.code_dir):
+ with file('cabal.log', 'a') as cabal_out:
+ with pwd(self.source_dir(original)):
+ args = [abspath('Setup'), 'build']
+ p = Popen(args, stdout=cabal_out, stderr=cabal_out)
+ log.info('Building %s, please wait...' % self.name)
+ p.wait()
+
+ def install(self, original=False):
+ '''This is not safe to run on an unconfigured source dir'''
+ self.compile_setup(original)
+ with pwd(self.pkg.code_dir):
+ with file('cabal.log', 'a') as cabal_out:
+ with pwd(self.source_dir(original)):
+ args = [abspath('Setup'), 'install']
+ p = Popen(args, stdout=cabal_out, stderr=cabal_out)
+ log.info('Building %s, please wait...' % self.name)
+ p.wait()
+
+ def install_source(self, target='home', original=False):
+ self.configure(target, original)
+ self.build(original)
+ self.install(original)
+
+ def install_sourceball(self, tarball, target='home'):
+ self.copy_in(tarball)
+ self.install_source(target, False)
+
+ def get_from_hackage(self, pkg, ver):
+ sb_file = self.hackage_url(pkg, ver)
+ self.copy_in(sb_file)
+
+ def get_latest(self, pkg):
+ ver = self.latest_version(pkg)
+ self.get_from_hackage(pkg, ver)
+
+ def install_from_hackage(self, pkg, ver, target='home'):
+ self.get_from_hackage(pkg, ver)
+ self.install_source(target, False)
+
+ def install_latest(self, pkg, target='home'):
+ self.get_latest(pkg)
+ self.install_source(target, False)
+
+ def source_dir(self, original=False):
+ with pwd(self.package.code_dir):
+ return abspath(self.package.cfg['source'] + (self.orig_src_dir if original else ""))
+
+ def latest_version(self, pkg):
+ hackage_title = compile(r'<title.*?>HackageDB: (.*)-(.*)</title.*?>', DOTALL)
+ site = 'http://hackage.haskell.org/cgi-bin/hackage-scripts/package/' + pkg
+ u = urlopen(site)
+ page = u.read()
+ match = hackage_title.search(page)
+ groups = match.groups()
+ print groups
+ if pkg = groups[0]:
+ return groups[1]
+ else:
+ raise ExecutionException("package does not match package name, can't determine version, sorry")
+
+ def hackage_url(self, pkg, ver):
+ return 'http://hackage.haskell.org/packages/archive/' + \
+ pkg + '/' + ver + '/' + pkg + '-' + ver + '.tar.gz'
+
+ def close(self):
+ self.package.close()