Use UTC where appropriate in python files

This commit is contained in:
NTD 2018-02-02 12:00:37 -05:00 • committed by Roy Tam
commit 30d5f081aa
16 changed files with 29 additions and 29 deletions

View file

@ -217,7 +217,7 @@ class Popen(subprocess.Popen):
# timeout is now in milliseconds # timeout is now in milliseconds
timeout = timeout * 1000 timeout = timeout * 1000
starttime = datetime.datetime.now() starttime = datetime.datetime.utcnow()
if mswindows: if mswindows:
if timeout is None: if timeout is None:
@ -234,7 +234,7 @@ class Popen(subprocess.Popen):
# Returns 1 if running, 0 if not, -1 if timed out # Returns 1 if running, 0 if not, -1 if timed out
def check(): def check():
now = datetime.datetime.now() now = datetime.datetime.utcnow()
diff = now - starttime diff = now - starttime
if (diff.seconds * 1000000 + diff.microseconds) < (timeout * 1000): # (1000*1000) if (diff.seconds * 1000000 + diff.microseconds) < (timeout * 1000): # (1000*1000)
if self._job: if self._job:
@ -302,7 +302,7 @@ class Popen(subprocess.Popen):
returncode = False returncode = False
now = datetime.datetime.now() now = datetime.datetime.utcnow()
diff = now - starttime diff = now - starttime
while (diff.seconds * 1000 * 1000 + diff.microseconds) < (timeout * 1000) and ( returncode is False ): while (diff.seconds * 1000 * 1000 + diff.microseconds) < (timeout * 1000) and ( returncode is False ):
if group is True: if group is True:
@ -311,7 +311,7 @@ class Popen(subprocess.Popen):
if subprocess.poll() is not None: if subprocess.poll() is not None:
returncode = self.returncode returncode = self.returncode
time.sleep(.5) time.sleep(.5)
now = datetime.datetime.now() now = datetime.datetime.utcnow()
diff = now - starttime diff = now - starttime
return self.returncode return self.returncode

View file

@ -241,8 +241,8 @@ class B2GRemoteAutomation(Automation):
self._devicemanager.killProcess('/system/b2g/b2g', sig=signal.SIGABRT) self._devicemanager.killProcess('/system/b2g/b2g', sig=signal.SIGABRT)
timeout = 10 # seconds timeout = 10 # seconds
starttime = datetime.datetime.now() starttime = datetime.datetime.utcnow()
while datetime.datetime.now() - starttime < datetime.timedelta(seconds=timeout): while datetime.datetime.utcnow() - starttime < datetime.timedelta(seconds=timeout):
if not self._devicemanager.processExist('/system/b2g/b2g'): if not self._devicemanager.processExist('/system/b2g/b2g'):
break break
time.sleep(1) time.sleep(1)

View file

@ -387,9 +387,9 @@ class RemoteAutomation(Automation):
# Get log updates on each interval, but if it is taking # Get log updates on each interval, but if it is taking
# too long, only do it every 60 seconds # too long, only do it every 60 seconds
if (not slowLog) or (timer % 60 == 0): if (not slowLog) or (timer % 60 == 0):
startRead = datetime.datetime.now() startRead = datetime.datetime.utcnow()
hasOutput = self.read_stdout() hasOutput = self.read_stdout()
if (datetime.datetime.now() - startRead) > datetime.timedelta(seconds=5): if (datetime.datetime.utcnow() - startRead) > datetime.timedelta(seconds=5):
slowLog = True slowLog = True
if hasOutput: if hasOutput:
noOutputTimer = 0 noOutputTimer = 0

View file

@ -129,7 +129,7 @@ def getReleaseTag(tag):
def generateRelbranchName(version, prefix='GECKO'): def generateRelbranchName(version, prefix='GECKO'):
return '%s%s_%s_RELBRANCH' % ( return '%s%s_%s_RELBRANCH' % (
prefix, version.replace('.', ''), prefix, version.replace('.', ''),
datetime.now().strftime('%Y%m%d%H')) datetime.utcnow().strftime('%Y%m%d%H'))
def getReleaseName(product, version, buildNumber): def getReleaseName(product, version, buildNumber):

View file

@ -17,7 +17,7 @@ def buildid_header(output):
print('Ignoring invalid MOZ_BUILD_DATE: %s' % buildid, file=sys.stderr) print('Ignoring invalid MOZ_BUILD_DATE: %s' % buildid, file=sys.stderr)
buildid = None buildid = None
if not buildid: if not buildid:
buildid = datetime.now().strftime('%Y%m%d%H%M%S') buildid = datetime.utcnow().strftime('%Y%m%d%H%M%S')
output.write("#define MOZ_BUILDID %s\n" % buildid) output.write("#define MOZ_BUILDID %s\n" % buildid)

View file

