Package: cloudmesh-common
Cloudmesh CommonInstallation and DocumentationPlease note that several packages are available which are pointed to in the
installation documentation.LinksDocumentationhttps://cloudmesh.github.io/cloudmesh-cloudCodehttps://github.com/cloudmesh/cloudmesh-cloudInstallation Instructionshttps://github.com/cloudmesh/getHighlighted featuresThis library contains a number of useful functions and APIs that we highlight
here. They are used to interact with the system and provide a number of
functions to implement command line programs and shells.ConsoleThe console provides convenient way to print colored messages types in the
terminal, such as errors, info, and regular messagescloudmesh.common.consolefromcloudmesh.common.consoleimportConsoleConsole.error("this is an error printed in red with prefix ERROR:")Console.msg("this is a msg printed in black")Console.ok("this is an ok message printed in green")ShellWe have lots of shell commands that call linux commands, but also have a
convenient execution command that returns the results in a string.For more information we like you to inspect the source code:cloudmesh.common.Shellfromcloudmesh.common.ShellimportShellshell=Shell()print(shell.terminal_type())# prints after the command is finishedr=shell.execute('pwd')print(r)# prints while the command is executedr=shell.live('pwd')print(r)# open a new terminal and start the command ls in it (for OSX and Gnome)shell.terminal("ls")# an example of a build in commandshell.pip("install cloudmesh-common")We have many such build in commands, please see the sourcePrinterA convenient way to print dictionaries and lists with repeated
entries as tables, csv, json, yaml. The dictionaries can even be hierarchical.cloudmesh.common.PrinterLet us assume we havedata=[{"name":"Gregor","address":{"street":"Funny Lane 11","city":"Cloudville"{},{"name":"Albert","address":{"street":"Memory Lane 1901","city":"Cloudnine"}}]Then we can print it nicely withprint(Printer.flatwrite(self.data,sort_keys=["name"],order=["name","address.street","address.city"],header=["Name","Street","City"],output="table"))Other formats such as csv, json, dict are also supported.In addition we have also printers for printing attribute lists. Please consult
the source code.StopWatchSee:https://colab.research.google.com/drive/1tG7IcP-XMQiNVxU05yazKQYciQ9GpMat#scrollTo=TZAjATZiQh4q&uniqifier=1for an exampleUsing Cloudmesh StopWatch Inlinefromcloudmesh.common.StopWatchimportStopWatchimporttimeStopWatch.start("a")time.sleep(3)StopWatch.stop("a")StopWatch.status("a",True)StopWatch.benchmark()Using Cloudmesh Benchmark wrapped in FunctionsIf it is not wrapped in functions, do not use it this way.fromcloudmesh.common.BenchmarkimportBenchmarkimporttimedefb():Benchmark.Start()time.sleep(3)Benchmark.Stop()defc():Benchmark.Start()time.sleep(1)Benchmark.Stop()b()c()Benchmark.print()See also:cloudmesh.common.StopWatchdotdictcloudmesh.common.dotdictOne dimensional Dictionaries in dot format.fromcloudmesh.common.dotdictimportdoctict# convert a simple dict to a dotdictd=dotdict({"name":"Gregor"})# Now you can sayprint(d["name"])print(d.name)sshcloudmesh.common.sshmanaging ssh config filesmanaging authorized keysutilVery useful functions are included in utilcloudmesh.common.utilEspecially useful aregenerating passwordsbannersyn_choicespath_expansiongrep (simple line matching)HEADING() which without parameter identifies the name of the function and
prints its name within a bannerChangesadded support for terminals with dark backgroundAcknowledgmentsContinued work was in part funded by the NSF
CyberTraining: CIC: CyberTraining for Students and Technologies
from Generation Z with the award numbers 1829704 and 2200409.