Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP8 fixes for PR #2373 (repo_error_fix) by autopep8 #2374

Merged
merged 3 commits into from
Jul 8, 2024
Merged
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
56 changes: 32 additions & 24 deletions ganga/GangaCore/Core/GangaRepository/SubJobXMLList.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from GangaCore.GPIDev.Schema.Schema import Schema, SimpleItem, Version
from GangaCore.GPIDev.Schema.Schema import Schema, Version
from GangaCore.GPIDev.Base.Objects import GangaObject
from GangaCore.Utility.logging import getLogger
from GangaCore.Core.GangaRepository.GangaRepository import RepositoryError
from GangaCore.Core.exceptions import GangaException
from GangaCore.GPIDev.Base.Proxy import stripProxy
from GangaCore.Core.GangaRepository.VStreamer import XMLFileError
import errno
import copy
import threading
import shutil
from os import listdir, path, stat

logger = getLogger()
Expand Down Expand Up @@ -152,7 +150,7 @@ def load_subJobIndex(self):
try:
index_file_obj = open(index_file, "rb")
self._subjobIndexData = from_file(index_file_obj)[0]
except IOError as err:
except IOError:
self._subjobIndexData = None
self._setDirty()

Expand Down Expand Up @@ -181,7 +179,7 @@ def load_subJobIndex(self):
new_data = self._registry.getIndexCache(self.__getitem__(subjob_id))
self._subjobIndexData[subjob_id] = new_data
continue
#self._subjobIndexData = {}
# self._subjobIndexData = {}
except Exception as err:
logger.debug("Subjob Index file open, error: %s" % err)
self._subjobIndexData = {}
Expand Down Expand Up @@ -249,7 +247,8 @@ def __iter__(self):
return SJXLIterator(self)

def __get_dataFile(self, index, force_backup=False):
"""Get the filename for this file (with out without backup '~'. Store already determine combinations in _cached_filenames for speed
"""Get the filename for this file (with out without backup '~'.
Store already determine combinations in _cached_filenames for speed
Args:
index (int): This is the index of the subjob we're interested in
force_backup (bool): Should we force the loading from the backup XML
Expand All @@ -270,7 +269,8 @@ def __get_dataFile(self, index, force_backup=False):
return subjob_data

def __len__(self):
""" return length or lookup the last modified time compare against self._stored_len[0] and if nothings changed return self._stored_len[1]"""
""" return length or lookup the last modified time compare against self._stored_len[0]
and if nothings changed return self._stored_len[1]"""
try:
this_time = stat(self._jobDirectory).st_ctime
except OSError:
Expand Down Expand Up @@ -315,7 +315,7 @@ def getSafeJob(self):
logger.debug("Error: %s" % err)
try:
job_obj = self._getParent()
except Exception as err:
except Exception:
job_obj = None
return job_obj

Expand All @@ -325,10 +325,10 @@ def getMasterID(self):
if job_obj is not None:
try:
fqid = job_obj.getFQID('.')
except Exception as err:
except Exception:
try:
fqid = job_obj.id
except:
except BaseException:
fqid = "unknown"
else:
fqid = "unknown"
Expand All @@ -340,11 +340,11 @@ def _loadSubJobFromDisk(self, subjob_data):
subjob_data (str): filename for the subjob 'data' file we're interested in
"""
# For debugging where this was called from to try and push it to as high a level as possible at runtime
#print("SJXML Load")
#import traceback
# print("SJXML Load")
# import traceback
# traceback.print_stack()
# print("\n\n\n")
#import sys
# import sys
# sys.exit(-1)
job_obj = self.getSafeJob()
if job_obj is not None:
Expand Down Expand Up @@ -414,14 +414,16 @@ def _getItem(self, index):
if isinstance(x, IOError) and x.errno == errno.ENOENT:
raise IOError("Subobject %s not found: %s" % (index, x))
else:
raise RepositoryError(self._registry.repository, "IOError on loading subobject %s: %s" % (index, x))
raise RepositoryError(
self._registry.repository, "IOError on loading subobject %s: %s" %
(index, x))

from GangaCore.Core.GangaRepository.VStreamer import from_file

# load the subobject into a temporary object
try:
loaded_sj = from_file(sj_file)[0]
except (IOError, XMLFileError) as err:
except (IOError, XMLFileError):

try:
logger.warning("Loading subjob #%s for job #%s from backup, recent changes may be lost" % (
Expand Down Expand Up @@ -490,7 +492,7 @@ def getCachedData(self, index):
def getAllCachedData(self):
"""Get the cached data from the index for all subjobs"""
cached_data = []
#logger.debug("Cache: %s" % self._subjobIndexData)
# logger.debug("Cache: %s" % self._subjobIndexData)
if len(self._subjobIndexData) == len(self):
for i in range(len(self)):
if self.isLoaded(i):
Expand Down Expand Up @@ -556,8 +558,10 @@ def _setFlushed(self):
super(SubJobXMLList, self)._setFlushed()

def _private_display(self, reg_slice, this_format, default_width, markup):
""" This is a private display method which makes use of the display slice as well as knowlede of the wanted format, default_width and markup to be used
Given it's display method this returns a displayable string. Given it's tied into the RegistrySlice it's similar to that
""" This is a private display method which makes use of the display slice as well as knowlede of the wanted format,
default_width and markup to be used.
Given it's display method this returns a displayable string.
Given it's tied into the RegistrySlice it's similar to that
Args:
reg_slice (RegistrySlice): This is the registry slice which is the context in which this is called
this_format (str): This is the format used in the registry slice for the formatting of the table
Expand All @@ -573,7 +577,7 @@ def _private_display(self, reg_slice, this_format, default_width, markup):
vals = []
for item in reg_slice._display_columns:
display_str = "display:" + str(item)
#logger.debug("Looking for : %s" % display_str)
# logger.debug("Looking for : %s" % display_str)
width = reg_slice._display_columns_width.get(item, default_width)
try:
if item == 'fqid':
Expand All @@ -591,8 +595,9 @@ def _private_display(self, reg_slice, this_format, default_width, markup):
@staticmethod
def checkJobHasChildren(jobDirectory, datafileName):
""" Return True/False if given (job?) object has children associated with it
This function will test for the presence of all of the subjob XML in the appropriate folders and will trigger an exception
if/when some of the xml files are missing. This is subtly different to the default countSubJobDirs behaviour.
This function will test for the presence of all of the subjob XML in the appropriate folders
and will trigger an exception if/when some of the xml files are missing.
This is subtly different to the default countSubJobDirs behaviour.
Args:
jobDirectory (str): name of folder to be examined
datafileName (str): name of the files containing the xml, i.e. 'data' by convention
Expand All @@ -605,12 +610,15 @@ def checkJobHasChildren(jobDirectory, datafileName):

@staticmethod
def countSubJobDirs(jobDirectory, datafileName, checkDataFiles):
""" I'm a function which returns a number, my number corresponds to the amount of sequentially listed numerically named folders exiting within 'jobDirectory'
This (optionally) checks for the existance of all of the XML files. This is useful during a call to 'jobHasChildrenTest' but not when calling __len__ repeatedly
""" I'm a function which returns a number, my number corresponds to the amount of sequentially
listed numerically named folders exiting within 'jobDirectory'.
This (optionally) checks for the existance of all of the XML files.
This is useful during a call to 'jobHasChildrenTest' but not when calling __len__ repeatedly
Args:
jobDirectory (str): name of folder to be examined
datafileName (str): name of the files containing the xml, i.e. 'data' by convention
checkDataFiles (bool): if True check for the existance of all of the data files and check this against the numerically named folders
checkDataFiles (bool): if True check for the existance of all of the data files
and check this against the numerically named folders
"""

jobDirectoryList = listdir(jobDirectory)
Expand Down
Loading