@ -12,7 +12,7 @@ class ProgressBar(object):
self.limit = limit self.limit = limit
self.label_width = label_width self.label_width = label_width
self.cur = 0 self.cur = 0
self.t0 = datetime.datetime.now() self.t0 = datetime.datetime.utcnow()
self.fullwidth = None self.fullwidth = None
self.barlen = 64 - self.label_width self.barlen = 64 - self.label_width
@ -23,7 +23,7 @@ class ProgressBar(object):
pct = int(100.0 * self.cur / self.limit) pct = int(100.0 * self.cur / self.limit)
barlen = int(1.0 * self.barlen * self.cur / self.limit) - 1 barlen = int(1.0 * self.barlen * self.cur / self.limit) - 1
bar = '='*barlen + '>' bar = '='*barlen + '>'
dt = datetime.datetime.now() - self.t0 dt = datetime.datetime.utcnow() - self.t0
dt = dt.seconds + dt.microseconds * 1e-6 dt = dt.seconds + dt.microseconds * 1e-6
line = self.fmt%(self.label[:self.label_width], pct, bar, dt) line = self.fmt%(self.label[:self.label_width], pct, bar, dt)
self.fullwidth = len(line) self.fullwidth = len(line)

View file

@ -28,7 +28,7 @@ class ProgressBar(object):
# field in the counters map. # field in the counters map.
self.limit = limit # int: The value of 'current' equal to 100%. self.limit = limit # int: The value of 'current' equal to 100%.
self.limit_digits = int(math.ceil(math.log10(self.limit))) # int: max digits in limit self.limit_digits = int(math.ceil(math.log10(self.limit))) # int: max digits in limit
self.t0 = datetime.now() # datetime: The start time. self.t0 = datetime.utcnow() # datetime: The start time.
# Compute the width of the counters and build the format string. # Compute the width of the counters and build the format string.
self.counters_width = 1 # [ self.counters_width = 1 # [
@ -68,7 +68,7 @@ class ProgressBar(object):
sys.stdout.write(bar + '|') sys.stdout.write(bar + '|')
# Update the bar. # Update the bar.
dt = datetime.now() - self.t0 dt = datetime.utcnow() - self.t0
dt = dt.seconds + dt.microseconds * 1e-6 dt = dt.seconds + dt.microseconds * 1e-6
sys.stdout.write('{:6.1f}s'.format(dt)) sys.stdout.write('{:6.1f}s'.format(dt))
Terminal.clear_right() Terminal.clear_right()

View file

@ -14,7 +14,7 @@ class Task(object):
self.pid = pid self.pid = pid
self.stdout = stdout self.stdout = stdout
self.stderr = stderr self.stderr = stderr
self.start = datetime.now() self.start = datetime.utcnow()
self.out = [] self.out = []
self.err = [] self.err = []
@ -59,7 +59,7 @@ def get_max_wait(tasks, timeout):
# If a timeout is supplied, we need to wake up for the first task to # If a timeout is supplied, we need to wake up for the first task to
# timeout if that is sooner. # timeout if that is sooner.
if timeout: if timeout:
now = datetime.now() now = datetime.utcnow()
timeout_delta = timedelta(seconds=timeout) timeout_delta = timedelta(seconds=timeout)
for task in tasks: for task in tasks:
remaining = task.start + timeout_delta - now remaining = task.start + timeout_delta - now
@ -136,7 +136,7 @@ def timed_out(task, timeout):
timed_out always returns False). timed_out always returns False).
""" """
if timeout: if timeout:
now = datetime.now() now = datetime.utcnow()
return (now - task.start) > timedelta(seconds=timeout) return (now - task.start) > timedelta(seconds=timeout)
return False return False
@ -175,7 +175,7 @@ def reap_zombies(tasks, timeout):
''.join(ended.out), ''.join(ended.out),
''.join(ended.err), ''.join(ended.err),
returncode, returncode,
(datetime.now() - ended.start).total_seconds(), (datetime.utcnow() - ended.start).total_seconds(),
timed_out(ended, timeout))) timed_out(ended, timeout)))
return tasks, finished return tasks, finished

View file

@ -36,7 +36,7 @@ def _do_work(qTasks, qResults, qWatch, prefix, run_skipped, timeout, show_cmd):
cmd = test.get_command(prefix) cmd = test.get_command(prefix)
if show_cmd: if show_cmd:
print(escape_cmdline(cmd)) print(escape_cmdline(cmd))
tStart = datetime.now() tStart = datetime.utcnow()
proc = subprocess.Popen(cmd, proc = subprocess.Popen(cmd,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE) stderr=subprocess.PIPE)
@ -49,7 +49,7 @@ def _do_work(qTasks, qResults, qWatch, prefix, run_skipped, timeout, show_cmd):
qWatch.put(TaskFinishedMarker) qWatch.put(TaskFinishedMarker)
# Create a result record and forward to result processing. # Create a result record and forward to result processing.
dt = datetime.now() - tStart dt = datetime.utcnow() - tStart
result = TestOutput(test, cmd, out, err, proc.returncode, dt.total_seconds(), result = TestOutput(test, cmd, out, err, proc.returncode, dt.total_seconds(),
dt > timedelta(seconds=timeout)) dt > timedelta(seconds=timeout))
qResults.put(result) qResults.put(result)

View file

