cloudmesh-common 5.0.62
pip install cloudmesh-common
Released:
A set of useful APIs for cloudmesh
Navigation
Unverified details
These details have not been verified by PyPIProject links
Meta
- License: Apache Software License (Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ Copyright 2017-2021 Gregor...)
- Author: Gregor von Laszewski
- Maintainer: Gregor von Laszewski
- Tags helper library, cloudmesh
- Requires: Python >=3.8
Classifiers
- Development Status
- Environment
- Intended Audience
- License
- Natural Language
- Operating System
- Programming Language
- Topic
Project description
Cloudmesh Common
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()
- See also: cloudmesh.common.StopWatch
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)
-
- managing ssh config files
- managing authorized keys
util
Very useful functions are included in util
Especially useful are
generate_password
- generates a random password from letters and numbers
banner
andstr_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
- to automatically replace path symbols such as
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.
Project details
Unverified details
These details have not been verified by PyPIProject links
Meta
- License: Apache Software License (Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ Copyright 2017-2021 Gregor...)
- Author: Gregor von Laszewski
- Maintainer: Gregor von Laszewski
- Tags helper library, cloudmesh
- Requires: Python >=3.8
Classifiers
- Development Status
- Environment
- Intended Audience
- License
- Natural Language
- Operating System
- Programming Language
- Topic
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cloudmesh_common-5.0.62.tar.gz
.
File metadata
- Download URL: cloudmesh_common-5.0.62.tar.gz
- Upload date:
- Size: 114.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebf09f3ef788d2bb59db8b8f4cea1d130cfeb33bf8d722e53b47bb8e099a1cc2 |
|
MD5 | 218ca16bab5147e22663d4b6ed416b7f |
|
BLAKE2b-256 | 31b308545050deeadd2d555809cf496e98d773264347c819128ebe1e613f2f16 |
File details
Details for the file cloudmesh_common-5.0.62-py2.py3-none-any.whl
.
File metadata
- Download URL: cloudmesh_common-5.0.62-py2.py3-none-any.whl
- Upload date:
- Size: 113.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef1790a96df52169bbc445d87074327ea41a08300ee6fbedd4076a298ce88241 |
|
MD5 | 59b7a18e9c2f6aa5b02556a24a125412 |
|
BLAKE2b-256 | 9b66085e322027a03ed59a3448379096970adaefa916cf2df44465f5fae2328c |