Esempio n. 1
0
    def load(self, cdr_id):
        """
        Check out the CDR Term document, parse it, and update it with
        the current concept information.

        Pass:
            cdr_id - unique identified of the existing CDR Term document

        Return:
            cdr.Doc object with updated terms and/or definitions
        """

        try:
            self.cdr_id, self.doc_id, frag_id = cdr.exNormalize(cdr_id)
            if cdr.lastVersions(self.session, self.cdr_id)[1] != -1:
                self.published = True
        except:
            Concept.fail("invalid CDR ID %r" % cdr_id)
        self.concept.logger.info("updating %s", self.cdr_id)
        try:
            doc = cdr.getDoc(self.session, self.cdr_id, "Y", getObject=True)
        except Exception as e:
            Concept.fail("failure retrieving %s: %s" % (self.cdr_id, e))
        try:
            self.root = self.parse(doc.xml)
            doc.xml = self.update()
            return doc
        except Exception:
            cdr.unlock(self.session, self.cdr_id)
            raise
Esempio n. 2
0
        def __init__(self, job, doc_id):

            self.job = job
            self.id = doc_id
            self.cdr_id = cdr.normalize(doc_id)
            self.versions = cdr.lastVersions("guest", doc_id, tier=job.tier)
            self.status = cdr.getDocStatus("guest", doc_id, tier=job.tier)
            self.saved = set()
            self.doc_objects = {}
            self.transformed_xml = {}
            self.errors = {}
            self.changed = set()
            self.load_versions()
Esempio n. 3
0
 def __init__(self, id):
     self.id = id
     self.name = None
     docId = 'CDR%d' % id
     versions = cdr.lastVersions('guest', docId)
     ver = str(versions[0])
     doc = cdr.getDoc('guest', docId, version=ver, getObject=True)
     errors = cdr.getErrors(doc, errorsExpected=False, asSequence=True)
     if errors:
         raise Exception("loading doc %d for editor in chief: %s" %
                         (id, "; ".join(errors)))
     dom = xml.dom.minidom.parseString(doc.xml)
     for node in dom.documentElement.childNodes:
         if node.nodeName == "PersonNameInformation":
             self.name = cdrmailer.PersonalName(node)
     if not self.name:
         raise Exception("No name found for editor-in-chief %d" % id)
Esempio n. 4
0
def main():
    """
    Store the new version of the filter.  Processing steps:

      1. Parse the command-line options and arguments.
      2. Load the new version of the filter from the file system.
      3. Log into the CDR on the target server.
      4. Find the CDR ID which matches the filter title
      5. Check out the document from the target CDR server.
      6. Store the new version on the target CDR server.
      7. Report the number of the new version.
      8. Clean up.
    """

    #------------------------------------------------------------------
    # 1. Parse the command-line options and arguments.
    #------------------------------------------------------------------
    parser = create_parser()
    opts = parser.parse_args()
    pub = "Y" if opts.publishable else "N"

    # If no comment is specified the last comment used (from the
    # all_docs table) would be stored.
    # Setting the comment to something to overwrite the last comment
    # -----------------------------------------------------------------
    comment = opts.comment or "Replaced w/o user comment"

    #------------------------------------------------------------------
    # 2. Load the new version of the filter from the file system.
    #------------------------------------------------------------------
    with open(opts.filename) as fp:
        xml = fp.read()
    if "]]>" in xml:
        parser.error("CdrDoc wrapper must be stripped from the file")

    #------------------------------------------------------------------
    # 3. Log into the CDR on the target server.
    #------------------------------------------------------------------
    if opts.session:
        session = opts.session
    else:
        password = getpass.getpass()
        session = cdr.login(opts.user, password, tier=opts.tier)
        error_message = cdr.checkErr(session)
        if error_message:
            parser.error(error_message)

    #------------------------------------------------------------------
    # 4. Find out what the filter's document ID is.
    #------------------------------------------------------------------
    doc_id = get_doc_id(xml, opts.tier, session)

    #------------------------------------------------------------------
    # 5. Check out the document from the target CDR server.
    #------------------------------------------------------------------
    args = dict(checkout="Y", getObject=True, tier=opts.tier)
    doc = cdr.getDoc(session, doc_id, **args)
    error_message = cdr.checkErr(doc)
    if error_message:
        parser.error(error_message)

    #------------------------------------------------------------------
    # 6. Store the new version on the target CDR server.
    #------------------------------------------------------------------
    doc.xml = xml.encode("utf-8")
    args = dict(
        doc=str(doc),
        checkIn="Y",
        setLinks="N",
        reason=comment,
        comment=comment,
        ver="Y",
        verPublishable=pub,
        tier=opts.tier
    )
    doc_id = cdr.repDoc(session, **args)
    if not doc_id.startswith("CDR"):
        parser.error(error_message)

    #------------------------------------------------------------------
    # 7. Report the number of the latest version.
    #------------------------------------------------------------------
    versions = cdr.lastVersions(session, doc_id, tier=opts.tier)
    print(("Saved {} as version {}".format(doc_id, versions[0])))

    #------------------------------------------------------------------
    # 8. Clean up.
    #------------------------------------------------------------------
    if not opts.session:
        cdr.logout(session, tier=opts.tier)