@ -182,7 +182,7 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
day=int(match.group(3)), hour=int(match.group(4)), day=int(match.group(3)), hour=int(match.group(4)),
minute=int(match.group(5)), second=int(match.group(6))) minute=int(match.group(5)), second=int(match.group(6)))
time_delta = abs(datetime.datetime.now() - date_time_from_xml) time_delta = abs(datetime.datetime.utcnow() - date_time_from_xml)
# timestamp value should be near the current local time # timestamp value should be near the current local time
self.assertTrue(time_delta < datetime.timedelta(seconds=600), self.assertTrue(time_delta < datetime.timedelta(seconds=600),
'time_delta is %s' % time_delta) 'time_delta is %s' % time_delta)

View file

@ -41,21 +41,21 @@ class AnyTest(unittest2.TestCase):
def test_any_and_datetime(self): def test_any_and_datetime(self):
mock = Mock() mock = Mock()
mock(datetime.now(), foo=datetime.now()) mock(datetime.utcnow(), foo=datetime.utcnow())
mock.assert_called_with(ANY, foo=ANY) mock.assert_called_with(ANY, foo=ANY)
def test_any_mock_calls_comparison_order(self): def test_any_mock_calls_comparison_order(self):
mock = Mock() mock = Mock()
d = datetime.now() d = datetime.utcnow()
class Foo(object): class Foo(object):
def __eq__(self, other): def __eq__(self, other):
return False return False
def __ne__(self, other): def __ne__(self, other):
return True return True
for d in datetime.now(), Foo(): for d in datetime.utcnow(), Foo():
mock.reset_mock() mock.reset_mock()
mock(d, foo=d, bar=d) mock(d, foo=d, bar=d)

View file

@ -79,7 +79,7 @@ def android_version_code_v1(buildid, cpu_arch=None, min_sdk=0, max_sdk=0):
''' '''
def hours_since_cutoff(buildid): def hours_since_cutoff(buildid):
# The ID is formatted like YYYYMMDDHHMMSS (using # The ID is formatted like YYYYMMDDHHMMSS (using
# datetime.now().strftime('%Y%m%d%H%M%S'); see build/variables.py). # datetime.utcnow().strftime('%Y%m%d%H%M%S'); see build/variables.py).
# The inverse function is time.strptime. # The inverse function is time.strptime.
# N.B.: the time module expresses time as decimal seconds since the # N.B.: the time module expresses time as decimal seconds since the
# epoch. # epoch.

View file

@ -18,7 +18,7 @@ import os
PROJECT_NAME = "psutil" PROJECT_NAME = "psutil"
AUTHOR = "Giampaolo Rodola'" AUTHOR = "Giampaolo Rodola'"
THIS_YEAR = str(datetime.datetime.now().year) THIS_YEAR = str(datetime.datetime.utcnow().year)
HERE = os.path.abspath(os.path.dirname(__file__)) HERE = os.path.abspath(os.path.dirname(__file__))

View file

@ -165,7 +165,7 @@ def print_header(procs_status, num_procs):
st.sort(key=lambda x: x[:3] in ('run', 'sle'), reverse=1) st.sort(key=lambda x: x[:3] in ('run', 'sle'), reverse=1)
print_line(" Processes: %s (%s)" % (num_procs, ' '.join(st))) print_line(" Processes: %s (%s)" % (num_procs, ' '.join(st)))
# load average, uptime # load average, uptime
uptime = datetime.now() - datetime.fromtimestamp(psutil.boot_time()) uptime = datetime.utcnow() - datetime.fromtimestamp(psutil.boot_time())
av1, av2, av3 = os.getloadavg() av1, av2, av3 = os.getloadavg()
line = " Load average: %.2f %.2f %.2f Uptime: %s" \ line = " Load average: %.2f %.2f %.2f Uptime: %s" \
% (av1, av2, av3, str(uptime).split('.')[0]) % (av1, av2, av3, str(uptime).split('.')[0])

View file

@ -192,7 +192,7 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
day=int(match.group(3)), hour=int(match.group(4)), day=int(match.group(3)), hour=int(match.group(4)),
minute=int(match.group(5)), second=int(match.group(6))) minute=int(match.group(5)), second=int(match.group(6)))
time_delta = abs(datetime.datetime.now() - date_time_from_xml) time_delta = abs(datetime.datetime.utcnow() - date_time_from_xml)
# timestamp value should be near the current local time # timestamp value should be near the current local time
self.assertTrue(time_delta < datetime.timedelta(seconds=600), self.assertTrue(time_delta < datetime.timedelta(seconds=600),
'time_delta is %s' % time_delta) 'time_delta is %s' % time_delta)

View file

@ -42,7 +42,7 @@ templates_path = ['_templates']
source_suffix = '.rst' source_suffix = '.rst'
master_doc = 'index' master_doc = 'index'
project = u'Mozilla Source Tree Docs' project = u'Mozilla Source Tree Docs'
year = datetime.now().year year = datetime.utcnow().year
# Grab the version from the source tree's milestone. # Grab the version from the source tree's milestone.
# FUTURE Use Python API from bug 941299. # FUTURE Use Python API from bug 941299.