added command line filtering options for BBBD

master
yorch 11 years ago
parent 3241398e80
commit 6036643e48

@ -1,55 +1,88 @@
#! /usr/bin/env python3 #! /usr/bin/env python3
import urllib.request,re,getopt,os,sys import urllib.request,re,getopt,os,sys
argsx = "--platform=linux --arch=x64 --branch=gooseberry -p=linux -a=x64 -b=gooseberry".split() ver = 0.1
msg = "bbbd v" + str(ver) + ", a Python Blender Build-bot version downloader script."
try: msg_use = "Usage: bbbd [ARGUMENTS]"
print(sys.argv[1:])
opts, args = getopt.getopt(argsx,"p:a:b:",["platform=","arch=","branch="]) def main():
print(args) print(msg)
print('it worked') try:
except getopt.GetoptError as err: args=sys.argv[1:]
opts, args = getopt.getopt(args,"p:a:b:",["platform=","arch=","branch="])
#print help information and exit:
print(str(err)) # will print something like "option -a not recognized" except getopt.GetoptError as err:
#usage() #print help information and exit:
print('it didn\'t worke') print(str(err)) # will print something like "option -a not recognized"
sys.exit(2) #usage()
sys.exit(2)
class BBBD(): url="http://builder.blender.org/download"
def __init__(self): identifiers=['linux','win','OSX','64.','86.']
self.url="http://builder.blender.org/download"
self.links = self.get_links() 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\=\")[^\"]*' ptn='(?<=href\=\")[^\"]*'
source=urllib.request.urlopen(self.url).read().decode("utf-8") source=urllib.request.urlopen(url).read().decode("utf-8")
self.link=(re.findall(ptn,source)) link=(re.findall(ptn,source))
masked_links = [] masked_links = []
for l in range(0,len(self.link)): num_branches = len(get_branches())
if self.link[l].find("blender") != -1:
masked_links.append(self.link[l]) if(num_branches == 0):
for l in range(0,len(link)):
if link[l].find("blender") == 0:
self.link = masked_links 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): def get_masked_links(*ptn):
links = set(self.links)
links = set(get_links())
masked_links = set(links) masked_links = set(links)
for p in ptn: for p in ptn:
for l in links: for l in links:
if l.find(p) == -1: if l.find(p) == -1:
if l in masked_links: if l in masked_links:
masked_links.remove(l) masked_links.remove(l)
return masked_links return masked_links
bd = BBBD() masks = []
for i in bd.get_masked_links('win',"64.","gooseberry"): if ('-p', 'linux') in opts or ('--platform','linux') in opts:
print(bd.url+os.sep+i) 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: #~ for l in links:
#~ print(url+os.sep+l,'/Users/makinegx15/Desktop'+os.sep+l) #~ print(url+os.sep+l,'/Users/makinegx15/Desktop'+os.sep+l)

Loading…
Cancel
Save