Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions ptrace/linux_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"""
from os import readlink, listdir
from resource import getpagesize
from ptrace.tools import timestampUNIX
from datetime import timedelta
from datetime import timedelta, datetime

PAGE_SIZE = getpagesize()

Expand Down Expand Up @@ -233,7 +232,7 @@ def getSystemBoot():
if not line.startswith("btime "):
continue
seconds = int(line[6:])
btime = timestampUNIX(seconds, True)
btime = datetime.fromtimestamp(seconds)
getSystemBoot.value = btime
break
stat_file.close()
Expand Down
26 changes: 0 additions & 26 deletions ptrace/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,6 @@ def formatBits(value, bitmasks, empty_text=None, format_value=str):
return str(value)


LOCAL_TIMEZONE_OFFSET = datetime.fromtimestamp(
0) - datetime.utcfromtimestamp(0)

# Start of UNIX timestamp (Epoch): 1st January 1970 at 00:00
UNIX_TIMESTAMP_T0 = datetime(1970, 1, 1)


def timestampUNIX(value, is_local):
"""
Convert an UNIX (32-bit) timestamp to datetime object. Timestamp value
is the number of seconds since the 1st January 1970 at 00:00. Maximum
value is 2147483647: 19 january 2038 at 03:14:07.

May raise ValueError for invalid value: value have to be in 0..2147483647.

>>> timestampUNIX(0, False)
datetime.datetime(1970, 1, 1, 0, 0)
>>> timestampUNIX(1154175644.37, False)
datetime.datetime(2006, 7, 29, 12, 20, 44, 370000)
"""
timestamp = UNIX_TIMESTAMP_T0 + timedelta(seconds=value)
if is_local:
timestamp += LOCAL_TIMEZONE_OFFSET
return timestamp


def locateProgram(program):
"""
Locate a program using the PATH environment variable. Return the
Expand Down