本文整理匯總了Python中click.progressbar方法的典型用法代碼示例。如果您正苦於以下問題:Python click.progressbar方法的具體用法?Python click.progressbar怎麽用?Python click.progressbar使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類click
的用法示例。
在下文中一共展示了click.progressbar方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: index_json
# 需要導入模塊: import click [as 別名]
# 或者: from click import progressbar [as 別名]
def index_json(filenames, force):
"""Index JSON-based vocabularies in Elasticsearch."""
if not force:
click.confirm(
"Are you sure you want to index the vocabularies?",
abort=True
)
source = "json"
index_count = 0
for filename in filenames:
click.echo('indexing vocabularies in {}...'.format(filename))
vocabularies = load_vocabularies(source, filename)
cfg = current_app.config["RECORDS_REST_ENDPOINTS"][VOCABULARY_PID_TYPE]
indexer = cfg["indexer_class"]()
with click.progressbar(vocabularies) as bar:
for vocabulary in bar:
indexer.index(vocabulary)
index_count += len(vocabularies)
click.echo('indexed {} vocabularies'.format(index_count))
示例2: index_opendefinition
# 需要導入模塊: import click [as 別名]
# 或者: from click import progressbar [as 別名]
def index_opendefinition(loader, path, whitelist_status, force):
"""Index JSON-based vocabularies in Elasticsearch."""
if not force:
click.confirm(
"Are you sure you want to index the vocabularies?",
abort=True
)
index_count = 0
click.echo('indexing licenses from loader {} and path {}...'.format(
loader,
path
))
if whitelist_status:
whitelist_status = whitelist_status.split(",")
vocabularies = load_vocabularies(
"opendefinition", loader, path, whitelist_status
)
cfg = current_app.config["RECORDS_REST_ENDPOINTS"][VOCABULARY_PID_TYPE]
indexer = cfg["indexer_class"]()
with click.progressbar(vocabularies) as bar:
for vocabulary in bar:
indexer.index(vocabulary)
index_count += len(vocabularies)
click.echo('indexed {} licenses'.format(index_count))
示例3: progressbar
# 需要導入模塊: import click [as 別名]
# 或者: from click import progressbar [as 別名]
def progressbar(self, label: str, total: int):
bar = progressbar(
length=total,
fill_char=stream.green(self.BAR_FILLED_CHAR),
empty_char=self.BAR_EMPTY_CHAR,
show_percent=False,
show_pos=True,
label=label,
bar_template="%(label)s %(bar)s %(info)s",
)
if self.parallel:
executor = ThreadPoolExecutor()
else:
executor = DummyExecutor()
with executor:
try:
yield bar, executor
except KeyboardInterrupt:
pass
示例4: start
# 需要導入模塊: import click [as 別名]
# 或者: from click import progressbar [as 別名]
def start(self):
itercontent = self._request.iter_content(chunk_size=self.CHUNK_SIZE)
f = open(self._destination, "wb")
chunks = int(ceil(self.get_size() / float(self.CHUNK_SIZE)))
if util.is_ci():
click.echo("Downloading...")
for _ in range(0, chunks):
f.write(next(itercontent))
else:
with click.progressbar(length=chunks, label="Downloading") as pb:
for _ in pb:
f.write(next(itercontent))
f.close()
self._request.close()
self._preserve_filemtime(self.get_lmtime())
示例5: progress_bar
# 需要導入模塊: import click [as 別名]
# 或者: from click import progressbar [as 別名]
def progress_bar(self, arg):
"""Returns a pre-configured Click progress bar to use with downloads.
If chapter uses separate page downloads, page download progress is
shown (e.g. '7/20').
"""
if self.uses_pages:
iterable = arg
length = None
else:
iterable = None
length = arg
click.echo('{c.alias} {c.chapter}'.format(c=self))
return click.progressbar(iterable=iterable, length=length,
fill_char='>', empty_char=' ',
show_pos=self.uses_pages, show_percent=True)
示例6: load_fixture
# 需要導入模塊: import click [as 別名]
# 或者: from click import progressbar [as 別名]
def load_fixture(fixture_file):
"""
Populate the database from a JSON file. Reads the JSON file FIXTURE_FILE
and uses it to populate the database. Fuxture files should consist of a
dictionary mapping database names to arrays of objects to store in those
databases.
"""
utils.check_for_local_server()
local_url = config["local_server"]["url"]
server = Server(local_url)
fixture = json.load(fixture_file)
for db_name, _items in fixture.items():
db = server[db_name]
with click.progressbar(
_items, label=db_name, length=len(_items)
) as items:
for item in items:
item_id = item["_id"]
if item_id in db:
old_item = db[item_id]
item["_rev"] = old_item["_rev"]
if item == old_item:
continue
db[item_id] = item
示例7: run
# 需要導入模塊: import click [as 別名]
# 或者: from click import progressbar [as 別名]
def run(self):
models = {model: self.make_query(model).count() for model in StoredFileMixin.__subclasses__()}
models = {model: total for model, total in models.iteritems() if total}
labels = {model: cformat('Processing %{blue!}{}%{reset} (%{cyan}{}%{reset} rows)').format(model.__name__, total)
for model, total in models.iteritems()}
max_length = max(len(x) for x in labels.itervalues())
labels = {model: label.ljust(max_length) for model, label in labels.iteritems()}
for model, total in sorted(models.items(), key=itemgetter(1)):
with click.progressbar(self.query_chunked(model, 1000), length=total, label=labels[model],
show_percent=True, show_pos=True) as objects:
for obj in self.flush_rclone_iterator(objects, 1000):
try:
self.process_obj(obj)
except Exception as exc:
click.echo(cformat('\n%{red!}Error processing %{reset}%{yellow}{}%{red!}: %{reset}%{yellow!}{}')
.format(obj, exc))
click.secho('All done!', fg='green')
click.echo('Add the following entries to your STORAGE_BACKENDS:')
for bucket, data in sorted(self.buckets.viewitems(), key=itemgetter(0)):
click.echo("'{}': 's3-readonly:host={},bucket={}',".format(
data['backend'], self.s3_endpoint.replace('https://', ''), bucket))
示例8: run
# 需要導入模塊: import click [as 別名]
# 或者: from click import progressbar [as 別名]
def run(url):
response = requests.get(url + '/', auth=('baseline', 'request'))
if response.status_code != 401:
click.echo(click.style('AEM authentication is not available', fg='red'))
return
click.echo(click.style('AEM authentication is available', fg='green'))
with open(os.path.dirname(__file__) + '/../data/aem-default-creds.txt', 'r') as f:
creds = map(string.strip, f.readlines())
found = []
with click.progressbar(creds, label='Checking default credentials') as bar:
for line in bar:
(login, password) = line.split(':')
response = requests.post(url + '/', auth=(login, password))
if response.status_code == 200:
found.append(line)
if found:
click.echo(click.style('Found {} default credentials!'.format(len(found)), fg='green'))
for item in found:
click.echo(click.style('{}'.format(item), fg='green'))
示例9: convert
# 需要導入模塊: import click [as 別名]
# 或者: from click import progressbar [as 別名]
def convert(association, ontology, output, association_file):
click.echo("converting {}".format(association))
rdfWriter = assoc_rdfgen.TurtleRdfWriter(label=os.path.basename(output.name))
rdfTransformer = assoc_rdfgen.CamRdfTransform(writer=rdfWriter)
parser_config = assocparser.AssocParserConfig(ontology=make_ontology(ontology))
parser = _association_parser(association, parser_config)
with open(association_file) as af:
lines = sum(1 for line in af)
with open(association_file) as af:
associations = parser.association_generator(file=af)
with click.progressbar(iterable=associations, length=lines) as assocs:
for assoc in assocs:
rdfTransformer.provenance()
rdfTransformer.translate(assoc)
click.echo("Writing ttl to disk")
rdfWriter.serialize(destination=output)
示例10: produce_gpi
# 需要導入模塊: import click [as 別名]
# 或者: from click import progressbar [as 別名]
def produce_gpi(dataset, target_dir, gaf_path, ontology_graph):
gafparser = GafParser()
gafparser.config = assocparser.AssocParserConfig(
ontology=ontology_graph
)
with open(gaf_path) as sg:
lines = sum(1 for line in sg)
gpi_path = os.path.join(os.path.split(gaf_path)[0], "{}.gpi".format(dataset))
with open(gaf_path) as gf, open(gpi_path, "w") as gpi:
click.echo("Using {} as the gaf to build gpi with".format(gaf_path))
bridge = gafgpibridge.GafGpiBridge()
gpiwriter = entitywriter.GpiWriter(file=gpi)
gpi_cache = set()
with click.progressbar(iterable=gafparser.association_generator(file=gf), length=lines) as associations:
for association in associations:
entity = bridge.convert_association(association)
if entity not in gpi_cache and entity is not None:
# If the entity is not in the cache, add it and write it out
gpi_cache.add(entity)
gpiwriter.write_entity(entity)
return gpi_path
示例11: cli
# 需要導入模塊: import click [as 別名]
# 或者: from click import progressbar [as 別名]
def cli(obj, ids, query, filters, attributes):
"""Update alert attributes."""
client = obj['client']
if ids:
total = len(ids)
else:
if query:
query = [('q', query)]
else:
query = build_query(filters)
total, _, _ = client.get_count(query)
ids = [a.id for a in client.get_alerts(query)]
with click.progressbar(ids, label='Updating {} alerts'.format(total)) as bar:
for id in bar:
client.update_attributes(id, dict(a.split('=') for a in attributes))
示例12: cli
# 需要導入模塊: import click [as 別名]
# 或者: from click import progressbar [as 別名]
def cli(obj, ids, query, filters, tags):
"""Add tags to alerts."""
client = obj['client']
if ids:
total = len(ids)
else:
if query:
query = [('q', query)]
else:
query = build_query(filters)
total, _, _ = client.get_count(query)
ids = [a.id for a in client.get_alerts(query)]
with click.progressbar(ids, label='Tagging {} alerts'.format(total)) as bar:
for id in bar:
client.tag_alert(id, tags)
示例13: cli
# 需要導入模塊: import click [as 別名]
# 或者: from click import progressbar [as 別名]
def cli(obj, ids, query, filters):
"""Delete alerts."""
client = obj['client']
if ids:
total = len(ids)
else:
if not (query or filters):
click.confirm('Deleting all alerts. Do you want to continue?', abort=True)
if query:
query = [('q', query)]
else:
query = build_query(filters)
total, _, _ = client.get_count(query)
ids = [a.id for a in client.get_alerts(query)]
with click.progressbar(ids, label='Deleting {} alerts'.format(total)) as bar:
for id in bar:
client.delete_alert(id)
示例14: cli
# 需要導入模塊: import click [as 別名]
# 或者: from click import progressbar [as 別名]
def cli(obj, ids, alert_ids, query, filters, text, delete):
"""Add or delete note to alerts."""
client = obj['client']
if delete:
client.delete_alert_note(*delete)
else:
if alert_ids:
total = len(alert_ids)
else:
if query:
query = [('q', query)]
else:
query = build_query(filters)
total, _, _ = client.get_count(query)
alert_ids = [a.id for a in client.get_alerts(query)]
with click.progressbar(alert_ids, label='Add note to {} alerts'.format(total)) as bar:
for id in bar:
client.alert_note(id, text=text)
示例15: cli
# 需要導入模塊: import click [as 別名]
# 或者: from click import progressbar [as 別名]
def cli(obj, ids, query, filters, tags):
"""Remove tags from alerts."""
client = obj['client']
if ids:
total = len(ids)
else:
if query:
query = [('q', query)]
else:
query = build_query(filters)
total, _, _ = client.get_count(query)
ids = [a.id for a in client.get_alerts(query)]
with click.progressbar(ids, label='Untagging {} alerts'.format(total)) as bar:
for id in bar:
client.untag_alert(id, tags)