Esempio n. 5
0
    def __parseBoardDoc(self, id):

        today = str(self.today)
        docId = "CDR%d" % id
        versions = cdr.lastVersions('guest', docId)
        ver = str(versions[0])
        doc = cdr.getDoc('guest', docId, version=ver, getObject=True)
        errors = cdr.getErrors(doc, errorsExpected=False, asSequence=True)
        if errors:
            raise Exception("loading doc for board %d: %s" %
                            (id, "; ".join(errors)))
        dom = xml.dom.minidom.parseString(doc.xml)
        for node in dom.documentElement.childNodes:
            if node.nodeName == "OrganizationNameInformation":
                for child in node.childNodes:
                    if child.nodeName == "OfficialName":
                        for grandchild in child.childNodes:
                            if grandchild.nodeName == "Name":
                                self.name = cdr.getTextContent(grandchild)
            elif node.nodeName == "OrganizationType":
                self.boardType = cdr.getTextContent(node)
            elif node.nodeName == "PDQBoardInformation":
                managerNode = None
                phoneNode = None
                emailNode = None
                for child in node.childNodes:
                    if child.nodeName == "BoardManager":
                        managerNode = child
                    elif child.nodeName == "BoardManagerPhone":
                        phoneNode = child
                    elif child.nodeName == "BoardManagerEmail":
                        emailNode = child
                    elif child.nodeName == "BoardMeetings":
                        for grandchild in child.childNodes:
                            if grandchild.nodeName == 'BoardMeeting':
                                md = self.MeetingDate(grandchild)
                                if md.date >= today:
                                    self.meetingDates.append(md)
                    elif child.nodeName == "AdvisoryBoardFor":
                        edBoardId = child.getAttribute("cdr:ref")
                        self.edBoardId = cdr.exNormalize(edBoardId)[1]
                self.manager = self.Manager(managerNode, phoneNode, emailNode)
        if not self.name or not self.name.strip():
            raise Exception("no name found for board in document %d" % id)
        if not self.manager:
            raise Exception("no board manager found in document %d" % id)
        self.boardValues = BoardValues.findBoardValues(self.name)
        self.summaryType = self.boardValues.summaryType
        self.workingGroups = self.boardValues.workingGroupBlock
        self.invitePara = self.boardValues.invitationParagraph
        self.meetingDates.sort(key=lambda a: a.date)
        self.name = self.name.strip()
        if self.boardType.upper() == 'PDQ ADVISORY BOARD':
            self.advBoardId = self.id
            self.advBoardName = self.name
            self.edBoardName = self.__getBoardName(self.edBoardId)
        elif self.boardType.upper() == 'PDQ EDITORIAL BOARD':
            self.edBoardId = self.id
            self.edBoardName = self.name
            self.advBoardId = self.__findAdvBoardFor(self.id)
            self.advBoardName = self.__getBoardName(self.advBoardId)
        else:
            raise Exception('Board type: %s' % self.boardType)
