Skip to content

Commit

Permalink
refactor: Changed name of Time module
Browse files Browse the repository at this point in the history
  • Loading branch information
rupozzi committed May 20, 2022
1 parent 02bad3f commit 49afdbe
Show file tree
Hide file tree
Showing 61 changed files with 190 additions and 185 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
import datetime
from 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.datetime.utcnow().year
copyright = "%s, DIRAC Project" % 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
6 changes: 3 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,7 @@
import datetime

from DIRAC import S_OK, S_ERROR
from DIRAC.Core.Utilities import Time
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 +124,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, Time._dateTimeType):
if not isinstance(self.startTime, TimeUtilities._dateTimeType):
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, Time._dateTimeType):
if not isinstance(self.endTime, TimeUtilities._dateTimeType):
return S_ERROR("End time is not a datetime object")
return self.checkRecord()

Expand Down
44 changes: 24 additions & 20 deletions src/DIRAC/AccountingSystem/DB/AccountingDB.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
""" Frontend to MySQL DB AccountingDB
"""
import datetime
from datetime import datetime
import time
import threading
import random

from DIRAC.Core.Base.DB import DB
from DIRAC import S_OK, S_ERROR, gConfig
from DIRAC.Core.Utilities import List, ThreadSafe, Time, DEncode
from DIRAC.Core.Utilities import List, ThreadSafe, DEncode, TimeUtilities
from DIRAC.Core.Utilities.Plotting.TypeLoader import TypeLoader
from DIRAC.Core.Utilities.ThreadPool import ThreadPool

Expand Down Expand Up @@ -49,9 +49,9 @@ 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.datetime.utcnow()
lcd = datetime.utcnow()
lcd.replace(hour=self.__compactTime.hour + 1, minute=0, second=0)
self.__lastCompactionEpoch = Time.toEpoch(lcd)
self.__lastCompactionEpoch = TimeUtilities.toEpoch(lcd)

self.__registerTypes()

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

def __periodicAutoCompactDB(self):
while self.autoCompact:
nct = datetime.datetime.utcnow()
nct = datetime.utcnow()
if nct.hour >= self.__compactTime.hour:
nct = nct + datetime.timedelta(days=1)
nct = nct.replace(
hour=self.__compactTime.hour, minute=self.__compactTime.minute, second=self.__compactTime.second
)
self.log.info("Next db compaction", "will be at %s" % nct)
sleepTime = Time.toEpoch(nct) - Time.toEpoch()
sleepTime = TimeUtilities.toEpoch(nct) - TimeUtilities.toEpoch()
time.sleep(sleepTime)
self.compactBuckets()

Expand Down Expand Up @@ -173,7 +173,7 @@ def loadPendingRecords(self):
gSynchro.unlock()
self.log.info("[PENDING] Loading pending records for insertion")
pending = 0
now = Time.toEpoch()
now = TimeUtilities.toEpoch()
recordsPerSlot = self.getCSOption("RecordsPerSlot", 100)
for typeName in self.dbCatalog:
self.log.info("[PENDING] Checking %s" % typeName)
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(Time.toEpoch(datetime.datetime.utcnow()))
nowEpoch = int(TimeUtilities.toEpoch(datetime.utcnow()))
bucketTimeLength = self.calculateBucketLengthForTime(typeName, nowEpoch, startTime)
currentBucketStart = startTime - startTime % bucketTimeLength
if startTime == endTime:
Expand Down Expand Up @@ -566,7 +566,7 @@ def insertRecordBundleThroughQueue(self, recordsToQueue):
if self.__readOnly:
return S_ERROR("ReadOnly mode enabled. No modification allowed")
recordsToProcess = []
now = Time.toEpoch()
now = TimeUtilities.toEpoch()
for record in recordsToQueue:
typeName, startTime, endTime, valuesList = record
result = self.__insertInQueueTable(typeName, startTime, endTime, valuesList)
Expand All @@ -585,7 +585,8 @@ def insertRecordThroughQueue(self, typeName, startTime, endTime, valuesList):
return S_ERROR("ReadOnly mode enabled. No modification allowed")
self.log.info(
"Adding record to queue",
"for type %s\n [%s -> %s]" % (typeName, Time.fromEpoch(startTime), Time.fromEpoch(endTime)),
"for type %s\n [%s -> %s]"
% (typeName, TimeUtilities.fromEpoch(startTime), TimeUtilities.fromEpoch(endTime)),
)
if typeName not in self.dbCatalog:
return S_ERROR("Type %s has not been defined in the db" % typeName)
Expand Down Expand Up @@ -618,7 +619,9 @@ def insertRecordDirectly(self, typeName, startTime, endTime, valuesList):
if self.__readOnly:
return S_ERROR("ReadOnly mode enabled. No modification allowed")
self.log.info(
"Adding record", "for type %s\n [%s -> %s]" % (typeName, Time.fromEpoch(startTime), Time.fromEpoch(endTime))
"Adding record",
"for type %s\n [%s -> %s]"
% (typeName, TimeUtilities.fromEpoch(startTime), TimeUtilities.fromEpoch(endTime)),
)
if typeName not in self.dbCatalog:
return S_ERROR("Type %s has not been defined in the db" % typeName)
Expand Down Expand Up @@ -667,7 +670,8 @@ def deleteRecord(self, typeName, startTime, endTime, valuesList):

