def replace(self): """Promote the selected version, log the action, and show the form.""" if not self.session.can_do("MODIFY DOCUMENT", self.doc.doctype.name): self.bail("Not authorized") if not self.version: self.bail("No version specified") comment = f"Replacing CWD with version {self.version:d}" doc = Doc(self.session, id=self.doc.id, version=self.version) doc.check_out(comment=comment) pub_ver = self.make_version_publishable if self.comment: comment = f"{comment}: {self.comment}" opts = dict( version=self.create_version, publishable=pub_ver, val_types=("schema", "links") if pub_ver else None, comment=comment, reason=comment, unlock=True, ) doc.save(**opts) path = f"{self.session.tier.logdir}/CWDReplacements.log" try: with open(path, "a", encoding="utf-8") as fp: fp.write(f"{self.message}\n") except IOError as e: self.bail(f"Error writing to {path}: {e}") self.show_form()
def save(self): """Create the Media document for this audio file. With changes introduced by CDR Maxwell, we also update Media documents which are being recycled with a new audio pronunciation recording. For those we defer the updating of those documents to be done in a batch using the global change harness, and only log them here. See OCECDR-4890 and other Maxwell tickets. """ if self.media_id: doc = Doc(self.__control.session, id=self.media_id) if doc.doctype.name != "Media": raise Exception(f"CDR{self.media_id} is not a Media document") action = "updated" else: opts = dict(xml=self.xml, blob=self.bytes, doctype="Media") doc = Doc(self.__control.session, **opts) action = "created" opts = dict( version=True, publishable=True, comment=self.COMMENT, reason=self.COMMENT, val_types=("schema", "links"), unlock=True, ) doc.save(**opts) self.media_id = doc.id args = action, self.term_id, self.name, self.langcode, self.__path message = self.MESSAGE.format(*args) self.__control.rows.append((f"CDR{doc.id}", message)) self.__control.logger.info("%s as CDR%d", message, doc.id)
def expire(self): """ Update data partner's CDR document to reflect deactivation. """ doc = Doc(self.control.session, id=self.org_id) root = doc.root node = root.find("LicenseeInformation/LicenseeStatus") if node.text == "Test-inactive": self.logger.warning("CDR%s already deactivated", self.org_id) return self.logger.info("Marking CDR%s as expired", self.org_id) node.text = "Test-inactive" today = str(datetime.date.today()) node = root.find("DateLastModified") if node is None: node = etree.SubElement(root, "DateLastModified") node.text = today node = root.find("LicenseeInformation/LicenseeStatusDates") if node is None: message = "CDR%s missing LicenseeStatusDates" self.logger.warning(message, self.org_id) else: child = node.find("TestInactivation") if child is None: child = etree.Element("TestInactivation") sibling = node.find("TestActivation") if sibling is not None: sibling.addnext(child) else: node.insert(0, child) if child.text is None or not child.text.strip(): child.text = today if not self.control.test: comment = "Marking account as inactive" doc.check_out(force=True, comment=comment) opts = dict( version=True, reason=comment, comment=comment, unlock=True, ) doc.save(**opts)
help="make version publishable", action="store_true") parser.add_argument("--force", "-f", help="force checkout", action="store_true") opts = parser.parse_args() if opts.session: session = Session(opts.session, tier=opts.tier) else: session = Session.create_session(opts.user, tier=opts.tier) print(session) with open(opts.xml, "rb") as fp: xml = fp.read() doc = Doc(session, id=opts.id, doctype=opts.doctype, xml=xml) if opts.id: doc.check_out(force=opts.force) version = opts.version or opts.publishable val_types = ["schema", "links"] if opts.publishable else None save_opts = dict( version=version, publishable=opts.publishable, val_types=val_types, comment=opts.comment, unlock=True, ) doc.save(**save_opts) print(f"saved {doc.cdr_id} ({doc.title})") if not opts.session: session.logout()