Esempio n. 6
0
    raise Exception("Can't have more than one sweep spec document")

# If the document already exists, create a new version
if result:
    doc_id = result[0].docId
    args = dict(checkout="Y", getObject=True, tier=opts.tier)
    doc = cdr.getDoc(opts.session, doc_id, **args)
    error_message = cdr.checkErr(doc)
    if error_message:
        parser.error(error_message)
    doc.xml = xml
    save_opts["doc"] = str(doc)
    doc_id, warnings = cdr.repDoc(opts.session, **save_opts)

# Otherwise, create the document (with a first version)
else:
    doc = cdr.Doc(xml, doctype, encoding="utf-8")
    save_opts["doc"] = str(doc)
    doc_id, warnings = cdr.addDoc(opts.session, **save_opts)

# Let the user know how things went
if warnings:
    print((doc_id and "WARNINGS" or "ERRORS"))
    for error in cdr.getErrors(warnings, asSequence=True):
        print((" -->", error))
if not doc_id:
    print("*** DOCUMENT NOT SAVED ***")
else:
    versions = cdr.lastVersions(opts.session, doc_id, tier=opts.tier)
    print(("Saved {} as version {}".format(doc_id, versions[0])))
Esempio n. 7
0
def main():

    #------------------------------------------------------------------
    # 1. Parse the command-line options and arguments.
    #------------------------------------------------------------------
    op = createOptionParser()
    (options, args) = op.parse_args()
    if len(args) != 4:
        op.error("incorrect number of arguments")
    uid, pwd, idArg, filename = args
    if not options.publishable:
        options.publishable = 'N'
    elif options.publishable == 'Y':
        options.version = 'Y'
    fullId, intId, fragId = cdr.exNormalize(idArg)

    # If no comment is specified the last comment used (from the
    # all_docs table) would be stored.
    # Setting the comment to something to overwrite the last comment
    # -----------------------------------------------------------------
    if not options.comment:
        options.comment = "Filter title changed"

    #------------------------------------------------------------------
    # 2. Load the new version of the filter from the file system.
    #------------------------------------------------------------------
    fp = open(filename, 'r')
    docXml = fp.read()
    fp.close()
    if ']]>' in docXml:
        op.error("CdrDoc wrapper must be stripped from the file")

    #------------------------------------------------------------------
    # 3. Log into the CDR on the target server.
    #------------------------------------------------------------------
    session = cdr.login(uid, pwd)
    checkForProblems(session, op)

    #------------------------------------------------------------------
    # 4. Check out the document from the target CDR server.
    #------------------------------------------------------------------
    docObj = cdr.getDoc(session, fullId, checkout='Y', getObject=True)
    checkForProblems(docObj, op)

    #------------------------------------------------------------------
    # 5. Plug in the new title for the filter.
    #------------------------------------------------------------------
    docObj.ctrl['DocTitle'] = getNewTitle(docXml)

    #------------------------------------------------------------------
    # 6. Store the new version on the target CDR server.
    #------------------------------------------------------------------
    doc = str(docObj)
    print('Versioned: %s, Publishable: %s' %
          (options.version, options.publishable))
    cdrId = cdr.repDoc(session,
                       doc=doc,
                       checkIn="Y",
                       setLinks="N",
                       reason=options.comment,
                       comment=options.comment,
                       ver=options.version,
                       verPublishable=options.publishable)
    checkForProblems(cdrId, op)

    #------------------------------------------------------------------
    # 7. Report the number of the latest version.
    #------------------------------------------------------------------
    versions = cdr.lastVersions(session, cdrId)
    if options.version == "N":
        print("CWD for %s updated" % cdrId)
    else:
        print("Latest version of %s is %d" % (cdrId, versions[0]))
    print("")
    print("DON'T FORGET TO CHANGE THE TITLE OF THIS FILTER ON ALL TIERS!")