Skip to main content

Cloudmesh Common

image Python License Format Status Travis

Installation and Documentation

Please note that several packages are available which are pointed to in the installation documentation.

Links
Documentation https://cloudmesh.github.io/cloudmesh-manual/autoapi/cloudmeshcommon/cloudmesh/index.html#module-cloudmesh-common.cloudmesh
Code https://github.com/cloudmesh/cloudmesh-common
Installation Instructions https://github.com/cloudmesh/get

Highlighted features

This 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.

The intention of cloudmesh-common is to provide convenience to the user with even simpler Python functions than those built-in, giving richer output messages, more concise file operations, and other goodies.

Console

The console provides convenient way to print colored messages types in the terminal, such as errors, info, and regular messages

from cloudmesh.common.console import Console

Console.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")

Shell

We have lots of shell commands that call linux commands, but also have a convenient execution command that returns the results in a string.

Shell functions such as run tend to work cross-platform (including Windows), but it is up to the user to ensure that commands and software are available on the system beforehand.

For more information we like you to inspect the source code:

from cloudmesh.common.Shell import Shell

shell = Shell()

print(shell.terminal_type())

# prints after the command is finished
r = shell.execute('pwd') 
print(r)

# prints while the command is executed
r = 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 command
shell.pip("install cloudmesh-common")

We have many such build in commands, please see the source

Printer

A convenient way to print dictionaries and lists with repeated entries as tables, csv, json, yaml. The dictionaries can even be hierarchical.

Let us assume we have

from cloudmesh.common.Printer import Printer

data = [
    {
        "name": "Gregor",
        "address": {
            "street": "Funny Lane 11",
            "city": "Cloudville"
        }
    },
    {
        "name": "Albert",
        "address": {
            "street": "Memory Lane 1901",
            "city": "Cloudnine"
        }
    }
]

Then we can print it nicely with

print(Printer.flatwrite(data,
                    sort_keys=["name"],
                    order=["name", "address.street", "address.city"],
                    header=["Name", "Street", "City"],
                    output="table")
          )

Output:

+--------+------------------+------------+
| Name   | Street           | City       |
+--------+------------------+------------+
| Gregor | Funny Lane 11    | Cloudville |
| Albert | Memory Lane 1901 | Cloudnine  |
+--------+------------------+------------+

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.

StopWatch

StopWatch is meant for benchmarking program runtimes, including custom user-set sections of such programs.

See: https://colab.research.google.com/drive/1tG7IcP-XMQiNVxU05yazKQYciQ9GpMat#scrollTo=TZAjATZiQh4q&uniqifier=1 for an example

Using Cloudmesh StopWatch Inline

from cloudmesh.common.StopWatch import StopWatch
import time

StopWatch.start("a")
time.sleep(3)
StopWatch.stop("a")
StopWatch.status("a", True)
StopWatch.benchmark()

Using Cloudmesh Benchmark wrapped in Functions

If it is not wrapped in functions, do not use it this way.

from cloudmesh.common.Benchmark import Benchmark
import time
  
def b():
  Benchmark.Start()
  time.sleep(3)
  Benchmark.Stop()

def c():
  Benchmark.Start()
  time.sleep(1)
  Benchmark.Stop()

 b()
 c()

Benchmark.print()

dotdict

One dimensional Dictionaries in dot format.

from cloudmesh.common.dotdict import dotdict

# convert a simple dict to a dotdict
d = dotdict({"name": "Gregor"})
# Now you can say
print(d["name"])
print(d.name)

ssh

Allows for a robust configuration of secure-shell (remote access to hosts)

util

Very useful functions are included in util

Especially useful are

  • generate_password
    • generates a random password from letters and numbers
  • banner and str_banner
    • outputs a prominent message in the console for debugging and cohesiveness
  • yn_choice
    • to ask the user "yes" or "no" and account for various answers like "Y"
  • path_expand
    • to automatically replace path symbols such as ~ with the home dir
    • works cross-platform across OS's
  • grep
    • simple line matching but as a python method
  • HEADING
    • which, without parameter, identifies the name of the function and prints its name within a banner

Changes

  • added support for terminals with dark background

Acknowledgments

Continued 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.

Release files for cloudmesh-common 5.0.64

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cloudmesh-common 5.0.64
File Size Uploaded
cloudmesh_common-5.0.64.tar.gz 115.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cloudmesh-common 5.0.64
File Interpreter ABI Platform
cloudmesh_common-5.0.64-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 228.9 kB

