Switch to Python's time module

This commit is contained in:
Ivan Kravets
2023-06-16 20:08:45 +03:00
parent 91487f179e
commit 378528abfc
5 changed files with 7 additions and 28 deletions

View File

@ -15,7 +15,7 @@
import os
import time
from platformio import __accounts_api__, app, util
from platformio import __accounts_api__, app
from platformio.exception import PlatformioException
from platformio.http import HTTPClient, HTTPClientError
@ -68,7 +68,7 @@ class AccountClient(HTTPClient): # pylint:disable=too-many-public-methods
return os.environ.get("PLATFORMIO_AUTH_TOKEN")
auth = app.get_state_item("account", {}).get("auth", {})
if auth.get("access_token") and auth.get("access_token_expire"):
if auth.get("access_token_expire") > util.get_timestamp():
if auth.get("access_token_expire") > time.time():
return auth.get("access_token")
if auth.get("refresh_token"):
try:

View File

@ -18,9 +18,10 @@ import json
import os
import platform
import socket
import time
import uuid
from platformio import __version__, exception, fs, proc, util
from platformio import __version__, exception, fs, proc
from platformio.compat import IS_WINDOWS, hashlib_encode_data
from platformio.package.lockfile import LockFile
from platformio.project.config import ProjectConfig
@ -253,7 +254,7 @@ def get_cid():
cid = str(cid)
if IS_WINDOWS or os.getuid() > 0: # pylint: disable=no-member
set_state_item("cid", cid)
set_state_item("created_at", int(util.get_timestamp()))
set_state_item("created_at", int(time.time()))
return cid

View File

@ -17,7 +17,6 @@ import json
import os
import re
import sys
import time
from urllib.parse import quote
import click
@ -64,15 +63,9 @@ class PlatformRunMixin:
if not os.path.isfile(variables["build_script"]):
raise BuildScriptNotFound(variables["build_script"])
started_at = time.time()
telemetry.log_platform_run(self, self.config, variables["pioenv"], targets)
result = self._run_scons(variables, targets, jobs)
telemetry.log_platform_run(
self,
self.config,
variables["pioenv"],
targets,
elapsed_time=time.time() - started_at,
)
assert "returncode" in result
return result

View File

@ -77,7 +77,6 @@ def system_info_cmd(json_output):
).get_installed()
),
}
click.echo(
json.dumps(data)
if json_output

View File

@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import base64
import datetime
import functools
import math
@ -168,10 +167,6 @@ def items_in_list(needle, haystack):
return set(needle) & set(haystack)
def get_timestamp(utc=True):
return datetime.datetime.now(datetime.timezone.utc if utc else None).timestamp()
def parse_datetime(datestr):
if "T" in datestr and "Z" in datestr:
return datetime.datetime.strptime(datestr, "%Y-%m-%dT%H:%M:%SZ")
@ -211,12 +206,3 @@ def humanize_duration_time(duration):
def strip_ansi_codes(text):
# pylint: disable=protected-access
return click._compat.strip_ansi(text)
def decrypt_message(key, message):
result = ""
message = bytearray(base64.b64decode(message))
for i, c in enumerate(message):
key_c = key[i % len(key)]
result += chr((256 + c - ord(key_c)) % 256)
return result