Repo moved to http://github.com/husio/aurshell/tree/master
[AurShell.git] / plugin / abs.py
blob5c9aae97642e3dd0490cad3a9d4537e21229d57b
1 import string
2 import os
3 import os.path
4 import sys
5 import re
6 import shutil
7 import makepkg
10 class abs(makepkg._make_package):
11 """
12 Do some stuff with ABS. Search, compile, install.
13 You know, everything that you need to be happy
14 """
15 def __init__(self, put, conf):
16 self.put = put
17 self.conf = conf
19 def do_builddir(self, bdir=None, *ignore):
20 # shouldn't this be plugin independent method?
21 if bdir:
22 if not os.path.isdir(bdir):
23 if self.put.ask("No such directory, create it?"):
24 try:
25 os.mkdir(bdir)
26 self.conf.build_dir = bdir
27 except OSError:
28 self.put("Permission denied.", "RED", True)
29 else:
30 self.conf.build_dir = bdir
31 self.put("Build directory: ", "GREEN", False)
32 self.put(self.conf.build_dir)
34 def do_info(self, pkgname, *ignore):
35 """Show PKGBUILD info"""
36 for root, dirs, files in os.walk(self.conf.abs_path):
37 for d in dirs:
38 if pkgname == d:
39 self.show_pkgbuild(os.path.join(root, d, "PKGBUILD"))
40 return
42 def do_search(self, pkgname, *ignore):
43 """Find PKGBUILD in ABS file tree."""
44 # TODO 2008-02-13 20:08:29
45 # Regular expression operations for searching
46 pkgbuild_found = []
47 for root, dirs, files in os.walk(self.conf.abs_path):
48 for d in dirs:
49 if pkgname in d:
50 try:
51 name = str(d)
52 for line in open(os.path.join(root, d, "PKGBUILD"), "r"):
53 if line.startswith("pkgver"):
54 name += " - " + line.split("=")[1][:-1]
55 self.put("[abs] ", "YELLOW", False)
56 self.put(name.ljust(32), "WHITE", False)
57 self.put(root)
58 except IOError:
59 pass
61 def do_compile(self, pkgname, *ignore):
62 """Run conf.compile_cmd in given path"""
63 for root, dirs, files in os.walk(self.conf.abs_path):
64 for d in dirs:
65 if d == pkgname:
66 path = os.path.join(root, d)
67 build_path = os.path.join(self.conf.build_dir, d)
68 if os.path.isdir(build_path):
69 if self.put.ask("Directory exist. Delete it?"):
70 shutil.rmtree(build_path)
71 else:
72 self.put("Nothing to do.")
73 return
74 shutil.copytree(path, build_path)
75 os.system("cd %s && %s " % (build_path, self.conf.compile_cmd))
76 return
77 self.put("PKGBUILD not found.")
79 def do_install(self, pkgname, *ignore):
80 """Install package from conf.build_path + pkgname."""
81 build_path = os.path.join(self.conf.build_dir, pkgname)
82 if not os.path.isdir(build_path):
83 self.put("No package found. Try to compile it first.")
84 return
85 self.run_install(build_path)