New conf.py variables.
[AurShell.git] / plugin / abs.py
blob98c38734fd3761952620f20ec6763ac6f08f98a3
1 import string
2 import os
3 import os.path
4 import sys
5 import re
6 import shutil
8 class abs(object):
9 """
10 Do some stuff with ABS. Search, compile, install.
11 You know, everything that you need to be happy
12 """
13 def __init__(self, put, conf):
14 self.put = put
15 self.conf = conf
16 self.compile_cmd = "makepkg -f "
17 self.install_cmd = "pacman -U "
18 self.search_path = "/var/abs"
21 def do_builddir(self, bdir=None, *ignore):
22 # shouldn't this be plugin independent method?
23 if bdir:
24 if not os.path.isdir(bdir):
25 if self.put.ask("No such directory, create it?"):
26 try:
27 os.mkdir(bdir)
28 self.conf.build_dir = bdir
29 except OSError:
30 self.put("Permission denied.", "RED", True)
31 else:
32 self.conf.build_dir = bdir
33 self.put("Build directory: ", "GREEN", False)
34 self.put(self.conf.build_dir)
37 def do_search(self, pkgname, *ignore):
38 """Find PKGBUILD"""
39 # TODO 2008-02-13 20:08:29
40 # Regular expression operations for searching
41 pkgbuild_found = []
42 for root, dirs, files in os.walk(self.search_path):
43 for d in dirs:
44 if pkgname in d:
45 try:
46 name = str(d)
47 for line in open(os.path.join(root, d, "PKGBUILD"), "r"):
48 if line.startswith("pkgver"):
49 name += " - " + line.split("=")[1][:-1]
50 self.put("[abs] ", "YELLOW", False)
51 self.put(name.ljust(32), "WHITE", False)
52 self.put(root)
53 except IOError:
54 pass
56 def do_compile(self, pkgname, *ignore):
57 for root, dirs, files in os.walk(self.search_path):
58 for d in dirs:
59 if d == pkgname:
60 path = os.path.join(root, d)
61 build_path = os.path.join(self.conf.build_dir, d)
62 if os.path.isdir(build_path):
63 if self.put.ask("Directory exist. Delete it?"):
64 shutil.rmtree(build_path)
65 else:
66 self.put("Nothing to do.")
67 return
68 shutil.copytree(path, build_path)
69 os.system("cd %s && %s " % (build_path, self.conf.compile_cmd))
70 return
71 self.put("PKGBUILD not found.")
73 def do_install(self, pkgname, *ignore):
74 build_path = os.path.join(self.conf.build_dir, pkgname)
75 if not os.path.isdir(build_path):
76 self.put("No package found. Try to compile it first.")
77 return
78 for pkgfile in os.listdir(build_path):
79 if pkgfile.endswith("pkg.tar.gz"):
80 os.system("cd %s && %s %s" % \
81 (build_path, self.conf.install_cmd, pkgfile))
82 return
83 self.put("No package found. Try to compile it first.")