Skip to content

Commit

Permalink
Code cleanup: standardize calls of client.new() using upper case class
Browse files Browse the repository at this point in the history
names
  • Loading branch information
RKrahl committed Nov 23, 2022
1 parent 25028e0 commit 51782a2
Show file tree
Hide file tree
Showing 21 changed files with 214 additions and 214 deletions.
10 changes: 5 additions & 5 deletions doc/examples/add-investigation-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def makeparam(t, pdata):
sample_type = client.assertedSearch(stsearch)[0]

print("Sample: creating '%s' ..." % sampledata['name'])
sample = client.new("sample")
sample = client.new("Sample")
initobj(sample, sampledata)
sample.type = sample_type
sample.investigation = investigation
Expand All @@ -134,7 +134,7 @@ def makeparam(t, pdata):

for datasetdata in investigationdata['datasets']:
print("Dataset: creating '%s' ..." % datasetdata['name'])
dataset = client.new("dataset")
dataset = client.new("Dataset")
initobj(dataset, datasetdata)
# Need to override the complete flag from the example data as we
# do not have create permissions on complete datasets.
Expand All @@ -149,7 +149,7 @@ def makeparam(t, pdata):
if not conf.skipfiles:
for datafiledata in datasetdata['datafiles']:
print("Datafile: creating '%s' ..." % datafiledata['name'])
datafile = client.new("datafile")
datafile = client.new("Datafile")
initobj(datafile, datafiledata)
datafile.datafileFormat = datafile_formats[datafiledata['format']]
if 'parameters' in datafiledata:
Expand All @@ -159,10 +159,10 @@ def makeparam(t, pdata):
dataset.datafiles.append(datafile)

if 'datasetInstruments' in dataset.InstMRel:
di = client.new("datasetInstrument", instrument=instrument)
di = client.new("DatasetInstrument", instrument=instrument)
dataset.datasetInstruments.append(di)
if 'datasetTechniques' in dataset.InstMRel and technique:
dt = client.new("datasetTechnique", technique=technique)
dt = client.new("DatasetTechnique", technique=technique)
dataset.datasetTechniques.append(dt)

dataset.create()
20 changes: 10 additions & 10 deletions doc/examples/add-job.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def makeparam(t, pdata):
# Create the input data collection
# ------------------------------------------------------------

inputcollection = client.new("dataCollection")
inputcollection = client.new("DataCollection")
initobj(inputcollection, jobdata['input'])

for ds in jobdata['input']['datasets']:
Expand All @@ -83,7 +83,7 @@ def makeparam(t, pdata):
"investigation.name":"= '%s'" % ds['investigation']
})
dataset = client.assertedSearch(query)[0]
dcs = client.new("dataCollectionDataset", dataset=dataset)
dcs = client.new("DataCollectionDataset", dataset=dataset)
inputcollection.dataCollectionDatasets.append(dcs)

for df in jobdata['input']['datafiles']:
Expand All @@ -93,7 +93,7 @@ def makeparam(t, pdata):
"dataset.investigation.name":"= '%s'" % df['investigation']
})
datafile = client.assertedSearch(query)[0]
dcf = client.new("dataCollectionDatafile", datafile=datafile)
dcf = client.new("DataCollectionDatafile", datafile=datafile)
inputcollection.dataCollectionDatafiles.append(dcf)

if 'parameters' in jobdata['input']:
Expand All @@ -108,7 +108,7 @@ def makeparam(t, pdata):
# Create the output data collection
# ------------------------------------------------------------

outputcollection = client.new("dataCollection")
outputcollection = client.new("DataCollection")
initobj(outputcollection, jobdata['output'])

