#!/usr/bin/python2 #chk_arch_pkg.py uses the current dir name and finds the archlinux package url #prints the current version of the package in archlinux #prints the current version of the PKGBUILD in the working dir #asks to download and expand the archlinx sources #asks to copy the archlinux sources to the working dir #asks to delete the downloaded and expanded sources import os,sys import shutil import urllib2 import re import subprocess def getArchVer(): # repos=['testing', 'core', 'extra', 'community-testing', 'community', 'aur'] repos=['core', 'extra', 'community-testing', 'community', 'aur'] website="" archVer="" aPKGBUILD="" global repo global sourceURL for repo in repos: try: if repo == "aur": url='https://aur.archlinux.org/packages/%s/' %currDirName else: url='https://www.archlinux.org/packages/%s/x86_64/%s/' %(repo, currDirName) website = urllib2.urlopen(url) #print website print '%s FOUND in %s:' %(currDirName, repo) print url break except urllib2.HTTPError, e: print '%s not in %s' %(currDirName, repo) if website: website_text = website.read() #print website_text try: if repo == "aur": archVerList = re.findall('

Package Details: .*? (.*?)

', website_text) archVer = archVerList[0] else: if "- Split Package Details" in website_text: print "This is a split package" aPKGBUILD = urllib2.urlopen("https://git.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/" + currDirName) aPKGBUILD_text = aPKGBUILD.read() archPKGVER = re.findall('pkgver=(.*?)', aPKGBUILD_text) archPKGREL = re.findall('pkgrel=(.*?)', aPKGBUILD_text) archVer = archPKGVER[0] + "-" + archPKGREL[0] else: archVerList = re.findall('', website_text) archVer = archVerList[0] print currDirName + " version in archlinux is: " + archVer except: print "Unable to find archlinux version" try: if repo == "aur": source = re.findall('
  • Download snapshot', website_text) sourceURL = "https://aur.archlinux.org" + source[0] else: if "- Split Package Details" in website_text: #print "Split Pkg" sourceURL = "https://git.archlinux.org/svntogit/packages.git/tree/trunk?h=packages/" + currDirName else: source = re.findall('Source Files', website_text) sourceURL = source[0] #print sourceURL except: print "Unable to find archlinux source link" sourceURL = "" else: print "%s is not found in archlinux repos" %currDirName return archVer def getLHVer(): pkgfile = os.getcwd() + "/PKGBUILD" if not os.path.isfile(pkgfile): print currDirName + " version in LH PKGBUILD is: Unknown" print " Can't find",pkgfile #sys.exit(2) else: LHVer="" variables=["pkgbase", "pkgname", "pkgver", "pkgrel", "epoch"] # Loop over contents to get our variables # Use bash to do it because PKGBUILDs are very loose with their format for item in variables: v = subprocess.Popen(['/bin/bash','-c', 'source ' + pkgfile + '; echo ${' + item + '[@]}'], stdout = subprocess.PIPE,) value = v.communicate()[0].strip('\n') if item == "pkgbase": pkgbase = value elif item == "pkgname": pkgname = value pkglist = list(value.split()) elif item == "epoch": if value: epoch = "%s:" %value LHVer=epoch elif item == "pkgver": pkgver = value elif item == "pkgrel": pkgrel = value LHVer=LHVer + pkgver + "-" + pkgrel print currDirName + " version in LH PKGBUILD is: " + LHVer def getSource(): if yes_all: str1 = "Y" else: str1 = raw_input("\n Press any key to download source from arch, or N to cancel: ") if str1 != 'N' and str1 != 'n': filename=currDirName + ".tar.gz" if repo == "aur": dlSource = sourceURL subprocess.call(["curl", "-O", dlSource]) subprocess.call(["tar", "xvf", filename]) else: if "community" in repo: repoTag = "community" else: repoTag = "packages" subprocess.call(["asp", "update"]) subprocess.call(["asp", "export", currDirName]) #print dlSource if yes_all: str2 = "Y" else: str2 = raw_input("\n Press any key to copy files to pkgdir, or N to cancel: ") if str2 != 'N' and str2 != 'n': if repo == "aur": srcDir = os.getcwd() + "/" + currDirName else: #srcDir = os.getcwd() + "/" + repoTag + "-packages/" + currDirName + "/trunk/" srcDir = os.getcwd() + "/" + currDirName src_files = os.listdir(srcDir) for file_name in src_files: if file_name != ".AURINFO" and file_name != ".SRCINFO": full_file_name = os.path.join(srcDir, file_name) if (os.path.isfile(full_file_name)): shutil.copy(full_file_name, os.getcwd()) subprocess.call("diff -q -x '__arch_LH.diff' -x '__changelog' -x '.SRCINFO' -x '.AURINFO' -x 'pkg' -x 'src' -x '*.pkg.tar.xz' -x '*.pkg.tar.zst' -x 'packages-packages' -x 'community-packages' -x %s -x '*-package.log' -x '*-build.log' -x '%s' ./ %s > ./__arch_LH.diff" % (currDirName,filename, srcDir), shell=True) if os.stat(os.getcwd() + "/__arch_LH.diff").st_size == 0: subprocess.call("rm __arch_LH.diff", shell=True) else: sys.exit(0) if yes_all: str3 = "Y" else: str3 = raw_input("\n Press any key to remove downloads, or N to cancel: ") if str3 != 'N' and str3 != 'n': subprocess.call(["rm", "-r", currDirName]) if repo == "aur": subprocess.call(["rm", filename]) #else: #subprocess.call(["rm", "-r", repoTag + "-packages"]) #subprocess.call(["rm", "-r", currDirName]) else: sys.exit(0) def main(): global currDirName global yes_all current_folder_path, currDirName = os.path.split(os.getcwd()) yes_all = False if "--yes_all" in sys.argv or "-y" in sys.argv: yes_all = True # use command line for currDirName if len(sys.argv) > 1: if not sys.argv[len(sys.argv) - 1].startswith('-'): currDirName = sys.argv[len(sys.argv) - 1] print "Searching for " + currDirName + " on archlinux.org..." archVer = getArchVer() getLHVer() # if archVer != "" and sourceURL != "": if sourceURL != "": getSource() if __name__ == "__main__": print "--------------------------" main() print "--------------------------"