summaryrefslogtreecommitdiffstats
path: root/build_tools/bin/chk_arch_pkg.py
diff options
context:
space:
mode:
Diffstat (limited to 'build_tools/bin/chk_arch_pkg.py')
-rwxr-xr-xbuild_tools/bin/chk_arch_pkg.py181
1 files changed, 181 insertions, 0 deletions
diff --git a/build_tools/bin/chk_arch_pkg.py b/build_tools/bin/chk_arch_pkg.py
new file mode 100755
index 0000000..e995fff
--- /dev/null
+++ b/build_tools/bin/chk_arch_pkg.py
@@ -0,0 +1,181 @@
+#!/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=['core', 'extra', '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('<h2>Package Details: .*? (.*?)</h2>', website_text)
+ else:
+ if "- Split Package Details</title>" in website_text:
+ print "This is a split package"
+ aPKGBUILD = urllib2.urlopen("https://projects.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/" + currDirName)
+ aPKGBUILD_text = aPKGBUILD.read()
+ archPKGVER = re.findall('pkgver<span class="hl opt">=</span><span class="hl num">(.*?)</span>', aPKGBUILD_text)
+ archPKGREL = re.findall('pkgrel<span class="hl opt">=</span><span class="hl num">(.*?)</span>', aPKGBUILD_text)
+ archVer = archPKGVER[0] + "-" + archPKGREL[0]
+ else:
+ archVerList = re.findall('<meta itemprop="softwareVersion" content="(.*?)"/>', 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('<li><a href="(.*?)">Download tarball</a></li>', website_text)
+ sourceURL = "https://aur.archlinux.org" + source[0]
+ else:
+ if "- Split Package Details</title>" in website_text:
+ #print "Split Pkg"
+ sourceURL = "https://projects.archlinux.org/svntogit/packages.git/tree/trunk?h=packages/" + currDirName
+ else:
+ source = re.findall('<a href="(.*?)" title="View source files for .*?">Source Files</a>', 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':
+ if repo == "aur":
+ dlSource = sourceURL
+ else:
+ if repo == "community":
+ repoTag = "community"
+ else:
+ repoTag = "packages"
+ dlSource = 'https://projects.archlinux.org/svntogit/%s.git/snapshot/%s-packages/%s.tar.gz' %(repoTag, repoTag, currDirName)
+
+ print dlSource
+ subprocess.call(["curl", "-O", dlSource])
+ filename=currDirName + ".tar.gz"
+ subprocess.call(["tar", "xvf", filename])
+
+ 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/"
+ src_files = os.listdir(srcDir)
+ for file_name in src_files:
+ if file_name != ".AURINFO":
+ full_file_name = os.path.join(srcDir, file_name)
+ if (os.path.isfile(full_file_name)):
+ shutil.copy(full_file_name, os.getcwd())
+ 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", filename])
+ if repo == "aur":
+ subprocess.call(["rm", "-r", currDirName])
+ else:
+ subprocess.call(["rm", "-r", repoTag + "-packages"])
+ 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
+
+ print "Searching for " + currDirName + " on archlinux.org..."
+ archVer = getArchVer()
+ getLHVer()
+ if archVer != "" and sourceURL != "":
+ getSource()
+
+if __name__ == "__main__":
+ print "--------------------------"
+ main()
+ print "--------------------------"
+