Opened 5 years ago

Closed 5 years ago

#7158 closed enhancement (implemented)

String utilities for stem

Reported by: atagar Owned by: neena
Priority: Medium Milestone:
Component: Core Tor/Stem Version:
Severity: Keywords:
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

Hi Ravi, just pushed some new string utilities (mostly stolen from arm) to my 'str_tools' branch...

https://gitweb.torproject.org/user/atagar/stem.git/shortlog/refs/heads/str_tools

Child Tickets

Change History (4)

comment:1 Changed 5 years ago by atagar

Status: newneeds_review

comment:2 Changed 5 years ago by neena

Looks good.

+  try:
+    time_sum = int(float(seconds))
+    time_sum += int(minutes) * 60
+    time_sum += int(hours) * 3600
+    time_sum += int(days) * 86400
+    return time_sum

If you don't mind importing datetime, that could be replaced with...

return datetime.timedelta(days=int(days), hours=int(hours), minutes=int(minutes), seconds=int(float(seconds))).total_seconds()

That is all.

comment:3 Changed 5 years ago by gsathya

+SIZE_UNITS_BYTES = (
+  (1125899906842624.0, " PB", " Petabyte"),
+  (1099511627776.0, " TB", " Terabyte"),
+  (1073741824.0, " GB", " Gigabyte"),
+  (1048576.0, " MB", " Megabyte"),
+  (1024.0, " KB", " Kilobyte"),
+  (1.0, " B", " Byte"),
+)

On OS X 10.6+, 1 kb = 1000 bytes, not 1024 bytes. Not sure if it'll break anything. Just, FYI - https://support.apple.com/kb/TS2419

comment:4 Changed 5 years ago by atagar

Resolution: implemented
Status: needs_reviewclosed

If you don't mind importing datetime, that could be replaced with...

Oh, neat. I didn't know that you could do that. I don't mind importing datetime, but personally I find the present summation to be a little bit easier to read than constructing a throwaway datetime object. But that's certainly debatable.

On OS X 10.6+, 1 kb = 1000 bytes, not 1024 bytes. Not sure if it'll break anything. Just, FYI

Thanks for the heads up. This won't break anything - this is simply a function for getting human readable labels and, frankly speaking, OSX is wrong about this.

Note: See TracTickets for help on using tickets.