Release files / cloudmesh_common-5.0.64.tar.gz

Download URL cloudmesh_common-5.0.64.tar.gz
Size 115.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7f0e551843f4d6b25b5c30e5706fdca4403384e1bb51b30065242dc5b2f673f3
BLAKE2b-256 checksum
How to use checksums
8ebdf5906ffcab049affb99616e9f5e87b44741492cc99fa8bde553bf1bf112a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Release files / cloudmesh_common-5.0.64-py2.py3-none-any.whl

Download URL cloudmesh_common-5.0.64-py2.py3-none-any.whl
Size 113.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
eef061d81a202f2a76f6e0ade200f1cbff6fd51a05269f2b5b9c699cf67b3230
BLAKE2b-256 checksum
How to use checksums
ac8c2f017e5e1ea7afbc5db33b05047c106c426dda3c6f4fb87e9d6a2017c483
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Release history Release notifications | RSS feed

This release

5.0.64 This release

2 release files

5.0.63

2 release files

5.0.62

2 release files

5.0.61

2 release files

5.0.60

2 release files

5.0.59

2 release files

5.0.58

2 release files

5.0.56

2 release files

5.0.55

2 release files

5.0.51

2 release files

5.0.50

2 release files

5.0.49

2 release files

5.0.48

2 release files

5.0.47

2 release files

5.0.46

2 release files

5.0.44

2 release files

5.0.41

2 release files

5.0.26

2 release files

4.4.1

2 release files

4.3.143

1 release file

4.3.99

2 release files

4.3.98

2 release files

4.3.97

2 release files

4.3.93

2 release files

4.3.92

2 release files

4.3.91

2 release files

4.3.90

2 release files

4.3.89

2 release files

4.3.88

2 release files

4.3.87

2 release files

4.3.86

2 release files

4.3.85

2 release files

4.3.83

2 release files

4.3.80

2 release files

4.3.79

2 release files

4.3.78

2 release files

4.3.77

2 release files

4.3.76

2 release files

4.3.75

2 release files

4.3.74

2 release files

4.3.73

2 release files

4.3.72

2 release files

4.3.71

2 release files

4.3.70

2 release files

4.3.69

2 release files

4.3.67

2 release files

4.3.60

2 release files

4.3.59

2 release files

4.3.58

2 release files

4.3.52

2 release files

4.3.51

2 release files

4.3.50

2 release files

4.3.49

2 release files

4.3.48

2 release files

4.3.47

2 release files

4.3.46

2 release files

4.3.45

2 release files

4.3.43

2 release files

4.3.42

2 release files

4.3.31

2 release files

4.3.26

2 release files

4.3.25

2 release files

4.3.23

2 release files

4.3.22

2 release files

4.3.18

2 release files

4.3.17

2 release files

4.3.16

2 release files

4.3.14

2 release files

4.3.12

2 release files

4.3.8

2 release files

4.3.6

2 release files

4.3.4

2 release files

4.3.2

2 release files

4.2.59

2 release files

4.2.58

2 release files

4.2.57

2 release files

4.2.56

2 release files

4.2.48

2 release files

4.2.47

2 release files

4.2.46

2 release files

4.2.45

2 release files

4.2.44

2 release files

4.2.43

2 release files

4.2.42

2 release files

4.2.41

2 release files

4.2.40

2 release files

4.2.39

2 release files

4.2.37

2 release files

4.2.33

2 release files

4.2.32

2 release files

4.2.31

2 release files

4.2.29

2 release files

4.2.28

2 release files

4.2.27

2 release files

4.2.26

2 release files

4.2.25

2 release files

4.2.24

2 release files

4.2.23

2 release files

4.2.22

2 release files

4.2.21

2 release files

4.2.17

2 release files

4.2.14

2 release files

4.2.13

2 release files

4.2.12

2 release files

4.2.11

2 release files

4.2.9

2 release files

4.2.8

2 release files

4.1.29

2 release files

4.1.20

2 release files

4.1.18

2 release files

4.1.10

2 release files

4.1.2

2 release files

4.1.1

2 release files

4.0.49

2 release files

4.0.47

2 release files

4.0.44

2 release files

1.5.3

2 release files

1.5.0

2 release files

1.4.22

2 release files

1.4.10

2 release files

1.4.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page