Skip to content

Commit

Permalink
fix: Removing unused TimeUtils import
Browse files Browse the repository at this point in the history
  • Loading branch information
rupozzi committed May 20, 2022
1 parent 49afdbe commit 519a7a6
Show file tree
Hide file tree
Showing 29 changed files with 68 additions and 73 deletions.
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# pylint: disable=invalid-name
import logging
from datetime import datetime
import datetime
import os
import sys

Expand Down Expand Up @@ -139,7 +139,7 @@ def setup(app):

# General information about the project.
project = "DIRAC"
copyright = "%s, DIRAC Project" % datetime.utcnow().year
copyright = "%s, DIRAC Project" % datetime.datetime.utcnow().year

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down
5 changes: 2 additions & 3 deletions src/DIRAC/AccountingSystem/Client/Types/BaseAccountingType.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import datetime

from DIRAC import S_OK, S_ERROR
from DIRAC.Core.Utilities import TimeUtilities
from DIRAC.Core.Base.Client import Client
from DIRAC.AccountingSystem.Client.DataStoreClient import gDataStoreClient

Expand Down Expand Up @@ -124,11 +123,11 @@ def checkValues(self):
return S_ERROR("Invalid values: %s" % ", ".join(errorList))
if not self.startTime:
return S_ERROR("Start time has not been defined")
if not isinstance(self.startTime, TimeUtilities._dateTimeType):
if not isinstance(self.startTime, datetime.datetime):
return S_ERROR("Start time is not a datetime object")
if not self.endTime:
return S_ERROR("End time has not been defined")
if not isinstance(self.endTime, TimeUtilities._dateTimeType):
if not isinstance(self.endTime, datetime.datetime):
return S_ERROR("End time is not a datetime object")
return self.checkRecord()

