示例#1
0
    def __init__(self, letter, name):
        """
        Creates a new MiscellaneousDoc object for insertion into
        a correspondence mailer RTF document.  Pass in the reference
        to the object for the letter into which the contents of
        the miscellaneous document are to be inserted, and the
        title of the CDR document to be loaded.
        """

        import cdr
        from lxml import etree

        self.letter = letter
        path = "/MiscellaneousDocument/MiscellaneousDocumentTitle"
        query = f"{path}/value eq {name}"
        try:
            resp = cdr.search("guest", query)
        except Exception as e:
            raise Exception("failure loading misc doc {name!r}: {e}")
        if not resp:
            raise Exception(f"Miscellaneous document {name!r} not found")
        self.docId = resp[0].docId
        try:
            doc = cdr.getDoc("guest", self.docId, getObject=True)
        except Exception as e:
            raise Exception(f"Retrieving {self.docId}: {e}")
        self.root = etree.fromstring(doc.xml)
示例#2
0
def get_doc_id(path, tier):
    """
    Extract the document title from the filename and look up the CDR
    document ID which matches the title.
    """

    basename = os.path.basename(path)
    if not basename.lower().endswith(".xml"):
        raise Exception("unexpected filename pattern %r" % basename)
    title = basename[:-4]
    doctype = "PublishingSystem"
    query = "CdrCtl/Title = {}".format(title)
    result = cdr.search("guest", query, doctypes=[doctype], tier=tier)
    if not result:
        raise Exception(u"Control document %r not found" % title)
    if len(result) > 1:
        raise Exception(u"Ambiguous title %r" % title)
    return result[0].docId
示例#3
0
def get_doc_id(xml, tier, session):
    """
    Extract the filter title from the document, and look up the CDR
    document ID which matches the title.
    """

    match = re.search("<!--\\s*filter title:(.*?)-->", xml, re.I)
    if not match:
        raise Exception("Filter title comment not found")
    title = match.group(1).strip()
    if not title:
        raise Exception("Filter title in document comment is empty")
    query = "CdrCtl/Title = {}".format(title)
    result = cdr.search(session, query, doctypes=["Filter"], tier=tier)
    if not result:
        raise Exception(u"Filter %r not found" % title)
    if len(result) > 1:
        raise Exception(u"Ambiguous filter title %r" % title)
    return result[0].docId
示例#4
0
if "]]>" in xml:
    parser.error("CdrDoc wrapper must be stripped from the file")

# Prepare the save operation
save_opts = dict(checkIn="Y",
                 reason=opts.comment,
                 comment=opts.comment,
                 ver="Y",
                 val="Y",
                 tier=opts.tier,
                 showWarnings=True)

# See if we already have the document installed
doctype = "SweepSpecifications"
query = "CdrCtl/Title contains %"
result = cdr.search("guest", query, doctypes=[doctype], tier=opts.tier)
if len(result) > 1:
    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)
示例#5
0
parser.add_argument("--quiet", "-q", action="store_true")
parser.add_argument("--tier", "-t")
parser.add_argument("files", nargs="*", default="*.xml")
opts = parser.parse_args()
session = Session('guest', tier=opts.tier)
for pattern in opts.files:
    for name in glob.glob(pattern):
        baseName = os.path.basename(name)
        try:
            with open(name, encoding="utf-8") as fp:
                localDoc = fp.read().replace("\r", "").splitlines(True)
        except Exception as e:
            print(f"... unable to open {name}: {e}")
            continue
        query = f"CdrCtl/Title = {baseName}"
        results = cdr.search(session, query, doctypes=["schema"],
                             tier=opts.tier)
        if len(results) < 1:
            print(f"... schema {baseName} not found in CDR")
        else:
            for result in results:
                if not opts.quiet:
                    print(f"comparing {result.docId} to {name}")
                try:
                    doc = Doc(session, id=result.docId)
                    xml = doc.xml
                except Exception as e:
                    print(f"error: {e}")
                    continue
                cdrDoc = xml.replace("\r", "").splitlines(True)
                diffSeq = differ.compare(localDoc, cdrDoc)
                diff = []