def test_aur_package( self , pkg_name ): """ Test if a package exists in AUR :param pkg_name: The name of the package :rtype: True if it exists of False """ pl = tools.clean_pkg_name( pkg_name ) config = cfg.aurpy_config() opener = urllib.request.FancyURLopener({}) url = config.get_pkg_url( glob.AUR , pl ) f = opener.open( url ) try : aur_html = f.read().decode() if re.search ( "404\s+\-\s+Page\s+Not\s+Found" , aur_html ) : return False except : return False return True
def unpack_src(pkg_name): config = cfg.aurpy_config() os.chdir(config.get_compile_dir()) cmd = ["bsdtar", "xzf", pkg_name + ".tar.gz"] call(cmd)
def download_pkg(origin, pkg_name): config = cfg.aurpy_config() cmd = ["wget"] cmd.append(config.get_aur_dw_pkg_url(pkg_name)) cmd.append("--directory-prefix=" + config.get_compile_dir()) call(cmd)
def compile_pkg(pkg_name): config = cfg.aurpy_config() os.chdir(config.get_pkg_build_dir(pkg_name)) cmd = "makepkg -f" ret = call(cmd.split()) if ret != 0: raise compilation_error(pkg_name)
def edit_file(pkg_name, file_name): config = cfg.aurpy_config() print(config.get_pkg_build_dir(pkg_name)) print(config.get_pkg_build_dir(pkg_name)) print(config.get_pkg_build_dir(pkg_name)) os.chdir(config.get_pkg_build_dir(pkg_name)) cmd = os.environ["EDITOR"] + " " + file_name call(cmd.split())
def get_pkgbuild(origin, pkg_name): config = cfg.aurpy_config() opener = urllib.request.FancyURLopener({}) f = opener.open(config.get_pkgbuild_url(origin, pkg_name)) try: pkgbuild = f.read() pkgbuild = pkgbuild.decode() except: return NameError("Error: PKGBUILD not found!") return pkgbuild
def read_repo_data(self): config = cfg.aurpy_config() query = qe.query() if self.origin == glob.AUR : opener = urllib.request.FancyURLopener({}) f = opener.open( config.get_pkg_url( self.origin , self.name ) ) try : aur_html = f.read() self._aur_html = aur_html.decode() except : return False #print( self._aur_html ) r = '<h2>Package\s+Details\:\s+([\w\-]+)\s+([\w+\-\.\:]+)\s*<\/h2>' m = re.search( r , self._aur_html ) if m == None : raise NameError("Invalid AUR HTML format") self.name = m.group(1) self.repo_version = m.group(2) self.test_vcs() inst = query.test_installed_package( self.name ) if inst : self.installed_version = inst[1] return True else : inf = query.test_repo_package( self.name ) inst = query.test_installed_package( self.name ) if inf == None and inst == None : return False self.repo_version = inf[2] if inst : self.installed_version = inst[1] return True
def get_sub_pkg_file_names(base_pkg_name, sub_pkg_names): config = cfg.aurpy_config() pkdir = config.get_pkg_build_dir(base_pkg_name) lsdir = os.listdir(pkdir) res = [] for f in lsdir: max = 0.0 for m in re.finditer("^%s.+pkg.+" % pkg_name, f): if os.path.getmtime(pkdir + "/" + f) > max: res.append(f) return res
def get_vcs_pkg_file_name(pkg_name, vcs): config = cfg.aurpy_config() pkdir = config.get_pkg_build_dir(pkg_name) lsdir = os.listdir(pkdir) max = 0.0 res = None for f in lsdir: m = re.search("^%s.+pkg.+" % pkg_name, f) if m: if os.path.getmtime(pkdir + "/" + f) > max: res = f return res
def install_pkg_list(pkg_name, pkg_files_names, reason=glob.EXPLICIT): config = cfg.aurpy_config() os.chdir(config.get_pkg_build_dir(pkg_name)) if reason == glob.EXPLICIT: reason = "--asexplicit" else: reason = "--asdeps" cmd = "sudo pacman -U %s %s" % (reason, "".join(" %s " % s for s in pkg_files_names)) print() print("\x1b[1;37m Installing packages with the command:\x1b[0m") print(" \x1b[1;32m %s \x1b[0m" % cmd) print() call(cmd.split())
def install( self , asdeps=False ): arch = self._pkg_data["CARCH"][0] if "any" in self._pkg_data["arch"] : arch = "any" if self.vcs : pkg_file_name = [ tools.get_vcs_pkg_file_name( self.name , self.vcs ) ] elif self.has_subpackages : get_sub_pkg_file_names( self.name , self._pkg_data["name"] ) else : pkg_file_names = [ "%s-%s-%s%s" % ( self.name , self.repo_version , arch , self._pkg_data["PKGEXT"][0] ) ] if asdeps : pacman.install_pkg_list( self.name , pkg_file_names , reason=glob.DEPENDS ) else : pacman.install_pkg_list( self.name , pkg_file_names ) if self.has_subpackages : config = cfg.aurpy_config() config.set_subpackages( self.name , pkg_file_names )
def parse_pkgbuild(pkgbuild): config = cfg.aurpy_config() wdir = config.get_tmp_rnd_dir() os.makedirs(wdir) fp = open(wdir + "/PKGBUILD", "w") fp.write(pkgbuild) fp.close() list_cmd = """ printf "=<VARIABLE>=||||" ; for item in ${<VARIABLE>[@]}; do printf "%s|||" $item ; done ; printf "|\n"; """ variables = """ pkgname pkgver pkgrel pkgdir epoch pkgbase pkgdesc arch url license groups depends optdepends makedepends checkdepends provides conflicts replaces backup options install changelog source noextract md5sums sha1sums sha256sums sha384sums sha512sums CARCH PKGEXT """.split() cmd = """ . /etc/makepkg.conf ; . PKGBUILD ; """ for v in variables: cmd = cmd + re.sub("<VARIABLE>", v, list_cmd) + "\n" fp = open(wdir + "/script", "w") fp.write(cmd) fp.close() os.chdir(wdir) pb_out = check_output(["bash", "script"]).decode() pkg_data = defaultdict(list) for v in variables: pkg_data[v] = _get_pkgbuild_variable(v, pb_out) print(pkg_data) return pkg_data