From 6036643e480c438417893c16e7105d5d666740ed Mon Sep 17 00:00:00 2001 From: yorch Date: Mon, 15 Dec 2014 12:39:38 -0800 Subject: [PATCH] added command line filtering options for BBBD --- python/bbbd.py | 105 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 69 insertions(+), 36 deletions(-) diff --git a/python/bbbd.py b/python/bbbd.py index 2d8ca32..bd6a5d2 100755 --- a/python/bbbd.py +++ b/python/bbbd.py @@ -1,55 +1,88 @@ #! /usr/bin/env python3 import urllib.request,re,getopt,os,sys -argsx = "--platform=linux --arch=x64 --branch=gooseberry -p=linux -a=x64 -b=gooseberry".split() - -try: - print(sys.argv[1:]) - opts, args = getopt.getopt(argsx,"p:a:b:",["platform=","arch=","branch="]) - print(args) - print('it worked') -except getopt.GetoptError as err: - - #print help information and exit: - print(str(err)) # will print something like "option -a not recognized" - #usage() - print('it didn\'t worke') - sys.exit(2) +ver = 0.1 +msg = "bbbd v" + str(ver) + ", a Python Blender Build-bot version downloader script." +msg_use = "Usage: bbbd [ARGUMENTS]" + +def main(): + print(msg) + try: + args=sys.argv[1:] + opts, args = getopt.getopt(args,"p:a:b:",["platform=","arch=","branch="]) + + except getopt.GetoptError as err: + #print help information and exit: + print(str(err)) # will print something like "option -a not recognized" + #usage() + sys.exit(2) -class BBBD(): - def __init__(self): - self.url="http://builder.blender.org/download" - self.links = self.get_links() + url="http://builder.blender.org/download" + identifiers=['linux','win','OSX','64.','86.'] + + def get_branches(): + branches = [] + for i in opts: + if i[0] == "-b": + branches.append(i[1]) + + return branches - def get_links(self): + def get_links(): ptn='(?<=href\=\")[^\"]*' - source=urllib.request.urlopen(self.url).read().decode("utf-8") - self.link=(re.findall(ptn,source)) + source=urllib.request.urlopen(url).read().decode("utf-8") + link=(re.findall(ptn,source)) masked_links = [] - for l in range(0,len(self.link)): - if self.link[l].find("blender") != -1: - masked_links.append(self.link[l]) - - - self.link = masked_links + num_branches = len(get_branches()) + + if(num_branches == 0): + for l in range(0,len(link)): + if link[l].find("blender") == 0: + masked_links.append(link[l]) + elif (num_branches>0): + for l in range(0,len(link)): + if link[l].find("blender") != -1: + masked_links.append(link[l]) + link = masked_links - return self.link + return link - def get_masked_links(self,*ptn): - links = set(self.links) + def get_masked_links(*ptn): + + links = set(get_links()) masked_links = set(links) + for p in ptn: for l in links: if l.find(p) == -1: if l in masked_links: masked_links.remove(l) return masked_links - -bd = BBBD() - -for i in bd.get_masked_links('win',"64.","gooseberry"): - print(bd.url+os.sep+i) - + + masks = [] + + if ('-p', 'linux') in opts or ('--platform','linux') in opts: + masks.append(identifiers[0]) + if ('-p', 'win') in opts or ('--platform','win') in opts: + masks.append(identifiers[1]) + if ('-p', 'mac') in opts or ('--platform','mac') in opts: + masks.append(identifiers[2]) + if ('-a', 'x64') in opts or ('--arch','x64') in opts: + masks.append(identifiers[3]) + if ('-a', 'x32') in opts or ('--arch','x32') in opts: + masks.append(identifiers[4]) + + print(get_branches()) + + for i in opts: + if i[0] == "-b" and i[1] != "all" : + masks.append(i[1]) + print(opts) + for i in get_masked_links(*masks): + print(url+os.sep+i) + +if __name__: + main() #~ for l in links: #~ print(url+os.sep+l,'/Users/makinegx15/Desktop'+os.sep+l)