def handle(self, *args, **options): release = Release.objects.get(program=options['program'], version=options['version']) dlpath = options['base'] while dlpath[-1] == '/': dlpath = dlpath[:-1] for f in options['file']: self.stdout.write("Adding %s..." % f) filename = os.path.basename(f) data = open(f).read() dl = Download() dl.release = release md5 = hashlib.md5() md5.update(data) dl.md5 = md5.hexdigest() sha1 = hashlib.sha1() sha1.update(data) dl.sha1 = sha1.hexdigest() dl.size = len(data) dl.platform = options['type'] dl.location = '%s/%s' % (dlpath, filename) dl.save()
def handle(self, *args, **options): if len(args) < 5: raise CommandError('Usage: add_file /base/path program version type file...') release = Release.objects.get(program = args[1], version = args[2]) dlpath = args[0] while dlpath[-1] == '/': dlpath = dlpath[:-1] for f in args[4:]: print "Adding %s..." % f path, filename = os.path.split(f) data = open(f).read() dl = Download() dl.release = release md5 = hashlib.md5() md5.update(data) dl.md5 = md5.hexdigest() sha1 = hashlib.sha1() sha1.update(data) dl.sha1 = sha1.hexdigest() dl.size = len(data) dl.platform = args[3] dl.location = '%s/%s' % (dlpath, filename) dl.save()
def handle(self, *args, **options): if len(args) < 5: raise CommandError( 'Usage: add_file /base/path program version type file...') release = Release.objects.get(program=args[1], version=args[2]) dlpath = args[0] while dlpath[-1] == '/': dlpath = dlpath[:-1] for f in args[4:]: self.stdout.write("Adding %s..." % f) filename = os.path.basename(f) data = open(f).read() dl = Download() dl.release = release md5 = hashlib.md5() md5.update(data) dl.md5 = md5.hexdigest() sha1 = hashlib.sha1() sha1.update(data) dl.sha1 = sha1.hexdigest() dl.size = len(data) dl.platform = args[3] dl.location = '%s/%s' % (dlpath, filename) dl.save()
def handle(self, *args, **options): if len(args) > 0: category = None if options['category']: category = Category.objects.get_or_create( title=options['category'], slug=slugify(options['category']))[0] state = 'unpublished' sites = None if options['sites']: state = 'published' sites = [] for site in options['sites']: sites.append(re.escape(site)) sites = Site.objects.filter(domain__regex= r'(' + '|'.join(sites) + ')') count = 0 for root, dir, files in os.walk(args[0]): for name in files: self.stdout.write('Adding ' + root + '/' + name + '\n') download = Download(title=name, primary_category=category, state=state) download.save() for site in sites: download.sites.add(site) f = open(os.path.join(root, name)) download.file.save(name, File(f)) f.close() count += 1 if not options['recursive']: break self.stdout.write('Added ' + str(count) + ' files\n') else: self.stderr.write('No folder path was specified\n')
def handle(self, *args, **options): release = Release.objects.get(program=options['program'], version=options['version']) dlpath = options['base'] while dlpath[-1] == '/': dlpath = dlpath[:-1] for f in options['file']: self.stdout.write("Adding %s..." % f) filename = os.path.basename(f) with open(f, 'rb') as handle: data = handle.read() dl = Download() dl.release = release md5 = hashlib.md5() md5.update(data) dl.md5 = md5.hexdigest() sha1 = hashlib.sha1() sha1.update(data) dl.sha1 = sha1.hexdigest() sha256 = hashlib.sha256() sha256.update(data) dl.sha256 = sha256.hexdigest() dl.size = len(data) dl.platform = options['type'] dl.location = '%s/%s' % (dlpath, filename) dl.save()
def handle(self, *args, **options): release = Release.objects.get(program=options["program"], version=options["version"]) dlpath = options["base"] while dlpath[-1] == "/": dlpath = dlpath[:-1] for f in options["file"]: self.stdout.write("Adding %s..." % f) filename = os.path.basename(f) with open(f, "rb") as handle: data = handle.read() dl = Download() dl.release = release md5 = hashlib.md5() md5.update(data) dl.md5 = md5.hexdigest() sha1 = hashlib.sha1() sha1.update(data) dl.sha1 = sha1.hexdigest() sha256 = hashlib.sha256() sha256.update(data) dl.sha256 = sha256.hexdigest() dl.size = len(data) dl.platform = options["type"] dl.location = f"{dlpath}/{filename}" dl.save()
sys.exit(1) release = Release.objects.get(program = sys.argv[2], version = sys.argv[3]) dlpath = sys.argv[1] while dlpath[-1] == '/': dlpath = dlpath[:-1] for f in sys.argv[5:]: print "Adding %s..." % f path, filename = os.path.split(f) data = open(f).read() dl = Download() dl.release = release md5 = hashlib.md5() md5.update(data) dl.md5 = md5.hexdigest() sha1 = hashlib.sha1() sha1.update(data) dl.sha1 = sha1.hexdigest() dl.size = len(data) dl.platform = sys.argv[4] dl.location = '%s/%s' % (dlpath, filename)