コード例 #1
0
def add_efuse(cid, efuse='', force=False, dryrun=False):

    p = page.pageFromId(cid)

    print 80 * "*"
    print cli.getPageTitle(cid)
    print 80 * "*"
    print p
    print 80 * "*"

    efuse_field = []
    if efuse:
        efuse_field.append(fields.EFUSEField(efuse))
    else:
        try:
            efuse_field = fields.buildEFUSEFields()
        except fields.AbortPage:
            print "Page Aborted"
            return False

    if not efuse_field or not p.addField(efuse_field, force=force):
        print "Couldn't add EFUSE %s - Aborting Page Update" % efuse
        return False

    print 80 * "*"
    print cli.getPageTitle(cid)
    print 80 * "*"
    print p
    print 80 * "*"

    if dryrun:
        print "Dry Run, not writing to HWDB"
        return True

    return cli.storePage(p.getMarkup(), cid=cid)
コード例 #2
0
def add_macs(cid, idx=0, macs=[], force=False, dryrun=False):
        
    p = page.pageFromId(cid)

    print 80*"*"
    print cli.getPageTitle(cid)
    print 80*"*"
    print p
    print 80*"*"

    mac_fields = []
    if macs:
        for mac in macs:
            try:
                mac_fields.append(fields.MACField(idx, mac))
                idx += 1
            except ValueError:
                return False
    else:
       try:
            i=0
            print "<enter> to end MAC additions, . to abort this page"
            while True:
                NewMAC = raw_input("MAC ADDRESS: ").strip()
                if NewMAC == ".":
                  raise AbortPage
                if NewMAC == "":
                  break          
                else:
                    if i==0:
                        MACval = "MAC " + str(i) + ": " + NewMAC
                    else:
                        MACval = MACval + "<br>" + "MAC " + str(i) + ": " + NewMAC + "</br>"
                    i=i+1   
            p.addProperty("MAC Addresses", MACval)
        except fields.AbortPage:
            print "Page Aborted"
            return False

    print 80*"*"
    print cli.getPageTitle(cid)
    print 80*"*"
    print p
    print 80*"*"

    if dryrun:
        print "Dry Run, not writing to HWDB"
        return True

    return cli.storePage(p.getMarkup(), cid=cid)
コード例 #3
0
ファイル: add_label.py プロジェクト: slaclab/ConfluenceHWDB
def add_label(cid, 
              label="",):
    
    p = page.pageFromId(cid)

    print 80*"*"
    print cli.getPageTitle(cid)
    print 80*"*"
    print p
    print 80*"*"

    if label: 
      cli.addLabel (label, cid)
    else:
      label = raw_input("Page Tag: ").strip()
      cli.addLabel (label, cid)
    return cli.storePage(p.getMarkup(), cid=cid)
コード例 #4
0
def add_field(cid,
              label="",
              value="",
              link="",
              space="",
              force=False,
              dryrun=False):

    p = page.pageFromId(cid)

    print 80 * "*"
    print cli.getPageTitle(cid)
    print 80 * "*"
    print p
    print 80 * "*"

    if label and (value or link):
        try:
            f = fields.Field(label, value, link, space)
        except ValueError:
            return False
    else:
        try:
            f = fields.buildField(label, value, link, space)
        except fields.AbortPage:
            print "Page Aborted"
            return False

    if not f or not p.addField(f, force=force):
        print "Couldn't add Serial - Aborting Page Update"
        return False

    print 80 * "*"
    print cli.getPageTitle(cid)
    print 80 * "*"
    print p
    print 80 * "*"

    if dryrun:
        print "Dry Run, not writing to HWDB"
        return True

    return cli.storePage(p.getMarkup(), cid=cid)
コード例 #5
0
def add_macs(cid, idx=0, macs=[], force=False, dryrun=False):

    p = page.pageFromId(cid)

    print 80 * "*"
    print cli.getPageTitle(cid)
    print 80 * "*"
    print p
    print 80 * "*"

    mac_fields = []
    if macs:
        for mac in macs:
            try:
                mac_fields.append(fields.MACField(idx, mac))
                idx += 1
            except ValueError:
                return False
    else:
        try:
            mac_fields = fields.buildMACFields(idx)
        except fields.AbortPage:
            print "Page Aborted"
            return False

    for f in mac_fields:
        if not f or not p.addField(f, force=force):
            print "Couldn't add MAC %s - Aborting Page Update" % f
            return False

    print 80 * "*"
    print cli.getPageTitle(cid)
    print 80 * "*"
    print p
    print 80 * "*"

    if dryrun:
        print "Dry Run, not writing to HWDB"
        return True

    return cli.storePage(p.getMarkup(), cid=cid)
