3 from logging
import getLogger; log =
getLogger(
"DQDefects.tags")
5 from PyCool
import cool
7 from DQUtils
import IOVSet
9 from DQDefects
import DEFECT_LOGIC_TAG_FORMAT
11 from .exceptions
import InvalidTagError, InvalidDefectTagError, InvalidLogicTagError
13 from .virtual_mixin
import NONHEAD_MODIFICATION_MSG
15 from typing
import List, Optional, Iterable
18 tagtype = collections.namedtuple(
'tagtype', [
'defects',
'logic'])
22 super(DefectsDBTagsMixin, self).
__init__()
29 Returns a list of existing logic tags
31 return [
str(t)
for t
in self.defect_logic_folder.listTags()]
36 Returns a list of existing defect tags
38 return [
str(t)
for t
in self.defects_folder.listTags()]
43 Gives the next available DEFECTLOGICS tag
47 new_id =
max(
int(
str(t).
split(
"-")[-1])
for t
in existing_tags) + 1
50 return DEFECT_LOGIC_TAG_FORMAT % new_id
54 Give the current HEAD of `folder` a new tag and lock it.
56 LOCKED = cool.HvsTagLock.LOCKED
57 aname = name.encode(
'ascii')
58 folder.cloneTagAsUserTag(
'HEAD', aname, description.encode(
'utf-8'))
59 folder.setTagLockStatus(aname, LOCKED)
63 Create a new heirarchical tag relating the defects and logics
65 New tag is of the form
66 "DetStatus-[Logic revision number]-[Defect tagname]"
70 logic_revision =
int(logics_tag.split(
"-")[-1])
71 defect_part =
"-".
join(defects_tag.split(
"-")[1:])
72 hierarchical_tag =
"DetStatus-v%02i-%s" % (logic_revision, defect_part)
73 logicspart =
"(%i) " % logic_revision
75 adefects_tag = defects_tag.encode(
'ascii')
76 alogics_tag = logics_tag.encode(
'ascii')
77 ahierarchical_tag = hierarchical_tag.encode(
'ascii')
78 logicspart = logicspart.encode(
'ascii')
79 defect_descr = self.defects_folder.tagDescription(adefects_tag).
encode(
'utf-8')
82 description = logicspart + defect_descr[:255 - len(logicspart)]
84 parent_folder = self.parent_folderset
85 self.defects_folder.createTagRelation(ahierarchical_tag, adefects_tag)
86 self.defect_logic_folder.createTagRelation(ahierarchical_tag, alogics_tag)
87 parent_folder.setTagDescription(ahierarchical_tag, description)
89 log.info(
"New hierarchical tag %s", hierarchical_tag)
90 return hierarchical_tag
96 except InvalidTagError:
105 except InvalidTagError:
112 Ensure that the tags that this DefectsDB instance was constructed with
121 Return the tag used for retrieving defects on this DefectsDB instance
123 if self._tag.defects ==
"HEAD":
return "HEAD"
125 return self.defects_folder.resolveTag(self._tag.defects)
130 return self._tag.defects
135 Return the tag used for retrieving virtual defect clauses
137 if self._tag.logic ==
"HEAD":
return "HEAD"
139 return self.defect_logic_folder.resolveTag(self._tag.logic)
144 return self._tag.logic
149 Readonly property stating the tag that the database was instantiated on
156 The list of tags which are on the database
158 return [
str(t)
for t
in self.parent_folderset.listTags()]
162 Create a new tag for the logic folder and lock it.
165 `description` : What changed in this tag? (optional, default "")
170 folder = self.defect_logic_folder
172 log.info(
"Tagged DEFECTLOGICS HEAD with %s", new_tag_name)
175 def new_defects_tag(self, name: str, description: str, iovranges: Optional[Iterable] =
None) -> str:
177 Clones the current DEFECTS tag (specified in the constructor) to a new one
178 If iovranges != None, does the slower thing of copying IOVs one by one
181 `name` : Name of the new tag
182 `description` : Description of the contents of this tag
184 if name.startswith(
"DetStatus"):
185 raise RuntimeError(
"Only specify the last part of the defect tag")
186 adescription = description.encode(
'utf-8')
188 log.info(
"Creating new tag %s", name)
190 name = f
"DetStatusDEFECTS-{name}"
191 aname = name.encode(
'ascii')
193 if iovranges
is None:
194 self.defects_folder.cloneTagAsUserTag(self.
defects_tag.
encode(
'ascii'), aname, adescription)
198 kwargs = dict(primary_only=
True, nonpresent=
True, intersect=
True)
199 iovsets = (self.retrieve(*iovrange, **kwargs)
for iovrange
in iovranges)
200 to_copy = IOVSet.from_iovsets(iovsets)
202 log.info(
"Copying IoVs: %r", to_copy)
204 with self.storage_buffer:
206 self._insert_iov(iov, name)
210 self.defects_folder.setTagDescription(aname, adescription)