for ds in jobdata['output']['datasets']:
Expand All @@ -121,7 +121,7 @@ def makeparam(t, pdata):
})
dataset_type = client.assertedSearch(query)[0]
print("Dataset: creating '%s' ..." % ds['name'])
dataset = client.new("dataset")
dataset = client.new("Dataset")
initobj(dataset, ds)
dataset.investigation = investigation
dataset.type = dataset_type
Expand All @@ -137,7 +137,7 @@ def makeparam(t, pdata):
})
datafile_format = client.assertedSearch(query)[0]
print("Datafile: creating '%s' ..." % df['name'])
datafile = client.new("datafile")
datafile = client.new("Datafile")
initobj(datafile, df)
datafile.datafileFormat = datafile_format
if 'parameters' in df:
Expand All @@ -153,7 +153,7 @@ def makeparam(t, pdata):
del dataset.datafiles
dataset.complete = True
dataset.update()
dcs = client.new("dataCollectionDataset", dataset=dataset)
dcs = client.new("DataCollectionDataset", dataset=dataset)
outputcollection.dataCollectionDatasets.append(dcs)

for df in jobdata['output']['datafiles']:
Expand All @@ -169,15 +169,15 @@ def makeparam(t, pdata):
})
datafile_format = client.assertedSearch(query)[0]
print("Datafile: creating '%s' ..." % df['name'])
datafile = client.new("datafile")
datafile = client.new("Datafile")
initobj(datafile, df)
datafile.dataset = dataset
datafile.datafileFormat = datafile_format
if 'parameters' in df:
for p in df['parameters']:
datafile.parameters.append(makeparam('datafileParameter', p))
datafile.create()
dcf = client.new("dataCollectionDatafile", datafile=datafile)
dcf = client.new("DataCollectionDatafile", datafile=datafile)
outputcollection.dataCollectionDatafiles.append(dcf)

if 'parameters' in jobdata['output']:
Expand All @@ -197,7 +197,7 @@ def makeparam(t, pdata):
% ( appdata['name'], appdata['version'] ))
application = client.assertedSearch(appsearch)[0]

job = client.new("job",
job = client.new("Job",
application=application,
inputDataCollection=inputcollection,
outputDataCollection=outputcollection)
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/addfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def getdatafileformat(dffid):
# ------------------------------------------------------------

for fname in conf.files:
datafile = client.new("datafile", name=fname.name,
datafile = client.new("Datafile", name=fname.name,
dataset=dataset, datafileFormat=datafileformat)
client.putData(fname, datafile)

Expand Down
4 changes: 2 additions & 2 deletions doc/examples/create-datafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@

fstats = df_path.stat()
modTime = datetime.datetime.utcfromtimestamp(fstats.st_mtime).isoformat() + "Z"
datafile = client.new("datafile")
datafile = client.new("Datafile")
datafile.datafileFormat = dff
datafile.name = conf.datafile.name
datafile.location = str(conf.datafile)
datafile.datafileModTime = modTime
datafile.datafileCreateTime = modTime
datafile.fileSize = fstats.st_size

dataset = client.new("dataset")
dataset = client.new("Dataset")
dataset.investigation=investigation
dataset.type=dst
dataset.complete=False
Expand Down
14 changes: 7 additions & 7 deletions doc/examples/create-investigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def getUser(client, attrs):
try:
return client.assertedSearch("User [name='%s']" % attrs['name'])[0]
except icat.SearchResultError:
user = client.new("user")
user = client.new("User")
initobj(user, attrs)
user.create()
return user
Expand Down Expand Up @@ -98,13 +98,13 @@ def getUser(client, attrs):
% investigationdata['name'])

print("Investigation: creating '%s' ..." % investigationdata['name'])
investigation = client.new("investigation")
investigation = client.new("Investigation")
initobj(investigation, investigationdata)
investigation.facility = facility
investigation.type = investigation_type
if 'parameters' in investigationdata:
for pdata in investigationdata['parameters']:
ip = client.new('investigationParameter')
ip = client.new("InvestigationParameter")
initobj(ip, pdata)
ptdata = data['parameter_types'][pdata['type']]
query = ("ParameterType [name='%s' AND units='%s']"
Expand All @@ -113,7 +113,7 @@ def getUser(client, attrs):
investigation.parameters.append(ip)
if 'shifts' in investigationdata:
for sdata in investigationdata['shifts']:
s = client.new('shift')
s = client.new("Shift")
initobj(s, sdata)
if 'instrument' in s.InstRel:
s.instrument = instrument
Expand All @@ -128,17 +128,17 @@ def getUser(client, attrs):
"endDate": "> '%s'" % parse_attr_string(sd, "Date"),
})
for fc in client.search(query):
ifc = client.new("investigationFacilityCycle", facilityCycle=fc)
ifc = client.new("InvestigationFacilityCycle", facilityCycle=fc)
investigation.investigationFacilityCycles.append(ifc)
if 'fundingReferences' in investigation.InstMRel:
for fr in investigationdata['fundingReferences']:
funding_ref = client.new('fundingReference')
funding_ref = client.new("FundingReference")
initobj(funding_ref, data['fundings'][fr])
try:
funding_ref.create()
except icat.ICATObjectExistsError:
funding_ref = client.searchMatching(funding_ref)
inv_fund = client.new('investigationFunding', funding=funding_ref)
inv_fund = client.new("InvestigationFunding", funding=funding_ref)
investigation.fundingReferences.append(inv_fund)
investigation.create()
investigation.addInstrument(instrument)
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/create-parametertypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
parametertypes = []
for pdata in parametertype_data:
print("ParameterType: creating '%s' ..." % pdata['name'])
parametertype = client.new("parameterType")
parametertype = client.new("ParameterType")
parametertype.name = pdata['name']
parametertype.units = pdata['units']
parametertype.unitsFullName = pdata['unitsFullName']
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/create-sampletype.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
% sampletypedata['name'])

