本文整理匯總了Python中humanize.naturaltime方法的典型用法代碼示例。如果您正苦於以下問題:Python humanize.naturaltime方法的具體用法?Python humanize.naturaltime怎麽用?Python humanize.naturaltime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類humanize
的用法示例。
在下文中一共展示了humanize.naturaltime方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_mesos_running_tasks_table
# 需要導入模塊: import humanize [as 別名]
# 或者: from humanize import naturaltime [as 別名]
def create_mesos_running_tasks_table(running_tasks):
rows = []
table_header = [
"Mesos Task ID",
"Host deployed to",
"Ram",
"CPU",
"Deployed at what localtime",
]
rows.append(table_header)
for task in running_tasks or []:
mem_string = get_mesos_task_memory_string(task)
cpu_string = get_mesos_task_cpu_string(task)
deployed_at = datetime.fromtimestamp(task.deployed_timestamp)
deployed_at_string = "{} ({})".format(
deployed_at.strftime("%Y-%m-%dT%H:%M"), humanize.naturaltime(deployed_at)
)
rows.append(
[task.id, task.hostname, mem_string, cpu_string, deployed_at_string]
)
rows.extend(format_tail_lines_for_mesos_task(task.tail_lines, task.id))
return format_table(rows)
示例2: create_mesos_non_running_tasks_table
# 需要導入模塊: import humanize [as 別名]
# 或者: from humanize import naturaltime [as 別名]
def create_mesos_non_running_tasks_table(non_running_tasks):
rows = []
table_header = [
"Mesos Task ID",
"Host deployed to",
"Deployed at what localtime",
"Status",
]
rows.append(table_header)
for task in non_running_tasks or []:
if task.deployed_timestamp is None:
deployed_at_string = "Unknown"
else:
deployed_at = datetime.fromtimestamp(task.deployed_timestamp)
deployed_at_string = "{} ({})".format(
deployed_at.strftime("%Y-%m-%dT%H:%M"),
humanize.naturaltime(deployed_at),
)
rows.append([task.id, task.hostname, deployed_at_string, task.state])
rows.extend(format_tail_lines_for_mesos_task(task.tail_lines, task.id))
table = format_table(rows)
return [PaastaColors.grey(formatted_row) for formatted_row in table]
示例3: format_kubernetes_replicaset_table
# 需要導入模塊: import humanize [as 別名]
# 或者: from humanize import naturaltime [as 別名]
def format_kubernetes_replicaset_table(replicasets):
rows = [("ReplicaSet Name", "Ready / Desired", "Created at what localtime")]
for replicaset in replicasets:
local_created_datetime = datetime.fromtimestamp(replicaset.create_timestamp)
replica_status = f"{replicaset.ready_replicas}/{replicaset.replicas}"
if replicaset.ready_replicas >= replicaset.replicas:
replica_status = PaastaColors.green(replica_status)
else:
replica_status = PaastaColors.red(replica_status)
rows.append(
(
replicaset.name,
replica_status,
"{} ({})".format(
local_created_datetime.strftime("%Y-%m-%dT%H:%M"),
humanize.naturaltime(local_created_datetime),
),
)
)
return format_table(rows)
示例4: get_services
# 需要導入模塊: import humanize [as 別名]
# 或者: from humanize import naturaltime [as 別名]
def get_services(ctx, cluster, sort_by):
if not cluster:
cluster = ctx.obj['cluster']
bw = ctx.obj['bw']
records = bw.get_services(cluster=cluster)
if sort_by:
records.sort(key=lambda r: jp(r, sort_by))
out = []
now = datetime.datetime.now(pytz.utc)
for r in records:
service_name = r['serviceName']
task_def = display.simple_task_definition(r['taskDefinition'])
status = r['status']
created_at = r['createdAt']
desired_count = r['desiredCount']
running_count = r['runningCount']
age = humanize.naturaltime(now - created_at)
row = (service_name, task_def, desired_count,
running_count, status, age)
out.append(row)
headers = ['NAME', 'TASK DEFINITION', 'DESIRED', 'RUNNING',
'STATUS', 'AGE']
output = tabulate.tabulate(out, headers=headers, tablefmt='plain')
click.echo(output)
示例5: get_task
# 需要導入模塊: import humanize [as 別名]
# 或者: from humanize import naturaltime [as 別名]
def get_task(ctx, cluster, sort_by):
if not cluster:
cluster = ctx.obj['cluster']
bw = ctx.obj['bw']
records = bw.get_tasks(cluster=cluster)
if sort_by:
records.sort(key=lambda r: jp(r, sort_by))
out = []
now = datetime.datetime.now(pytz.utc)
for r in records:
status = r['lastStatus']
created_at = r['createdAt']
task_id = display.simple_task(r['taskArn'])
task_def = display.simple_task_definition(r['taskDefinitionArn'])
age = humanize.naturaltime(now - created_at)
row = (task_id, status, task_def, age)
out.append(row)
headers = ['TASK ID', 'STATUS', 'TASK DEFINITION', 'AGE']
output = tabulate.tabulate(out, headers=headers, tablefmt='plain')
click.echo(output)
示例6: list
# 需要導入模塊: import humanize [as 別名]
# 或者: from humanize import naturaltime [as 別名]
def list():
"""Returns a list of snapshots"""
snapshots = get_app().get_snapshots()
click.echo('\n'.join(
'%s: %s' % (
s.snapshot_name,
humanize.naturaltime(datetime.utcnow() - s.created_at)
)
for s in snapshots
))
示例7: ago_filter
# 需要導入模塊: import humanize [as 別名]
# 或者: from humanize import naturaltime [as 別名]
def ago_filter(dt):
"""
Format a datetime using humanize.naturaltime, "ago"
:param dt: datetime to compare to now
:type dt: datetime.datetime
:return: ago string
:rtype: str
"""
if dt == '' or dt is None or isinstance(dt, Undefined):
return ''
return naturaltime(dtnow() - dt)
示例8: time_offset
# 需要導入模塊: import humanize [as 別名]
# 或者: from humanize import naturaltime [as 別名]
def time_offset(self):
if self.ok:
now = datetime.datetime.today()
gp_time = self.datetime
if now > gp_time:
multiplier = 1
time_offset = now - gp_time
else:
multiplier = -1
time_offset = gp_time - now
time_offset = time_offset.total_seconds() * multiplier
self._status['time_offset'] = humanize.naturaltime(time_offset)
return time_offset
示例9: getNaturalUptime
# 需要導入模塊: import humanize [as 別名]
# 或者: from humanize import naturaltime [as 別名]
def getNaturalUptime(self):
"""
Returns the uptime in a human-readable format.
"""
return humanize.naturaltime(self.startupTime)
示例10: list_previous_commits
# 需要導入模塊: import humanize [as 別名]
# 或者: from humanize import naturaltime [as 別名]
def list_previous_commits(service, deploy_groups, any_given_deploy_groups, git_shas):
def format_timestamp(tstamp):
return naturaltime(datetime_from_utc_to_local(parse_timestamp(tstamp)))
print("Below is a list of recent commits:")
git_shas = sorted(git_shas.items(), key=lambda x: x[1], reverse=True)[:10]
rows = [("Timestamp -- UTC", "Human time", "deploy_group", "Git SHA")]
for sha, (timestamp, deploy_group) in git_shas:
rows.extend([(timestamp, format_timestamp(timestamp), deploy_group, sha)])
for line in format_table(rows):
print(line)
if len(git_shas) >= 2:
sha, (timestamp, deploy_group) = git_shas[1]
deploy_groups_arg_line = (
"-l %s " % ",".join(deploy_groups) if any_given_deploy_groups else ""
)
print(
"\nFor example, to use the second to last commit from {} used on {}, run:".format(
format_timestamp(timestamp), PaastaColors.bold(deploy_group)
)
)
print(
PaastaColors.bold(
f" paasta rollback -s {service} {deploy_groups_arg_line}-k {sha}"
)
)
示例11: format_marathon_task_table
# 需要導入模塊: import humanize [as 別名]
# 或者: from humanize import naturaltime [as 別名]
def format_marathon_task_table(tasks):
rows = [
("Mesos Task ID", "Host deployed to", "Deployed at what localtime", "Health")
]
for task in tasks:
local_deployed_datetime = datetime.fromtimestamp(task.deployed_timestamp)
if task.host is not None:
hostname = f"{task.host}:{task.port}"
else:
hostname = "Unknown"
if task.is_healthy is None:
health_check_status = PaastaColors.grey("N/A")
elif task.is_healthy:
health_check_status = PaastaColors.green("Healthy")
else:
health_check_status = PaastaColors.red("Unhealthy")
rows.append(
(
task.id,
hostname,
"{} ({})".format(
local_deployed_datetime.strftime("%Y-%m-%dT%H:%M"),
humanize.naturaltime(local_deployed_datetime),
),
health_check_status,
)
)
return format_table(rows)
示例12: build_smartstack_backends_table
# 需要導入模塊: import humanize [as 別名]
# 或者: from humanize import naturaltime [as 別名]
def build_smartstack_backends_table(backends: Iterable[Any]) -> List[str]:
rows: List[Tuple[str, ...]] = [("Name", "LastCheck", "LastChange", "Status")]
for backend in backends:
if backend.status == "UP":
status = PaastaColors.default(backend.status)
elif backend.status == "DOWN":
status = PaastaColors.red(backend.status)
elif backend.status == "MAINT":
status = PaastaColors.grey(backend.status)
else:
status = PaastaColors.yellow(backend.status)
if backend.check_duration is None:
check_duration = ""
else:
check_duration = str(backend.check_duration)
row: Tuple[str, ...] = (
f"{backend.hostname}:{backend.port}",
f"{backend.check_status}/{backend.check_code} in {check_duration}ms",
humanize.naturaltime(timedelta(seconds=backend.last_change)),
status,
)
if not backend.has_associated_task:
row = tuple(
PaastaColors.grey(remove_ansi_escape_sequences(col)) for col in row
)
rows.append(row)
return format_table(rows)
示例13: get_first_status_timestamp_string
# 需要導入模塊: import humanize [as 別名]
# 或者: from humanize import naturaltime [as 別名]
def get_first_status_timestamp_string(task: Task) -> str:
"""Gets the first status timestamp from a task id and returns a human
readable string with the local time and a humanized duration:
``2015-01-30T08:45 (an hour ago)``
"""
first_status_timestamp = get_first_status_timestamp(task)
if first_status_timestamp is None:
return "Unknown"
else:
first_status_datetime = datetime.datetime.fromtimestamp(first_status_timestamp)
return "{} ({})".format(
first_status_datetime.strftime("%Y-%m-%dT%H:%M"),
humanize.naturaltime(first_status_datetime),
)
示例14: subtract_time
# 需要導入模塊: import humanize [as 別名]
# 或者: from humanize import naturaltime [as 別名]
def subtract_time(start, end):
"""Get humanized time"""
subtracted = humanize.naturaltime(start - end)
return str(subtracted)
示例15: process_output_line
# 需要導入模塊: import humanize [as 別名]
# 或者: from humanize import naturaltime [as 別名]
def process_output_line(self, line: str):
if 'Waiting for wallet encryption password' in line:
self.update_status(NodeStatus.UNLOCK_READY)
elif 'Waiting for chain backend to finish sync' in line:
self.set_icon_color.emit('blue')
self.update_status(NodeStatus.SYNCING)
elif 'Unable to synchronize wallet to chain' in line:
self.terminate()
self.restart_process()
elif 'Unable to complete chain rescan' in line:
self.terminate()
self.restart_process()
elif 'Starting HTLC Switch' in line:
self.set_icon_color.emit('green')
self.update_status(NodeStatus.SYNCED)
self.notification.emit(
'LND is ready',
'Open Joule or Zap',
QSystemTrayIcon.Information
)
elif 'Caught up to height' in line:
new_height = int(line.split(' ')[-1])
timestamp = line.split('[INF]')[0].strip()
new_timestamp = datetime.strptime(
timestamp,
'%Y-%m-%d %H:%M:%S.%f'
)
if self.old_height is not None:
change = new_height - self.old_height
if change:
timestamp_change = new_timestamp - self.old_timestamp
total_left = 600000 - new_height
time_left = (total_left / change) * timestamp_change
humanized = humanize.naturaltime(-time_left)
self.sync_progress.emit(
f'ETA: {humanized}, caught up to height {new_height}'
)
self.old_height = new_height
self.old_timestamp = new_timestamp