本文整理汇总了Python中clint.textui.progress.bar方法的典型用法代码示例。如果您正苦于以下问题:Python progress.bar方法的具体用法?Python progress.bar怎么用?Python progress.bar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clint.textui.progress
的用法示例。
在下文中一共展示了progress.bar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: downloadGetsploitDb
# 需要导入模块: from clint.textui import progress [as 别名]
# 或者: from clint.textui.progress import bar [as 别名]
def downloadGetsploitDb(self, full_path):
print("Downloading getsploit database archive. Please wait, it may take time. Usually around 5-10 minutes.")
# {'apiKey':self._Vulners__api_key}
download_request = self._Vulners__opener.get(self.vulners_urls['searchsploitdb'], stream = True)
with open(full_path, 'wb') as f:
total_length = int(download_request.headers.get('content-length'))
for chunk in progress.bar(download_request.iter_content(chunk_size=1024), expected_size=(total_length / 1024) + 1):
if chunk:
f.write(chunk)
f.flush()
print("\nUnpacking database.")
zip_ref = zipfile.ZipFile(full_path, 'r')
zip_ref.extractall(DBPATH)
zip_ref.close()
os.remove(full_path)
return True
示例2: handle
# 需要导入模块: from clint.textui import progress [as 别名]
# 或者: from clint.textui.progress import bar [as 别名]
def handle(self, *args, **options):
with transaction.atomic():
for label in progress.bar(ShapeSubstanceLabel.objects.all()):
new_hit_settings = label.mturk_assignment.hit.hit_type.experiment.new_hit_settings
shape = label.shape
substance = label.substance
if (shape.substances.filter(substance=substance).count() >=
new_hit_settings.min_assignment_consensus):
shape.substance = substance
shape.update_entropy(save=False)
shape.save()
with transaction.atomic():
for label in progress.bar(MaterialShapeNameLabel.objects.all()):
new_hit_settings = label.mturk_assignment.hit.hit_type.experiment.new_hit_settings
shape = label.shape
name = label.name
if (shape.names.filter(name=name).count() >=
new_hit_settings.min_assignment_consensus):
shape.name = name
shape.update_entropy(save=False)
shape.save()
示例3: handle
# 需要导入模块: from clint.textui import progress [as 别名]
# 或者: from clint.textui.progress import bar [as 别名]
def handle(self, *args, **options):
print ('This will delete all material shapes, '
'thereby deleting all quality votes and '
'any derivative items')
if raw_input("Are you sure? [y/n] ").lower() != "y":
print 'Exiting'
return
if raw_input("Is it backed up? [y/n] ").lower() != "y":
print 'Exiting'
return
# delete existing shapes
for shape in progress.bar(MaterialShape.objects.all()):
for f in shape._ik.spec_files:
f.delete()
shape.delete()
# schedule new ones to be computed
for photo in progress.bar(Photo.objects.all()):
retriangulate_material_shapes_task.delay(photo)
示例4: handle
# 需要导入模块: from clint.textui import progress [as 别名]
# 或者: from clint.textui.progress import bar [as 别名]
def handle(self, *args, **options):
qset = PhotoWhitebalanceLabel.objects.filter(
whitebalanced=F('photo__whitebalanced')
)
out = []
for label in progress.bar(qset):
photo = label.photo.__class__.objects.get(id=label.photo.id)
pil = open_image(photo.image_300)
points_list = label.points.split(',')
for idx in xrange(label.num_points):
x = float(points_list[idx * 2]) * pil.size[0]
y = float(points_list[idx * 2 + 1]) * pil.size[1]
rgb = pil.getpixel((x, y))
out.append([c / 255.0 for c in rgb])
out = np.array(out)
np.save(args[0] if args else 'whitebalance_clicks.npy', out)
示例5: chunk_list_generator
# 需要导入模块: from clint.textui import progress [as 别名]
# 或者: from clint.textui.progress import bar [as 别名]
def chunk_list_generator(lst, chunksize):
""" Generator that chunks a list ``lst`` into sublists of size ``chunksize`` """
if lst:
chunksize = max(chunksize, 1)
for i in xrange(0, len(lst), chunksize):
yield lst[i:i + chunksize]
#def queryset_batch_delete(queryset, batch_size=100000, show_progress=False):
#""" Delete a large queryset, batching into smaller queries (sometimes huge
#commands crash) """
#if show_progress:
#print 'queryset_batch_delete: fetching ids for %s' % queryset.model
#ids = queryset.values_list('pk', flat=True)
#if len(ids) <= batch_size:
#queryset.delete()
#else:
#iterator = range(0, len(ids), batch_size)
#if show_progress:
#progress.bar(iterator)
#for i in iterator:
#queryset.filter(pk__in=ids[i:i+batch_size]).delete()
#return len(ids)
示例6: handle
# 需要导入模块: from clint.textui import progress [as 别名]
# 或者: from clint.textui.progress import bar [as 别名]
def handle(self, *args, **options):
storage = DefaultStorage()
for model in _get_models(['shapes', 'photos', 'shapes']):
has_images = False
# transfer image fields
for f in model._meta.fields:
if isinstance(f, models.ImageField):
has_images = True
if hasattr(storage, 'transfer'):
filenames = model.objects.all() \
.values_list(f.name, flat=True)
print '%s: %s' % (model, f)
for filename in progress.bar(filenames):
if filename and storage.local.exists(filename):
storage.transfer(filename)
# transfer thumbs
if has_images:
print '%s: thumbnails' % model
ids = model.objects.all().values_list('id', flat=True)
ct_id = ContentType.objects.get_for_model(model).id
for id in progress.bar(ids):
ensure_thumbs_exist_task.delay(ct_id, id)
示例7: add_nodes
# 需要导入模块: from clint.textui import progress [as 别名]
# 或者: from clint.textui.progress import bar [as 别名]
def add_nodes(self):
"""
Register displayed texts.
"""
for t in progress.bar(Text_Index.rank_texts()):
text = t['text']
self.graph.add_node(text.id, dict(
label = text.pretty('title'),
author = text.pretty('surname'),
count = text.count,
score = t['score'],
))
示例8: query_bar
# 需要导入模块: from clint.textui import progress [as 别名]
# 或者: from clint.textui.progress import bar [as 别名]
def query_bar(query):
"""
Wrap a query in a progress bar.
Args:
query (peewee.Query): A query instance.
Returns:
The query, wrapped in a progress bar.
"""
size = query.count()
return progress.bar(
ServerSide(query.naive()),
expected_size=size
)
示例9: download_fasttext
# 需要导入模块: from clint.textui import progress [as 别名]
# 或者: from clint.textui.progress import bar [as 别名]
def download_fasttext(self):
# Open the url and download the data with progress bars.
data_stream = requests.get('https://dl.fbaipublicfiles.com/fasttext/' +
'vectors-english/wiki-news-300d-1M.vec.zip', stream=True)
zipped_path = os.path.join(self.input_dir, 'fasttext.zip')
with open(zipped_path, 'wb') as file:
total_length = int(data_stream.headers.get('content-length'))
for chunk in progress.bar(data_stream.iter_content(chunk_size=1024),
expected_size=total_length / 1024 + 1):
if chunk:
file.write(chunk)
file.flush()
# Extract file.
zip_file = zipfile.ZipFile(zipped_path, 'r')
zip_file.extractall(self.input_dir)
zip_file.close()
# Generate a vocab from data files.
示例10: download_data
# 需要导入模块: from clint.textui import progress [as 别名]
# 或者: from clint.textui.progress import bar [as 别名]
def download_data(self, train_mode):
'''
Params:
:train_mode: Whether we are in train or dev mode.
'''
# Open the url and download the data with progress bars.
data_stream = requests.get(self._url, stream=True)
with open(self._zipped_data, 'wb') as file:
total_length = int(data_stream.headers.get('content-length'))
for chunk in progress.bar(data_stream.iter_content(chunk_size=1024),
expected_size=total_length / 1024 + 1):
if chunk:
file.write(chunk)
file.flush()
# Next step is extracting the data.
print('t2t_csaky_log: Extracting data to ' + self._zipped_data + '.')
self.extract_data(train_mode)
# Extract data and go to the next step.
示例11: download_data
# 需要导入模块: from clint.textui import progress [as 别名]
# 或者: from clint.textui.progress import bar [as 别名]
def download_data(url, zipped_path, extract):
# Open the url and download the data with progress bars.
data_stream = requests.get(url, stream=True)
with open(zipped_path, 'wb') as file:
total_length = int(data_stream.headers.get('content-length'))
for chunk in progress.bar(data_stream.iter_content(chunk_size=1024),
expected_size=total_length / 1024 + 1):
if chunk:
file.write(chunk)
file.flush()
# Extract file.
zip_file = zipfile.ZipFile(zipped_path, 'r')
zip_file.extractall(extract)
zip_file.close()
示例12: index
# 需要导入模块: from clint.textui import progress [as 别名]
# 或者: from clint.textui.progress import bar [as 别名]
def index(self, text, terms=None, **kwargs):
"""
Index all term pair distances.
Args:
text (Text): The source text.
terms (list): Terms to index.
"""
self.clear()
# By default, use all terms.
terms = terms or text.terms.keys()
pairs = combinations(terms, 2)
count = comb(len(terms), 2)
for t1, t2 in bar(pairs, expected_size=count, every=1000):
# Set the Bray-Curtis distance.
score = text.score_braycurtis(t1, t2, **kwargs)
self.set_pair(t1, t2, score)
示例13: download_package
# 需要导入模块: from clint.textui import progress [as 别名]
# 或者: from clint.textui.progress import bar [as 别名]
def download_package(self, query_id, format, progressbar=False):
url = self.PACKAGE_DOWNLOAD_URL.format(query_id=query_id, format=format)
logger.info('Downloading package for queryId=%s with format=%s. url=%s', query_id, format, url)
response = self.session.get(url, stream=progressbar)
assert response.status_code in [200, 302], 'No download package. status={}'.format(response.status_code)
assert response.headers['Content-Type'] == 'application/zip'
if not progressbar:
return response.content
else:
# https://stackoverflow.com/questions/15644964/python-progress-bar-and-downloads/20943461#20943461
total_length = int(response.headers.get('Content-Length'))
buffer = BytesIO()
for chunk in progress.bar(response.iter_content(chunk_size=1024), expected_size=(total_length/1024) + 1, filled_char='='):
if chunk:
buffer.write(chunk)
buffer.seek(0)
return buffer.read()
示例14: download_dataset
# 需要导入模块: from clint.textui import progress [as 别名]
# 或者: from clint.textui.progress import bar [as 别名]
def download_dataset(url, dl_path):
"""
Download filtered etymwn from jmsv.me mirror, displaying progress bar
"""
r = requests.get(url, stream=True)
with open(dl_path, "wb") as f:
total_length = int(r.headers.get("content-length"))
chunk_size = 4096
for chunk in progress.bar(
r.iter_content(chunk_size=chunk_size),
expected_size=(total_length / chunk_size) + 1,
):
if chunk:
f.write(chunk)
f.flush()
print("Downloaded to " + dl_path)
示例15: progress_bar
# 需要导入模块: from clint.textui import progress [as 别名]
# 或者: from clint.textui.progress import bar [as 别名]
def progress_bar(enumerable, logger, **kwargs):
"""
Show the progress bar in the terminal, if the logging level matches and we are interactive.
:param enumerable: The iterator of which we indicate the progress.
:param logger: The bound logging.Logger.
:param kwargs: Keyword arguments to pass to clint.textui.progress.bar.
:return: The wrapped iterator.
"""
if not logger.isEnabledFor(logging.INFO) or sys.stdin.closed or not sys.stdin.isatty():
return enumerable
return progress.bar(enumerable, **kwargs)