self.log.info(
"Deleting record",
"for type %s\n [%s -> %s]" % (typeName, Time.fromEpoch(startTime), Time.fromEpoch(endTime)),
"for type %s\n [%s -> %s]"
% (typeName, TimeUtilities.fromEpoch(startTime), TimeUtilities.fromEpoch(endTime)),
)
sqlValues = []
sqlValues.extend(valuesList)
Expand Down Expand Up @@ -950,7 +954,7 @@ def retrieveBucketedData(
)
if not retVal["OK"]:
return retVal
nowEpoch = Time.toEpoch(datetime.datetime.utcnow())
nowEpoch = TimeUtilities.toEpoch(datetime.utcnow())
bucketTimeLength = self.calculateBucketLengthForTime(typeName, nowEpoch, startTime)
startTime = startTime - startTime % bucketTimeLength
result = self.__queryType(
Expand Down Expand Up @@ -1121,7 +1125,7 @@ def compactBuckets(self, typeFilter=False):
else:
self.__compactBucketsForType(typeName)
self.log.info("[COMPACT] Compaction finished")
self.__lastCompactionEpoch = int(Time.toEpoch())
self.__lastCompactionEpoch = int(TimeUtilities.toEpoch())
gSynchro.lock()
try:
if self.__doingCompaction:
Expand Down Expand Up @@ -1169,7 +1173,7 @@ def __compactBucketsForType(self, typeName):
"""
Compact all buckets for a given type
"""
nowEpoch = Time.toEpoch()
nowEpoch = TimeUtilities.toEpoch()
# retVal = self.__startTransaction(connObj)
# if not retVal[ 'OK' ]:
# return retVal
Expand All @@ -1181,7 +1185,7 @@ def __compactBucketsForType(self, typeName):
nextBucketLength = self.dbBucketsLength[typeName][bPos + 1][1]
self.log.info(
"[COMPACT] Compacting data newer that %s with bucket size %s"
% (Time.fromEpoch(timeLimit), bucketLength)
% (TimeUtilities.fromEpoch(timeLimit), bucketLength)
)
# Retrieve the data
retVal = self.__selectForCompactBuckets(typeName, timeLimit, bucketLength, nextBucketLength)
Expand Down Expand Up @@ -1218,15 +1222,15 @@ def __slowCompactBucketsForType(self, typeName):
"""
Compact all buckets for a given type
"""
nowEpoch = Time.toEpoch()
nowEpoch = TimeUtilities.toEpoch()
for bPos in range(len(self.dbBucketsLength[typeName]) - 1):
self.log.info("[COMPACT] Query %d of %d" % (bPos, len(self.dbBucketsLength[typeName]) - 1))
secondsLimit = self.dbBucketsLength[typeName][bPos][0]
bucketLength = self.dbBucketsLength[typeName][bPos][1]
timeLimit = (nowEpoch - nowEpoch % bucketLength) - secondsLimit
self.log.info(
"[COMPACT] Compacting data newer that %s with bucket size %s for %s"
% (Time.fromEpoch(timeLimit), bucketLength, typeName)
% (TimeUtilities.fromEpoch(timeLimit), bucketLength, typeName)
)
querySize = 10000
previousRecordsSelected = querySize
Expand All @@ -1235,7 +1239,7 @@ def __slowCompactBucketsForType(self, typeName):
# Retrieve the data
self.log.info(
"[COMPACT] Retrieving buckets to compact newer that %s with size %s"
% (Time.fromEpoch(timeLimit), bucketLength)
% (TimeUtilities.fromEpoch(timeLimit), bucketLength)
)
roundStartTime = time.time()
result = self.__selectIndividualForCompactBuckets(typeName, timeLimit, bucketLength, querySize)
Expand Down Expand Up @@ -1402,7 +1406,7 @@ def regenerateBuckets(self, typeName):
sqlQueries = []
dateInclusiveConditions = []
countedField = "`%s`.`%s`" % (rawTableName, self.dbCatalog[typeName]["keys"][0])
lastTime = Time.toEpoch()
lastTime = TimeUtilities.toEpoch()
# Iterate for all ranges
for iRange, iValue in enumerate(self.dbBucketsLength[typeName]):
bucketTimeSpan = iValue[0]
Expand Down
18 changes: 9 additions & 9 deletions src/DIRAC/AccountingSystem/Service/DataStoreHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from DIRAC.AccountingSystem.DB.MultiAccountingDB import MultiAccountingDB
from DIRAC.ConfigurationSystem.Client import PathFinder
from DIRAC.Core.DISET.RequestHandler import RequestHandler, getServiceOption
from DIRAC.Core.Utilities import Time
from DIRAC.Core.Utilities import TimeUtilities
from DIRAC.Core.Utilities.ThreadScheduler import gThreadScheduler
from DIRAC.Core.Base.Client import Client

Expand Down Expand Up @@ -133,8 +133,8 @@ def export_commit(self, typeName, startTime, endTime, valuesList):
Add a record for a type
"""
setup = self.serviceInfoDict["clientSetup"]
startTime = int(Time.toEpoch(startTime))
endTime = int(Time.toEpoch(endTime))
startTime = int(TimeUtilities.toEpoch(startTime))
endTime = int(TimeUtilities.toEpoch(endTime))
return self.__acDB.insertRecordThroughQueue( # pylint: disable=no-member
setup, typeName, startTime, endTime, valuesList
)
Expand All @@ -159,8 +159,8 @@ def export_commitRegisters(self, entriesList):
return S_ERROR("Unexpected type in report")
records = []
for entry in entriesList:
startTime = int(Time.toEpoch(entry[1]))
endTime = int(Time.toEpoch(entry[2]))
startTime = int(TimeUtilities.toEpoch(entry[1]))
endTime = int(TimeUtilities.toEpoch(entry[2]))
self.log.debug("inserting", entry)
records.append((setup, entry[0], startTime, endTime, entry[3]))
return self.__acDB.insertRecordBundleThroughQueue(records)
Expand All @@ -186,8 +186,8 @@ def export_remove(self, typeName, startTime, endTime, valuesList):
Remove a record for a type
"""
setup = self.serviceInfoDict["clientSetup"]
startTime = int(Time.toEpoch(startTime))
endTime = int(Time.toEpoch(endTime))
startTime = int(TimeUtilities.toEpoch(startTime))
endTime = int(TimeUtilities.toEpoch(endTime))
return self.__acDB.deleteRecord(setup, typeName, startTime, endTime, valuesList) # pylint: disable=no-member

types_removeRegisters = [list]
Expand All @@ -206,8 +206,8 @@ def export_removeRegisters(self, entriesList):
return S_ERROR("%s field in the records should be %s" % (i, expectedTypes[i]))
ok = 0
for entry in entriesList:
startTime = int(Time.toEpoch(entry[1]))
endTime = int(Time.toEpoch(entry[2]))
startTime = int(TimeUtilities.toEpoch(entry[1]))
endTime = int(TimeUtilities.toEpoch(entry[2]))
record = entry[3]
result = self.__acDB.deleteRecord(setup, entry[0], startTime, endTime, record) # pylint: disable=no-member
if not result["OK"]:
Expand Down
4 changes: 2 additions & 2 deletions src/DIRAC/AccountingSystem/Service/ReportGeneratorHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from DIRAC import S_OK, S_ERROR, rootPath, gConfig, gLogger
from DIRAC.Core.Utilities.File import mkDir
from DIRAC.Core.Utilities import Time
from DIRAC.Core.Utilities import TimeUtilities
from DIRAC.AccountingSystem.DB.MultiAccountingDB import MultiAccountingDB
from DIRAC.Core.Utilities.Plotting import gDataCache
from DIRAC.AccountingSystem.private.MainReporter import MainReporter
Expand Down Expand Up @@ -94,7 +94,7 @@ def __checkPlotRequest(self, reportRequest):
% (key, str(type(reportRequest[key])), str(self.__reportRequestDict[key]))
)
if key in ("startTime", "endTime"):
reportRequest[key] = int(Time.toEpoch(reportRequest[key]))
reportRequest[key] = int(TimeUtilities.toEpoch(reportRequest[key]))

