def getAuthenticatedKeys():
    from PyFoam.Infrastructure.Authentication import authenticatedKeys,ensureKeyPair
    ensureKeyPair()
    return authenticatedKeys()
    def run(self):
        from PyFoam.Infrastructure.Authentication import ensureKeyPair
        ensureKeyPair()

        if self.opts.zeroconf:
            data = getServerList(self.opts.timeout,
                                 verbose=self.opts.debugZeroconf,
                                 progress=self.opts.progressZeroconf)
        else:
            self.warning(
                "Using the old method of querying the meta-server. This is deprecated"
            )
            try:
                self.server = getServerProxy(self.parser.options.server,
                                             self.parser.options.port)
                data = self.server.list()
            except socket.error as reason:
                print_("Socket error while connecting:", reason)
                sys.exit(1)
            except ProtocolError as reason:
                print_("XMLRPC-problem", reason)
                sys.exit(1)

        if len(data) == 0:
            self.warning("No runs found")
            return

        hostString = "Hostname"
        maxhost = len(hostString)
        cmdString = "Command Line"
        maxcommandline = len(cmdString)

        for name, info in iteritems(data):
            if len(info["commandLine"]) > maxcommandline:
                maxcommandline = len(info["commandLine"])
            if self.opts.ip:
                tmpHost = info["ip"]
            else:
                tmpHost = info["hostname"]
                if tmpHost == "no info":
                    tmpHost = info["ip"]
            if len(tmpHost) > maxhost:
                maxhost = len(tmpHost)

        header = hostString + (
            " " * (maxhost - len(hostString))
        ) + " | " + " Port  | User       | " + cmdString + "\n"
        line = ("-" * (len(header)))
        header += line

        formatString = "%-" + str(maxhost) + "s | %6d | %10s | %s"
        print_(header)

        for name, info in iteritems(data):
            if self.opts.user:
                if self.opts.user != info["user"]:
                    continue

            if self.opts.ip:
                tmpHost = info["ip"]
            else:
                tmpHost = info["hostname"]
                if tmpHost == "no info":
                    tmpHost = info["ip"]

            print_(formatString %
                   (tmpHost, info["port"], info["user"], info["commandLine"]))
            if self.parser.options.process:
                isParallel = self.forwardCommand(info, "isParallel()")
                if isParallel:
                    pidString = "CPUs: %5d" % self.forwardCommand(
                        info, "procNr()")
                else:
                    pidString = "PID: %6d" % info["pid"]
                print_("  %s   Working dir: %s" % (pidString, info["cwd"]))
            if self.parser.options.time:
                startTime = self.forwardCommand(info, "startTime()")
                endTime = self.forwardCommand(info, "endTime()")
                createTime = self.forwardCommand(info, "createTime()")
                nowTime = self.forwardCommand(info, "time()")
                try:
                    progress = (nowTime - createTime) / (endTime - createTime)
                except ZeroDivisionError:
                    progress = 0

                try:
                    progress2 = (nowTime - startTime) / (endTime - startTime)
                except ZeroDivisionError:
                    progress2 = 0

                print_(
                    "  Time: %g Timerange: [ %g , %g ]  Mesh created: %g -> Progress: %.2f%% (Total: %.2f%%)"
                    % (nowTime, startTime, endTime, createTime, progress * 100,
                       progress2 * 100))

                wallTime = self.forwardCommand(info, "wallTime()")
                now = time.time()
                start = now - wallTime
                startString = time.strftime("%Y-%b-%d %H:%M",
                                            time.localtime(start))
                try:
                    estimate = start + wallTime / progress
                    estimateString = time.strftime("%Y-%b-%d %H:%M",
                                                   time.localtime(estimate))
                except ZeroDivisionError:
                    estimate = start
                    estimateString = " - NaN - "

                print_("  Started: %s   Walltime: %8gs  Estimated End: %s" %
                       (startString, wallTime, estimateString))

            if self.opts.resources:
                mem = self.forwardCommand(info, "usedMemory()")
                loads = self.forwardCommand(info, "loadAvg()")
                loadString = ""
                if len(loads) == 3:
                    loadString = "  Load 1m: %.1f - 5m: %.1f - 15m: %.1f" % tuple(
                        loads)
                print(("   Max memory: %f MB" % mem) + loadString)
            if self.parser.options.process or self.parser.options.time:
                print_(line)
            if self.parser.options.dump:
                print_(info)
                print_(line)
def getPublicKey():
    from PyFoam.Infrastructure.Authentication import myPublicKeyText,ensureKeyPair
    ensureKeyPair()
    return myPublicKeyText()
    def run(self):
        from PyFoam.Infrastructure.Authentication import ensureKeyPair
        ensureKeyPair()

        host=self.parser.getArgs()[0]
        port=int(self.parser.getArgs()[1])

        cmd=self.parser.options.command

        try:
            self.server=getServerProxy(host,port)
            methods=self.server.system.listMethods()
            if not cmd:
                print_("Connected to server",host,"on port",port)
                print_(len(methods),"available methods found")
        except socket.error as reason:
            print_("Socket error while connecting:",reason)
            sys.exit(1)
        except ProtocolError as reason:
            print_("XMLRPC-problem",reason)
            sys.exit(1)

        if cmd:
            result=self.executeCommand(cmd)
            if result!=None:
                print_(result)
            sys.exit(0)

        while 1:
            try:
                if PY3:
                    line = input(self.prompt)
                else:
                    line = raw_input(self.prompt)
            except (KeyboardInterrupt,EOFError):    # Catch a ctrl-D
                print_()
                print_("Goodbye")
                sys.exit()
            line.strip()
            parts=line.split()

            if len(parts)==0:
                print_("For help type 'help'")
                continue

            if parts[0]=="help":
                if len(parts)==1:
                    print_("For help on a method type 'help <method>'")
                    print_("Available methods are:")
                    for m in methods:
                        print_("\t",m)
                elif len(parts)==2:
                    name=parts[1]
                    if name in methods:
                        signature=self.executeCommand("system.methodSignature(\""+name+"\")")
                        help=self.executeCommand("system.methodHelp(\""+name+"\")")
                        print_("Method    : ",name)
                        print_("Signature : ",signature)
                        print_(help)
                    else:
                        print_("Method",name,"does not exist")
                else:
                    print_("Too many arguments")
            else:
                result=self.executeCommand(line)
                if result!=None:
                    print_(result)
