MCPcopy
hub / github.com/RUB-NDS/PRET / conv

Class conv

helper.py:332–380  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

330
331
332class conv():
333 # return current time
334 def now(self):
335 return int(time.time())
336
337 # return time elapsed since unix epoch
338 def elapsed(self, date, div=1, short=False):
339 date = str(datetime.timedelta(seconds=int(date)/div))
340 return date.split(",")[0] if short else date
341
342 # return date dependent on current year
343 def lsdate(self, date):
344 year1 = datetime.datetime.now().year
345 year2 = datetime.datetime.fromtimestamp(date).year
346 pdate = '%b %e ' if os.name == 'posix' else '%b %d '
347 format = pdate + "%H:%M" if year1 == year2 else pdate + " %Y"
348 return time.strftime(format, time.localtime(date))
349
350 # return date plus/minus given seconds
351 def timediff(self, seconds):
352 return self.lsdate(self.now() + self.int(seconds) / 1000)
353
354 # convert size to human readable value
355 def filesize(self, num):
356 num = self.int(num)
357 for unit in ['B', 'K', 'M']:
358 if abs(num) < 1024.0:
359 return (("%4.1f%s" if unit == 'M' else "%4.0f%s") % (num, unit))
360 num /= 1024.0
361
362 # remove carriage return from line breaks
363 def nstrip(self, data):
364 return re.sub(r'\r\n', '\n', data)
365
366 # convert string to hexadecimal
367 def hex(self, data, sep=''):
368 return sep.join("{:02x}".format(ord(c)) for c in data)
369
370 # convert to ascii character
371 def chr(self, num):
372 return chr(self.int(num))
373
374 # convert to integer or zero
375 def int(self, num):
376 try:
377 n = int(num)
378 except ValueError:
379 n = 0
380 return n
381
382# ----------------------------------------------------------------------
383

Callers 15

file_existsMethod · 0.90
do_destroyMethod · 0.90
do_nvramMethod · 0.90
do_floodMethod · 0.90
do_getMethod · 0.90
do_lsMethod · 0.90
putMethod · 0.90
echo2dataMethod · 0.90
file_existsMethod · 0.90
do_lsMethod · 0.90
do_uptimeMethod · 0.90
overlayMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected