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

daf_persistence - Tickets/dm 11407 #74

Merged
merged 10 commits into from
Sep 1, 2017
Merged

daf_persistence - Tickets/dm 11407 #74

merged 10 commits into from
Sep 1, 2017

Conversation

n8pease
Copy link
Contributor

@n8pease n8pease commented Aug 21, 2017

No description provided.

Copy link
Contributor

@andy-slac andy-slac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly OK, see comments in diffs. One left-over self needs to be removed.



class RepositoryCfgPosixFormatter():
def write(butlerLocation, cfg):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read and write are very generic names and you do from .fmtPosixRepositoryCfg import * which has a small chance of messing up with other names. I'd probably add __all__ = [] before all imports to avoid these names being picked up by import *. Two other alternatives:

  • replace from .fmtPosixRepositoryCfg import * with from . import fmtPosixRepositoryCfg (I don't think you need any names from this module
  • rename read and write into "local" names _read and _write. Still __all__ = [] is useful if you keep import * because all non-underscored names are still being imported if you don't define __all__

----------
cfg : RepositoryCfg instance
The RepositoryCfg to be serialized.
butlerLocation : ButlerLocation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order should probably correspond to order in the argument list.

loc = os.path.split(loc)[0] # remove the `repoistoryCfg.yaml` file name
if loc is None or cfg.root == loc:
cfg = copy.copy(cfg)
loc = cfg.root
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this line do anything?

return
except IOError as e:
if e.errno != errno.ENOENT: # ENOENT is 'No such file or directory'
raise e
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raise without e is enough

Parameters
----------
fileObject : an open file object
the file that contains the RepositoryCfg.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add uri description?

return


def readPafStorage(self, butlerLocation):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self?

for locationString in butlerLocation.getLocations():
logLoc = LogicalLocation(butlerLocation.getStorage().locationWithRoot(locationString),
butlerLocation.getAdditionalData())
finalItem = Policy(filePath=logLoc.locString())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this Policy is different from pexPolicy? Sort of confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah. naming is hard. sorry.

The formatter class that can be used by the StorageInterface instance to read and write the object
to the storage.
readFormatter : a read formatter callable
The formatter class that can be used by the StorageInterface instance to read the object from the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatter class - > method? (or function if you prefer)

cls._registerFormatter(formatable, readFormatter, 'read')

@classmethod
def registerWriteFormatter(cls, formatable, writeFormatter):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead three separate methods registerFormatters, registerReadFormatter, registerWriteFormatter I'd probably define just one with keyword arguments:

def registerFormatters(cls, formattable, read=None, write=None)
    ....

Feels more Pythonic to me 🐍

formatter callable
The formatter callable used to read the object from the storageInterface.
"""
classFormatters = StorageInterface.readFormatters.get(cls, None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor issue with using cls as a key in a global map — if, for example, I decide to implement new Storage as subclass of PosixStorage (not sure if that is possible) then calling self._getFormatter() in a subclass will not find any formatters registered with PosixStorage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it's broken. I ran into it the other day. Needs fixing.

@n8pease n8pease force-pushed the tickets/DM-11407 branch 3 times, most recently from 3d781fd to 4b2be16 Compare August 28, 2017 18:23
@n8pease n8pease merged commit be307b4 into master Sep 1, 2017
@ktlim ktlim deleted the tickets/DM-11407 branch August 25, 2018 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants