added command line filtering options for BBBD
This commit is contained in:
+62
-29
@@ -1,43 +1,57 @@
|
||||
#! /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()
|
||||
ver = 0.1
|
||||
msg = "bbbd v" + str(ver) + ", a Python Blender Build-bot version downloader script."
|
||||
msg_use = "Usage: bbbd [ARGUMENTS]"
|
||||
|
||||
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:
|
||||
def main():
|
||||
print(msg)
|
||||
try:
|
||||
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"
|
||||
#usage()
|
||||
print('it didn\'t worke')
|
||||
sys.exit(2)
|
||||
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_links(self):
|
||||
def get_branches():
|
||||
branches = []
|
||||
for i in opts:
|
||||
if i[0] == "-b":
|
||||
branches.append(i[1])
|
||||
|
||||
return branches
|
||||
|
||||
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])
|
||||
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
|
||||
|
||||
self.link = masked_links
|
||||
return link
|
||||
|
||||
return self.link
|
||||
def get_masked_links(*ptn):
|
||||
|
||||
def get_masked_links(self,*ptn):
|
||||
links = set(self.links)
|
||||
links = set(get_links())
|
||||
masked_links = set(links)
|
||||
|
||||
for p in ptn:
|
||||
for l in links:
|
||||
if l.find(p) == -1:
|
||||
@@ -45,11 +59,30 @@ class BBBD():
|
||||
masked_links.remove(l)
|
||||
return masked_links
|
||||
|
||||
bd = BBBD()
|
||||
masks = []
|
||||
|
||||
for i in bd.get_masked_links('win',"64.","gooseberry"):
|
||||
print(bd.url+os.sep+i)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user