From 3241398e80fe009270957fe7b63d7cb3e2156b33 Mon Sep 17 00:00:00 2001 From: yorch Date: Thu, 11 Dec 2014 10:17:28 -0800 Subject: [PATCH] Started to add support for options to filter the versions to be downloaded --- python/bbbd.py | 80 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 23 deletions(-) diff --git a/python/bbbd.py b/python/bbbd.py index 5a3252e..2d8ca32 100755 --- a/python/bbbd.py +++ b/python/bbbd.py @@ -1,23 +1,57 @@ -import urllib.request,re,getopt,os -url="http://builder.blender.org/download" - - -def get_links(**options): - ptn='(?<=href\=\")[^\"]*' - source=urllib.request.urlopen(url).read().decode("utf-8") - links=(re.findall(ptn,source)) - masked_links = [] - for l in range(0,len(links)): - if links[l].find("blender") != -1: - masked_links.append(links[l]) - try: - opt = options.get() - except TypeError: - opt = "none" - return masked_links -links = get_links() - -for l in links: - print(url+os.sep+l,'/Users/makinegx15/Desktop'+os.sep+l) - urllib.request.urlretrieve(url+os.sep+l,'/Users/makinegx15/Desktop'+os.sep+l) - print('downloaded :'+l) +#! /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) + +class BBBD(): + def __init__(self): + self.url="http://builder.blender.org/download" + self.links = self.get_links() + + def get_links(self): + ptn='(?<=href\=\")[^\"]*' + source=urllib.request.urlopen(self.url).read().decode("utf-8") + self.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 + + return self.link + + def get_masked_links(self,*ptn): + links = set(self.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) + + +#~ for l in links: + #~ print(url+os.sep+l,'/Users/makinegx15/Desktop'+os.sep+l) + #~ urllib.request.urlretrieve(url+os.sep+l,'/Users/makinegx15/Desktop'+os.sep+l) + #~ print('downloaded :'+l)