return S_OK(reportRequest)

Expand Down
4 changes: 2 additions & 2 deletions src/DIRAC/AccountingSystem/private/DBUtils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""" Class that collects utilities used in Accounting and Monitoring systems
"""
from DIRAC.Core.Utilities import Time
from DIRAC.Core.Utilities import TimeUtilities


class DBUtils(object):
Expand Down Expand Up @@ -63,7 +63,7 @@ def _getBins(self, typeName, startTime, endTime):
return self._acDB.calculateBuckets(self._setup, typeName, startTime, endTime)

def _getBucketLengthForTime(self, typeName, momentEpoch):
nowEpoch = Time.toEpoch()
nowEpoch = TimeUtilities.toEpoch()
return self._acDB.calculateBucketLengthForTime(self._setup, typeName, nowEpoch, momentEpoch)

def _spanToGranularity(self, granularity, bucketsData):
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, Time
from DIRAC.Core.Utilities import List, TimeUtilities
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
6 changes: 3 additions & 3 deletions src/DIRAC/ConfigurationSystem/private/ConfigurationData.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from diraccfg import CFG
from DIRAC.Core.Utilities.File import mkDir
from DIRAC.Core.Utilities import List, Time
from DIRAC.Core.Utilities import List, TimeUtilities
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 +198,7 @@ def deleteOptionInCFG(self, path, cfg=False):
self.sync()

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

Expand Down Expand Up @@ -336,7 +336,7 @@ def dumpRemoteCFGToFile(self, fileName):
def __backupCurrentConfiguration(self, backupName):
configurationFilename = "%s.cfg" % self.getName()
configurationFile = os.path.join(DIRAC.rootPath, "etc", configurationFilename)
today = Time.date()
today = TimeUtilities.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, Time
from DIRAC.Core.Utilities import List, TimeUtilities
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 @@ -11,14 +11,14 @@
$ dirac-admin-sort-cs-sites -C CLOUDS DIRAC
sort site names by country postfix in '/Resources/Sites/CLOUDS' and '/Resources/Sites/DIRAC' subsection
"""
import datetime
from datetime import datetime

from DIRAC import gLogger, exit as DIRACExit
from DIRAC.Core.Base.Script import Script
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.Time import toString
from DIRAC.Core.Utilities.TimeUtilities import toString

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

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

Expand Down
Loading

0 comments on commit 49afdbe

Please sign in to comment.