コード例 #6
0
def updateProperty(cid):
    p = page.pageFromId(cid)

    print 80 * "*"
    print cli.getPageTitle(cid)
    print 80 * "*"
    print p
    print 80 * "*"
    while True:
        TypeChange = raw_input(
            "Enter <0> to initialize, <1> to add new properties, <2> to change an existing property, <3> to remove a property, <.> to abort:"
        ).strip()

        if TypeChange == ".":
            raise AbortPage

        if TypeChange == "0":
            p.buildProperty()
            return cli.storePage(p.getMarkup(), cid=cid)

        if TypeChange == "1":
            print "<enter> to end property additions, . to abort this page"
            while True:
                NewLabel = raw_input("New Label: ").strip()
                if NewLabel == ".":
                    raise AbortPage
                if NewLabel == "":
                    break
                try:
                    NewValue = raw_input(
                        "Corresponding Value (<enter> for none): ").strip()
                    if NewValue == ".":
                        raise AbortPage
                    if NewValue == "":
                        break
                    try:
                        p.addProperty(NewLabel, NewValue)
                        return cli.storePage(p.getMarkup(), cid=cid)
                    except ValueError:
                        pass
                except ValueError:
                    pass

        if TypeChange == "2":
            try:
                for i in range(len(p.__properties.__key)):
                    print "<" + i + "> " + p.__properties.__key[i]
                while true:
                    LabelChange = raw_input(
                        "To change a category name, select the corresponding <#>: "
                    ).strip()
                    if LabelChange == ".":
                        raise AbortPage
                    if LabelChange == " ":
                        break
                    try:
                        NewLabel = raw_input("New Label: ").strip()
                        p.__properties.__key[i] = NewLabel
                        for j in range(len(p.__properties.__value)):
                            print "<" + j + "> " + p.__properties.__value[j]
                            ValueChange = raw_input(
                                "To change a category name, select the corresponding <#>: "
                            ).strip()
                            if ValueChange == ".":
                                raise AbortPage
                            if ValueChange == " ":
                                break
                            try:
                                NewValue = raw_input("New Value: ").strip()
                                p.__properties.__key[j] = NewValue
                            except ValueError:
                                pass
                    except ValueError:
                        pass
            except ValueError:
                pass

        if TypeChange == "3":
            try:
                for i in range(len(p.__properties.__key)):
                    print "<" + i + "> " + p.__properties._key[i]
                while true:
                    RemoveIndex = raw_input(
                        "To remove a category, select the corresponding <#>: "
                    ).strip()
                    if RemoveIndex == ".":
                        raise AbortPage
                    if RemoveIndex == " ":
                        break
                    try:
                        del p.__properties.__key[RemoveIndex]
                        del p.__properties.__value[RemoveIndex]
                    except ValueError:
                        pass
            except ValueError:
                pass

    print 80 * "*"
    print cli.getPageTitle(cid)
    print 80 * "*"
    print p
    print 80 * "*"

    return cli.storePage(p.getMarkup(), cid=cid)
コード例 #7
0
ファイル: initpage.py プロジェクト: slaclab/ConfluenceHWDB
def init_page(cid, devtype="", tag="", status="", site="", dryrun=False):

    p = page.pageFromId(cid)
    title_base = cli.getPageTitle(cid)

    print 80 * "*"
    print title_base
    print 80 * "*"
    print p
    print 80 * "*"

    if not p.isBlank():
        print "-ERROR- Can only run initpage on a blank page"
        return False

    if devtype:
        try:
            f = fields.TypeField(devtype)
        except ValueError:
            return False
    else:
        f = fields.buildTypeField()

    if not f or not p.addField(f, force=True):
        print "Couldn't add Type - Aborting Page Init"
        return False

    devclass = hwpages.typeToClass.get(f.getLink(), None)

    if tag:
        try:
            f = fields.AssetTagField(tag)
        except ValueError:
            return False
    else:
        f = fields.buildAssetTagField()

    tag = f.getValue()

    if not f or not p.addField(f, force=True):
        print "Couldn't add AssetTag - Aborting Page Init"
        return False

    if not status:
        status = raw_input("Board Status: ")

    p.setStatus(status)

    p.buildProperty()

    label = raw_input("Page Tag: ").strip()
    cli.addLabel(label, cid)

    comment = "Born: " + datetime.datetime.utcnow().isoformat(" ") + " UTC"
    new_title = devclass + " " + tag + ' - ' + title_base

    if not site:
        site = fields.choose("New Location", sites.CONTAINER_PAGES)

    if not dryrun:
        if not cli.storePage(p.getMarkup(), cid=cid):
            print "Page content update failed!"
            return False

        if not cli.addComment(title_base, comment):
            print "Adding a comment failed!"
            return False

        if not cli.renamePage(newTitle=new_title, cid=cid, newParent=site):
            print "Moving the page failed!"
            return False
    else:
        print "Dry Run, not writing to HWDB"

    print "*" * 80
    print "%s/%s" % (site, new_title)
    print "*" * 80
    print p
    print "*" * 80

    return True