Expand Down
10 changes: 5 additions & 5 deletions src/DIRAC/AccountingSystem/DB/AccountingDB.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""" Frontend to MySQL DB AccountingDB
"""
from datetime import datetime
import datetime
import time
import threading
import random
Expand Down Expand Up @@ -49,7 +49,7 @@ def __init__(self, name="Accounting/AccountingDB", readOnly=False, parentLogger=
self.__loadCatalogFromDB()

self.__compactTime = datetime.time(hour=2, minute=random.randint(0, 59), second=random.randint(0, 59))
lcd = datetime.utcnow()
lcd = datetime.datetime.utcnow()
lcd.replace(hour=self.__compactTime.hour + 1, minute=0, second=0)
self.__lastCompactionEpoch = TimeUtilities.toEpoch(lcd)

Expand All @@ -69,7 +69,7 @@ def autoCompactDB(self):

def __periodicAutoCompactDB(self):
while self.autoCompact:
nct = datetime.utcnow()
nct = datetime.datetime.utcnow()
if nct.hour >= self.__compactTime.hour:
nct = nct + datetime.timedelta(days=1)
nct = nct.replace(
Expand Down Expand Up @@ -534,7 +534,7 @@ def calculateBuckets(self, typeName, startTime, endTime, nowEpoch=False):
the proportional part for each bucket
"""
if not nowEpoch:
nowEpoch = int(TimeUtilities.toEpoch(datetime.utcnow()))
nowEpoch = int(TimeUtilities.toEpoch())
bucketTimeLength = self.calculateBucketLengthForTime(typeName, nowEpoch, startTime)
currentBucketStart = startTime - startTime % bucketTimeLength
if startTime == endTime:
Expand Down Expand Up @@ -954,7 +954,7 @@ def retrieveBucketedData(
)
if not retVal["OK"]:
return retVal
nowEpoch = TimeUtilities.toEpoch(datetime.utcnow())
nowEpoch = TimeUtilities.toEpoch()
bucketTimeLength = self.calculateBucketLengthForTime(typeName, nowEpoch, startTime)
startTime = startTime - startTime % bucketTimeLength
result = self.__queryType(
Expand Down
2 changes: 1 addition & 1 deletion src/DIRAC/ConfigurationSystem/Client/CSAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from DIRAC import gLogger, gConfig, S_OK, S_ERROR
from DIRAC.ConfigurationSystem.Client.ConfigurationClient import ConfigurationClient
from DIRAC.Core.Utilities import List, TimeUtilities
from DIRAC.Core.Utilities import List
from DIRAC.Core.Security.X509Chain import X509Chain # pylint: disable=import-error
from DIRAC.Core.Security import Locations
from DIRAC.ConfigurationSystem.private.Modificator import Modificator
Expand Down
7 changes: 4 additions & 3 deletions src/DIRAC/ConfigurationSystem/private/ConfigurationData.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import zipfile
import _thread
import time
import datetime
import DIRAC

from diraccfg import CFG
from DIRAC.Core.Utilities.File import mkDir
from DIRAC.Core.Utilities import List, TimeUtilities
from DIRAC.Core.Utilities import List
from DIRAC.Core.Utilities.ReturnValues import S_OK, S_ERROR
from DIRAC.Core.Utilities.LockRing import LockRing
from DIRAC.FrameworkSystem.Client.Logger import gLogger
Expand Down Expand Up @@ -198,7 +199,7 @@ def deleteOptionInCFG(self, path, cfg=False):
self.sync()

def generateNewVersion(self):
self.setVersion(TimeUtilities.toString())
self.setVersion(str(datetime.datetime.utcnow()))
self.sync()
gLogger.info("Generated new version %s" % self.getVersion())

Expand Down Expand Up @@ -336,7 +337,7 @@ def dumpRemoteCFGToFile(self, fileName):
def __backupCurrentConfiguration(self, backupName):
configurationFilename = "%s.cfg" % self.getName()
configurationFile = os.path.join(DIRAC.rootPath, "etc", configurationFilename)
today = TimeUtilities.date()
today = datetime.datetime.utcnow().date()
backupPath = os.path.join(self.getBackupDir(), str(today.year), "%02d" % today.month)
mkDir(backupPath)
backupFile = os.path.join(backupPath, configurationFilename.replace(".cfg", ".%s.zip" % backupName))
Expand Down
2 changes: 1 addition & 1 deletion src/DIRAC/ConfigurationSystem/private/Modificator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import datetime

from diraccfg import CFG
from DIRAC.Core.Utilities import List, TimeUtilities
from DIRAC.Core.Utilities import List
from DIRAC.ConfigurationSystem.Client.ConfigurationData import gConfigurationData
from DIRAC.Core.Security.ProxyInfo import getProxyInfo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from DIRAC.Core.Security.ProxyInfo import getProxyInfo
from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getPropertiesForGroup
from DIRAC.ConfigurationSystem.Client.CSAPI import CSAPI
from DIRAC.Core.Utilities.TimeUtilities import toString

global SORTBYNAME, REVERSE
SORTBYNAME = True
Expand Down Expand Up @@ -113,7 +112,7 @@ def main():
gLogger.notice("Nothing to do, site names are already sorted")
DIRACExit(0)

timestamp = toString(datetime.utcnow())
timestamp = str(datetime.utcnow())
stamp = "Site names are sorted by %s script at %s" % (Script.scriptName, timestamp)
cs.setOptionComment("/Resources/Sites", stamp)

Expand Down
3 changes: 2 additions & 1 deletion src/DIRAC/Core/Base/AgentModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import signal
import importlib
import inspect
import datetime

import DIRAC
from DIRAC import S_OK, S_ERROR, gConfig, gLogger, rootPath
Expand Down Expand Up @@ -227,7 +228,7 @@ def am_checkStopAgentFile(self):
def am_createStopAgentFile(self):
try:
with open(self.am_getStopAgentFile(), "w") as fd:
fd.write("Dirac site agent Stopped at %s" % TimeUtilities.toString())
fd.write("Dirac site agent Stopped at %s" % str(datetime.datetime.utcnow()))
except Exception:
pass

Expand Down
7 changes: 5 additions & 2 deletions src/DIRAC/Core/DISET/MessageClient.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import random
import datetime
from hashlib import md5

from DIRAC.Core.Utilities.ThreadSafe import Synchronizer
from DIRAC.Core.DISET.private.BaseClient import BaseClient
from DIRAC.Core.DISET.private.MessageBroker import getGlobalMessageBroker
from DIRAC.Core.Utilities.ReturnValues import S_OK, S_ERROR, isReturnStructure
from DIRAC.Core.Utilities import Network, TimeUtilities
from DIRAC.Core.Utilities import Network
from DIRAC.FrameworkSystem.Client.Logger import gLogger

gMsgSync = Synchronizer()
Expand All @@ -25,7 +26,9 @@ def _initialize(self):
self.__specialCallbacks = {"drop": [], "msg": []}

def __generateUniqueClientName(self):
hashStr = ":".join((TimeUtilities.toString(), str(random.random()), Network.getFQDN(), gLogger.getName()))
hashStr = ":".join(
(str(datetime.datetime.utcnow()), str(random.random()), Network.getFQDN(), gLogger.getName())
)
hexHash = md5(hashStr.encode()).hexdigest()
return hexHash

Expand Down
1 change: 0 additions & 1 deletion src/DIRAC/Core/DISET/RequestHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from DIRAC.Core.DISET.private.FileHelper import FileHelper
from DIRAC.Core.Utilities.ReturnValues import S_OK, S_ERROR, isReturnStructure
from DIRAC.Core.Utilities import TimeUtilities
from DIRAC.ConfigurationSystem.Client.Config import gConfig
from DIRAC.FrameworkSystem.Client.Logger import gLogger
from DIRAC.Core.Security.Properties import CS_ADMINISTRATOR
Expand Down
1 change: 0 additions & 1 deletion src/DIRAC/Core/DISET/ServiceReactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from DIRAC.Core.DISET.private.Service import Service
from DIRAC.Core.DISET.private.GatewayService import GatewayService
from DIRAC.Core.DISET.RequestHandler import RequestHandler
from DIRAC.Core.Utilities import TimeUtilities
from DIRAC.Core.Base.private.ModuleLoader import ModuleLoader
from DIRAC.Core.DISET.private.Protocols import gProtocolDict
from DIRAC.ConfigurationSystem.Client.Helpers import Registry
Expand Down
6 changes: 3 additions & 3 deletions src/DIRAC/Core/Utilities/NTP.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from socket import socket, AF_INET, SOCK_DGRAM
import struct
import time as time
from datetime import datetime
import datetime
from DIRAC import S_OK, S_ERROR

TIME1970 = 2208988800
Expand All @@ -28,13 +28,13 @@ def getNTPUTCTime(serverList=None, retries=2):
if data:
myTime = struct.unpack("!12I", data)[10]
myTime -= TIME1970
return S_OK(datetime(*time.gmtime(myTime)[:6]))
return S_OK(datetime.datetime(*time.gmtime(myTime)[:6]))
return S_ERROR("Could not get NTP time")


def getClockDeviation(serverList=None):
result = getNTPUTCTime(serverList)
if not result["OK"]:
return result
td = datetime.utcnow() - result["Value"]
td = datetime.datetime.utcnow() - result["Value"]
return S_OK(abs(td.days * 86400 + td.seconds))
12 changes: 1 addition & 11 deletions src/DIRAC/Core/Utilities/TimeUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,6 @@ def timed(*args, **kw):
return timed


def date(myDateTime=None):
"""
Return current UTC date, as datetime.date object
if a _dateTimeType is pass as argument its associated date is returned
"""
if isinstance(myDateTime, _dateTimeType):
return myDateTime.date()
return datetime.datetime.utcnow().date()


def time(myDateTime=None):
"""
Return current UTC time, as datetime.time object
Expand Down Expand Up @@ -266,7 +256,7 @@ def measureQueryTime(*args, **kwargs):


_dateTimeType = type(datetime.datetime.utcnow())
_dateType = type(date())
_dateType = type(datetime.datetime.utcnow().date())
_timeType = type(time())

_allTimeTypes = (_dateTimeType, _timeType)
Expand Down
1 change: 0 additions & 1 deletion src/DIRAC/DataManagementSystem/Client/DataManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import DIRAC
from DIRAC import S_OK, S_ERROR, gLogger, gConfig
from DIRAC.Core.Utilities import DErrno
from DIRAC.Core.Utilities import TimeUtilities
from DIRAC.Core.Utilities.Adler import fileAdler, compareAdler
from DIRAC.Core.Utilities.File import makeGuid, getSize
from DIRAC.Core.Utilities.List import randomize, breakListIntoChunks
Expand Down
1 change: 0 additions & 1 deletion src/DIRAC/FrameworkSystem/Client/SecurityLogClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from DIRAC import gLogger, gConfig
from DIRAC.Core.Base.Client import Client
from DIRAC.Core.Utilities import TimeUtilities
from DIRAC.Core.Utilities.ThreadScheduler import gThreadScheduler


Expand Down
2 changes: 1 addition & 1 deletion src/DIRAC/FrameworkSystem/DB/ComponentMonitoringDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def __registerIfNotThere(self, compDict):
if "startTime" in compDict:
sqlInsertFields.append("StartTime")
val = compDict["startTime"]
if isinstance(val, TimeUtilities._allDateTypes):
if isinstance(val, (datetime.datetime, datetime.date)):
val = self.__datetime2str(val)
sqlInsertValues.append("'%s'" % val)
for field in ("cycles", "queries"):
Expand Down
4 changes: 2 additions & 2 deletions src/DIRAC/Interfaces/API/Dirac.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import tarfile
import tempfile
import time
import datetime
from urllib.parse import unquote


import DIRAC
from DIRAC import gConfig, gLogger, S_OK, S_ERROR
from DIRAC.Core.Base.API import API
from DIRAC.Core.Base.Client import Client
from DIRAC.Core.Utilities import TimeUtilities
from DIRAC.Core.Utilities.File import mkDir
from DIRAC.Core.Utilities.List import breakListIntoChunks
from DIRAC.Core.Utilities.SiteSEMapping import getSEsForSite
Expand Down Expand Up @@ -1974,7 +1974,7 @@ def selectJobs(
except Exception as x:
return self._errorReport(str(x), "Expected yyyy-mm-dd string for date")
else:
date = "%s" % TimeUtilities.date()
date = str(datetime.datetime.utcnow().date())
self.log.verbose("Setting date to %s" % (date))

self.log.verbose("Will select jobs with last update %s and following conditions" % date)
Expand Down
5 changes: 3 additions & 2 deletions src/DIRAC/Interfaces/scripts/dirac_wms_job_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
$ dirac-wms-job-delete 12
Deleted job 12
"""
import datetime
import os.path

from DIRAC.Core.Base.Script import Script
Expand All @@ -25,7 +26,7 @@ def main():

import DIRAC
from DIRAC.Interfaces.API.Dirac import Dirac, parseArguments
from DIRAC.Core.Utilities.TimeUtilities import toString, date, day
from DIRAC.Core.Utilities.TimeUtilities import toString, day

dirac = Dirac()

Expand All @@ -38,7 +39,7 @@ def main():
jFile.close()
elif sw.lower() in ("g", "jobgroup"):
group = value
jobDate = toString(date() - 30 * day)
jobDate = toString(datetime.datetime.utcnow().date() - 30 * day)
result = dirac.selectJobs(jobGroup=value, date=jobDate)
if not result["OK"]:
if "No jobs selected" not in result["Message"]:
Expand Down
5 changes: 3 additions & 2 deletions src/DIRAC/Interfaces/scripts/dirac_wms_job_get_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"""
import os
import shutil
import datetime

import DIRAC
from DIRAC.Core.Base.Script import Script
Expand All @@ -27,7 +28,7 @@ def main():
sws, args = Script.parseCommandLine(ignoreErrors=True)

from DIRAC.Interfaces.API.Dirac import Dirac, parseArguments
from DIRAC.Core.Utilities.TimeUtilities import toString, date, day
from DIRAC.Core.Utilities.TimeUtilities import toString, day
from DIRAC.Core.Utilities.File import mkDir

dirac = Dirac()
Expand All @@ -47,7 +48,7 @@ def main():
jFile.close()
elif sw.lower() in ("g", "jobgroup"):
group = value
jobDate = toString(date() - 30 * day)
jobDate = toString(datetime.datetime.utcnow().date() - 30 * day)

# Choose jobs in final state, no more than 30 days old
result = dirac.selectJobs(jobGroup=value, date=jobDate, status="Done")
Expand Down
5 changes: 3 additions & 2 deletions src/DIRAC/Interfaces/scripts/dirac_wms_job_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
JobID=2 Status=Done; MinorStatus=Execution Complete; Site=EELA.UTFSM.cl;
"""
import os
import datetime
from DIRAC.Core.Base.Script import Script


Expand All @@ -23,7 +24,7 @@ def main():
sws, args = Script.parseCommandLine(ignoreErrors=True)

from DIRAC import exit as DIRACExit
from DIRAC.Core.Utilities.TimeUtilities import toString, date, day
from DIRAC.Core.Utilities.TimeUtilities import toString, day
from DIRAC.Interfaces.API.Dirac import Dirac, parseArguments

dirac = Dirac()
Expand All @@ -37,7 +38,7 @@ def main():
jobs += jFile.read().split()
jFile.close()
elif key.lower() in ("g", "jobgroup"):
jobDate = toString(date() - 30 * day)
jobDate = toString(datetime.datetime.utcnow().date() - 30 * day)
# Choose jobs no more than 30 days old
result = dirac.selectJobs(jobGroup=value, date=jobDate)
if not result["OK"]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from DIRAC.ResourceStatusSystem.Client import ResourceStatusClient
from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
from DIRAC.Core.Security.ProxyInfo import getProxyInfo
from DIRAC.Core.Utilities import TimeUtilities
from DIRAC.Core.Utilities.PrettyPrint import printTable
from DIRAC.Core.Utilities import TimeUtilities

subLogger = None

Expand Down
Loading

0 comments on commit 519a7a6

Please sign in to comment.