Exemplo n.º 5
0
def getAuthenticatedKeys():
    from PyFoam.Infrastructure.Authentication import authenticatedKeys, ensureKeyPair
    ensureKeyPair()
    return authenticatedKeys()
Exemplo n.º 6
0
def getPublicKey():
    from PyFoam.Infrastructure.Authentication import myPublicKeyText, ensureKeyPair
    ensureKeyPair()
    return myPublicKeyText()
    def run(self):
        from PyFoam.Infrastructure.Authentication import ensureKeyPair
        ensureKeyPair()

        if self.opts.zeroconf:
            data=getServerList(self.opts.timeout,
                               verbose=self.opts.debugZeroconf,
                               progress=self.opts.progressZeroconf)
        else:
            self.warning("Using the old method of querying the meta-server. This is deprecated")
            try:
                self.server=getServerProxy(self.parser.options.server,self.parser.options.port)
                data=self.server.list()
            except socket.error as reason:
                print_("Socket error while connecting:",reason)
                sys.exit(1)
            except ProtocolError as reason:
                print_("XMLRPC-problem",reason)
                sys.exit(1)

        if len(data)==0:
            self.warning("No runs found")
            return

        hostString="Hostname"
        maxhost=len(hostString)
        cmdString="Command Line"
        maxcommandline=len(cmdString)

        for name,info in iteritems(data):
            if len(info["commandLine"])>maxcommandline:
                maxcommandline=len(info["commandLine"])
            if self.opts.ip:
                tmpHost=info["ip"]
            else:
                tmpHost=info["hostname"]
                if tmpHost=="no info":
                    tmpHost=info["ip"]
            if len(tmpHost)>maxhost:
                maxhost=len(tmpHost)

        header=hostString+(" "*(maxhost-len(hostString)))+" | "+" Port  | User       | "+cmdString+"\n"
        line=("-"*(len(header)))
        header+=line

        formatString="%-"+str(maxhost)+"s | %6d | %10s | %s"
        print_(header)

        for name,info in iteritems(data):
            if self.opts.user:
                if self.opts.user!=info["user"]:
                    continue

            if self.opts.ip:
                tmpHost=info["ip"]
            else:
                tmpHost=info["hostname"]
                if tmpHost=="no info":
                    tmpHost=info["ip"]

            print_(formatString % (tmpHost,info["port"],info["user"],info["commandLine"]))
            if self.parser.options.process:
                isParallel=self.forwardCommand(info,"isParallel()")
                if isParallel:
                    pidString="CPUs: %5d" % self.forwardCommand(info,"procNr()")
                else:
                    pidString="PID: %6d" % info["pid"]
                print_("  %s   Working dir: %s" % (pidString,info["cwd"]))
            if self.parser.options.time:
                startTime=self.forwardCommand(info,"startTime()")
                endTime=self.forwardCommand(info,"endTime()")
                createTime=self.forwardCommand(info,"createTime()")
                nowTime=self.forwardCommand(info,"time()")
                try:
                    progress=(nowTime-createTime)/(endTime-createTime)
                except ZeroDivisionError:
                    progress=0

                try:
                    progress2=(nowTime-startTime)/(endTime-startTime)
                except ZeroDivisionError:
                    progress2=0

                print_("  Time: %g Timerange: [ %g , %g ]  Mesh created: %g -> Progress: %.2f%% (Total: %.2f%%)" % (nowTime,startTime,endTime,createTime,progress*100,progress2*100))

                wallTime=self.forwardCommand(info,"wallTime()")
                now=time.time()
                start=now-wallTime
                startString=time.strftime("%Y-%b-%d %H:%M",time.localtime(start))
                try:
                    estimate=start+wallTime/progress
                    estimateString=time.strftime("%Y-%b-%d %H:%M",time.localtime(estimate))
                except ZeroDivisionError:
                    estimate=start
                    estimateString=" - NaN - "

                print_("  Started: %s   Walltime: %8gs  Estimated End: %s" % (startString,wallTime,estimateString))

            if self.opts.resources:
                mem=self.forwardCommand(info,"usedMemory()")
                loads=self.forwardCommand(info,"loadAvg()")
                loadString=""
                try:
                    if len(loads)==3:
                        loadString="  Load 1m: %.1f - 5m: %.1f - 15m: %.1f" % tuple(loads)
                except TypeError:
                    loadString="  Load: "+str(loads)
                print(("   Max memory: %f MB" % mem)+loadString)
            if self.parser.options.process or self.parser.options.time:
                print_(line)
            if self.parser.options.dump:
                print_(info)
                print_(line)