예제 #1
0
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description="  updates python-%s, python3-~ on all hosts from the repo"
        % (PACKET_NAME))

    parser.add_argument(
        '-x',
        dest="execute",
        action="store_true",
        default=False,
        help='update python-%s, python3-~ on all nodes, from repo' %
        (PACKET_NAME))

    parser.add_argument('-r',
                        dest="updateRepo",
                        action="store_true",
                        default=False,
                        help='update repo first')

    args = parser.parse_args()

    if not args.execute:
        parser.print_help()
        return

    if args.updateRepo:
        if os.system("./UpdateDebianRepo.py -x"):
            print "Failed to update the debian repo"
            return

    nodes = HasyUtils.readHostList(HOST_LIST)

    sz = len(nodes)
    count = 1
    countFailed = 0
    countOffline = 0
    for host in nodes:
        if not HasyUtils.checkHostRootLogin(host):
            print "-- checkHostRootLogin returned error %s" % host
            countOffline += 1
            continue
        cmd = 'ssh -l root %s "apt-get update && apt -y install python-%s && apt install -y python3-%s && dpkg -s python-%s && dpkg -s python3-%s && echo "" > /dev/null 2>&1"' % (
            host, PACKET_NAME, PACKET_NAME, PACKET_NAME, PACKET_NAME)
        # print( "%s" % cmd)
        if os.system(cmd):
            print "Failed to update %s" % host
            countFailed += 1
            continue
        else:
            print("Updated %s OK" % host)
        print "\nDoAll: %d/%d (offline %d, failed %d) %s \n" % (
            count, sz, countOffline, countFailed, host)
        count += 1
    return
예제 #2
0
def main():

    DIR_NAME = os.getenv("PWD").split("/")[-1]
    if DIR_NAME == 'hasyutils':
        PACKET_NAME = "hasyutils"
    elif DIR_NAME == 'pySpectra':
        PACKET_NAME = "pyspectra"
    elif DIR_NAME == 'tngGui':
        PACKET_NAME = "tnggui"
    else:
        print("DisplayVersion.py: failed to identify %s" % DIR_NAME)
        sys.exit(255)
    ROOT_DIR = "/home/kracht/Misc/%s" % DIR_NAME

    nodes = HasyUtils.readHostList(HOST_LIST)

    sz = len(nodes)
    count = 1
    for host in nodes:
        if not HasyUtils.checkHostRootLogin(host):
            print "-- checkHostRootLogin returned error %s" % host
            continue
        ret = os.popen("ssh root@%s \"dpkg -l python-%s 2>/dev/null\"" %
                       (host, PACKET_NAME)).read()
        lst = ret.split('\n')
        for line in lst:
            if line.find("python-%s" % PACKET_NAME) > 0:
                lst1 = line.split()
                print "%d/%d: %s, python-%s %s" % (count, sz, host,
                                                   PACKET_NAME, lst1[2])
        ret = os.popen("ssh root@%s \"dpkg -l python3-%s 2>/dev/null\"" %
                       (host, PACKET_NAME)).read()
        lst = ret.split('\n')
        for line in lst:
            if line.find("python3-%s" % PACKET_NAME) > 0:
                lst1 = line.split()
                print "%d/%d: %s, python3-%s %s" % (count, sz, host,
                                                    PACKET_NAME, lst1[2])
        count += 1
    return