print("SampleType: creating '%s' ..." % sampletypedata['name'])
sampletype = client.new("sampleType")
sampletype = client.new("SampleType")
sampletype.name = sampletypedata['name']
sampletype.molecularFormula = sampletypedata['molecularFormula']
sampletype.facility = facility
Expand Down
26 changes: 13 additions & 13 deletions doc/examples/init-icat.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def getUser(client, attrs):
try:
return client.assertedSearch("User [name='%s']" % attrs['name'])[0]
except icat.SearchResultError:
user = client.new("user")
user = client.new("User")
initobj(user, attrs)
user.create()
return user
Expand Down Expand Up @@ -402,7 +402,7 @@ def getUser(client, attrs):
( "InvestigationFunding", "funding"),
])
pubsteps.sort()
objs = [ client.new("publicStep", origin=origin, field=field)
objs = [ client.new("PublicStep", origin=origin, field=field)
for (origin, field) in pubsteps ]
client.createMany(objs)

Expand All @@ -413,7 +413,7 @@ def getUser(client, attrs):

facilities = {}
for k in data['facilities'].keys():
fac = client.new("facility")
fac = client.new("Facility")
initobj(fac, data['facilities'][k])
fac.create()
facilities[k] = fac
Expand All @@ -426,7 +426,7 @@ def getUser(client, attrs):
if "technique" in client.typemap:
techniques = []
for k in data['techniques'].keys():
t = client.new("technique")
t = client.new("Technique")
initobj(t, data['techniques'][k])
techniques.append(t)
client.createMany(techniques)
Expand All @@ -438,7 +438,7 @@ def getUser(client, attrs):

instusers = []
for k in data['instruments'].keys():
inst = client.new("instrument")
inst = client.new("Instrument")
initobj(inst, data['instruments'][k])
inst.facility = facilities[data['instruments'][k]['facility']]
inst.create()
Expand All @@ -457,7 +457,7 @@ def getUser(client, attrs):
# investigationTypes
investigation_types = []
for k in data['investigation_types'].keys():
it = client.new("investigationType")
it = client.new("InvestigationType")
initobj(it, data['investigation_types'][k])
it.facility = facilities[data['investigation_types'][k]['facility']]
investigation_types.append(it)
Expand All @@ -466,7 +466,7 @@ def getUser(client, attrs):
# datasetTypes
dataset_types = []
for k in data['dataset_types'].keys():
dt = client.new("datasetType")
dt = client.new("DatasetType")
initobj(dt, data['dataset_types'][k])
dt.facility = facilities[data['dataset_types'][k]['facility']]
dataset_types.append(dt)
Expand All @@ -475,7 +475,7 @@ def getUser(client, attrs):
# datafileFormats
fileformats = []
for k in data['datafile_formats'].keys():
ff = client.new("datafileFormat")
ff = client.new("DatafileFormat")
initobj(ff, data['datafile_formats'][k])
ff.facility = facilities[data['datafile_formats'][k]['facility']]
fileformats.append(ff)
Expand All @@ -485,7 +485,7 @@ def getUser(client, attrs):
if "dataPublicationType" in client.typemap:
data_publication_types = []
for k in data['data_publication_types'].keys():
dpt = client.new("dataPublicationType")
dpt = client.new("DataPublicationType")
initobj(dpt, data['data_publication_types'][k])
dpt.facility = facilities[data['data_publication_types'][k]['facility']]
data_publication_types.append(dpt)
Expand All @@ -494,20 +494,20 @@ def getUser(client, attrs):
# parameterTypes
param_types = []
for k in data['parameter_types'].keys():
pt = client.new("parameterType")
pt = client.new("ParameterType")
initobj(pt, data['parameter_types'][k])
pt.facility = facilities[data['parameter_types'][k]['facility']]
if 'values' in data['parameter_types'][k]:
for v in data['parameter_types'][k]['values']:
psv = client.new('permissibleStringValue', value=v)
psv = client.new("PermissibleStringValue", value=v)
pt.permissibleStringValues.append(psv)
param_types.append(pt)
client.createMany(param_types)

# applications
applications = []
for k in data['applications'].keys():
app = client.new("application")
app = client.new("Application")
initobj(app, data['applications'][k])
app.facility = facilities[data['applications'][k]['facility']]
applications.append(app)
Expand All @@ -532,7 +532,7 @@ def gettz(month):
c = 0
for p in fcdata['cycles']:
c += 1
cycle = client.new("facilityCycle")
cycle = client.new("FacilityCycle")
cycle.name = "%02d%d" % (y, c)
cycle.startDate = datetime.datetime(year, p[0], p[1],
tzinfo=gettz(p[0]))
Expand Down
4 changes: 2 additions & 2 deletions doc/examples/paramtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def getMinMax(s):
subcmd = config.add_subcommands()

def add_paramtype(client, conf):
pt = client.new("parameterType")
pt = client.new("ParameterType")
pt.facility = client.assertedSearch("Facility")[0]
pt.name = conf.name
units, units_fullname = getUnits(conf.units)
Expand Down Expand Up @@ -75,7 +75,7 @@ def add_paramtype(client, conf):
raise ValueError("permissible strings do not make sense "
"for %s value type" % conf.valueType)
for s in conf.permstrings.split(','):
psv = client.new("permissibleStringValue", value=s)
psv = client.new("PermissibleStringValue", value=s)
pt.permissibleStringValues.append(psv)
pt.create()
return pt
Expand Down
8 changes: 4 additions & 4 deletions icat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ def searchMatching(self, obj, includes=None):
Search the object from the ICAT server that matches the given
object in the uniqueness constraint.
>>> dataset = client.new("dataset", investigation=inv, name=dsname)
>>> dataset = client.new("Dataset", investigation=inv, name=dsname)
>>> dataset = client.searchMatching(dataset)
>>> dataset.id
172383
Expand Down Expand Up @@ -706,7 +706,7 @@ def createUser(self, name, search=False, **kwargs):
return users[0]

log.info("User: creating '%s'", name)
u = self.new("user", name=name, **kwargs)
u = self.new("User", name=name, **kwargs)
u.create()
return u

Expand All @@ -721,7 +721,7 @@ def createGroup(self, name, users=()):
:rtype: :class:`icat.entity.Entity`
"""
log.info("Group: creating '%s'", name)
g = self.new("grouping", name=name)
g = self.new("Grouping", name=name)
g.create()
g.addUsers(users)
return g
Expand Down Expand Up @@ -749,7 +749,7 @@ def createRules(self, crudFlags, what, group=None):

rules = []
for w in what:
r = self.new("rule",
r = self.new("Rule",
crudFlags=crudFlags, what=str(w), grouping=group)
rules.append(r)
return self.createMany(rules)
Expand Down
Loading

0 comments on commit 51782a2

Please sign in to comment.