cloudmesh-common


Namecloudmesh-common JSON
Version 5.0.62 PyPI version JSON
download
home_pageNone
SummaryA set of useful APIs for cloudmesh
upload_time2025-01-16 23:37:22
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseApache License Version 2.0, January 2004 http://www.apache.org/licenses/ Copyright 2017-2021 Gregor von Laszewski, Indiana University Copyright 2021,2022 Gregor von Laszewski, University of Virginia Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
keywords helper library cloudmesh
VCS
bugtrack_url
requirements python-dateutil humanize oyaml pyfiglet python-hostlist requests simplejson tabulate tqdm pyyaml psutil pywin32 pyuac tzlocal rich
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Cloudmesh Common


[![image](https://img.shields.io/pypi/v/cloudmesh-common.svg)](https://pypi.org/project/cloudmesh-common/)
[![Python](https://img.shields.io/pypi/pyversions/cloudmesh-common.svg)](https://pypi.python.org/pypi/cloudmesh-common)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/cloudmesh/cloudmesh-common/blob/main/LICENSE)
[![Format](https://img.shields.io/pypi/format/cloudmesh-common.svg)](https://pypi.python.org/pypi/cloudmesh-common)
[![Status](https://img.shields.io/pypi/status/cloudmesh-common.svg)](https://pypi.python.org/pypi/cloudmesh-common)
[![Travis](https://travis-ci.com/cloudmesh/cloudmesh-common.svg?branch=main)](https://travis-ci.com/cloudmesh/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

* [cloudmesh.common.console](https://github.com/cloudmesh/cloudmesh-common/blob/main/cloudmesh/common/console.py)

```python
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:

* [cloudmesh.common.Shell](https://github.com/cloudmesh/cloudmesh-common/blob/main/cloudmesh/common/Shell.py)


```python
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.

* [cloudmesh.common.Printer](https://github.com/cloudmesh/cloudmesh-common/blob/main/cloudmesh/common/Printer.py)

Let us assume we have 

```python
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 

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

Output:
```bash
+--------+------------------+------------+
| 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

```python
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.

``` python
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](https://github.com/cloudmesh/cloudmesh-common/blob/main/cloudmesh/common/StopWatch.py)


## dotdict


* [cloudmesh.common.dotdict](https://github.com/cloudmesh/cloudmesh-common/blob/main/cloudmesh/common/dotdict.py)

One dimensional Dictionaries in dot format. 

```python
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)

* [cloudmesh.common.ssh](https://github.com/cloudmesh/cloudmesh-common/blob/main/cloudmesh/common/ssh)

  * managing ssh config files
  * managing authorized keys

## util

Very useful functions are included in util


* [cloudmesh.common.util](https://github.com/cloudmesh/cloudmesh-common/blob/main/cloudmesh/common/util.py)

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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "cloudmesh-common",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Gregor von Laszewski <laszewski@gmail.com>",
    "keywords": "helper library, cloudmesh",
    "author": null,
    "author_email": "Gregor von Laszewski <laszewski@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/31/b3/08545050deeadd2d555809cf496e98d773264347c819128ebe1e613f2f16/cloudmesh_common-5.0.62.tar.gz",
    "platform": null,
    "description": "# Cloudmesh Common\r\n\r\n\r\n[![image](https://img.shields.io/pypi/v/cloudmesh-common.svg)](https://pypi.org/project/cloudmesh-common/)\r\n[![Python](https://img.shields.io/pypi/pyversions/cloudmesh-common.svg)](https://pypi.python.org/pypi/cloudmesh-common)\r\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/cloudmesh/cloudmesh-common/blob/main/LICENSE)\r\n[![Format](https://img.shields.io/pypi/format/cloudmesh-common.svg)](https://pypi.python.org/pypi/cloudmesh-common)\r\n[![Status](https://img.shields.io/pypi/status/cloudmesh-common.svg)](https://pypi.python.org/pypi/cloudmesh-common)\r\n[![Travis](https://travis-ci.com/cloudmesh/cloudmesh-common.svg?branch=main)](https://travis-ci.com/cloudmesh/cloudmesh-common)\r\n\r\n \r\n## Installation and Documentation\r\n\r\nPlease note that several packages are available which are pointed to in the\r\ninstallation documentation.\r\n\r\n|  | Links |\r\n|---------------|-------|\r\n| Documentation | <https://cloudmesh.github.io/cloudmesh-manual/autoapi/cloudmeshcommon/cloudmesh/index.html#module-cloudmesh-common.cloudmesh> |\r\n| Code | <https://github.com/cloudmesh/cloudmesh-common> |\r\n| Installation Instructions | <https://github.com/cloudmesh/get> |\r\n\r\n## Highlighted features\r\n\r\nThis library contains a number of useful functions and APIs that we highlight\r\nhere. They are used to interact with the system and provide a number of\r\nfunctions to implement command line programs and shells.\r\n\r\nThe intention of cloudmesh-common is to provide convenience to the user\r\nwith even simpler Python functions than those built-in, giving\r\nricher output messages, more concise file operations, and other\r\ngoodies.\r\n\r\n## Console\r\n\r\nThe console provides convenient way to print colored messages types in the\r\nterminal, such as errors, info, and regular messages\r\n\r\n* [cloudmesh.common.console](https://github.com/cloudmesh/cloudmesh-common/blob/main/cloudmesh/common/console.py)\r\n\r\n```python\r\nfrom cloudmesh.common.console import Console\r\n\r\nConsole.error(\"this is an error printed in red with prefix ERROR:\")\r\nConsole.msg(\"this is a msg printed in black\")\r\nConsole.ok(\"this is an ok message printed in green\")\r\n``` \r\n\r\n## Shell\r\n\r\nWe have lots of shell commands that call linux commands, but also have a\r\nconvenient execution command that returns the results in a string.\r\n\r\nShell functions such as `run` tend to work cross-platform (including\r\nWindows), but it is up to the user to ensure that commands and software\r\nare available on the system beforehand.\r\n\r\nFor more information we like you to inspect the source code:\r\n\r\n* [cloudmesh.common.Shell](https://github.com/cloudmesh/cloudmesh-common/blob/main/cloudmesh/common/Shell.py)\r\n\r\n\r\n```python\r\nfrom cloudmesh.common.Shell import Shell\r\n\r\nshell = Shell()\r\n\r\nprint(shell.terminal_type())\r\n\r\n# prints after the command is finished\r\nr = shell.execute('pwd') \r\nprint(r)\r\n\r\n# prints while the command is executed\r\nr = shell.live('pwd') \r\nprint(r)\r\n\r\n# open a new terminal and start the command ls in it (for OSX and Gnome)\r\nshell.terminal(\"ls\")\r\n\r\n# an example of a build in command\r\nshell.pip(\"install cloudmesh-common\")\r\n```\r\n \r\nWe have many such build in commands, please see the source\r\n\r\n    \r\n## Printer\r\n\r\nA convenient way to print dictionaries and lists with repeated\r\nentries as tables, csv, json, yaml. The dictionaries can even be hierarchical.\r\n\r\n* [cloudmesh.common.Printer](https://github.com/cloudmesh/cloudmesh-common/blob/main/cloudmesh/common/Printer.py)\r\n\r\nLet us assume we have \r\n\r\n```python\r\nfrom cloudmesh.common.Printer import Printer\r\n\r\ndata = [\r\n    {\r\n        \"name\": \"Gregor\",\r\n        \"address\": {\r\n            \"street\": \"Funny Lane 11\",\r\n            \"city\": \"Cloudville\"\r\n        }\r\n    },\r\n    {\r\n        \"name\": \"Albert\",\r\n        \"address\": {\r\n            \"street\": \"Memory Lane 1901\",\r\n            \"city\": \"Cloudnine\"\r\n        }\r\n    }\r\n]\r\n```\r\n\r\nThen we can print it nicely with \r\n\r\n```python\r\nprint(Printer.flatwrite(data,\r\n                    sort_keys=[\"name\"],\r\n                    order=[\"name\", \"address.street\", \"address.city\"],\r\n                    header=[\"Name\", \"Street\", \"City\"],\r\n                    output=\"table\")\r\n          )\r\n```\r\n\r\nOutput:\r\n```bash\r\n+--------+------------------+------------+\r\n| Name   | Street           | City       |\r\n+--------+------------------+------------+\r\n| Gregor | Funny Lane 11    | Cloudville |\r\n| Albert | Memory Lane 1901 | Cloudnine  |\r\n+--------+------------------+------------+\r\n```\r\n\r\nOther formats such as csv, json, dict are also supported.\r\n\r\nIn addition we have also printers for printing attribute lists. Please consult\r\nthe source code.\r\n\r\n## StopWatch\r\n\r\nStopWatch is meant for benchmarking program runtimes, including \r\ncustom user-set sections of such programs.\r\n\r\nSee: https://colab.research.google.com/drive/1tG7IcP-XMQiNVxU05yazKQYciQ9GpMat#scrollTo=TZAjATZiQh4q&uniqifier=1 for an example\r\n\r\n### Using Cloudmesh StopWatch Inline\r\n\r\n```python\r\nfrom cloudmesh.common.StopWatch import StopWatch\r\nimport time\r\n\r\nStopWatch.start(\"a\")\r\ntime.sleep(3)\r\nStopWatch.stop(\"a\")\r\nStopWatch.status(\"a\", True)\r\nStopWatch.benchmark()\r\n```\r\n\r\n### Using Cloudmesh Benchmark wrapped in Functions\r\n\r\nIf it is not wrapped in functions, do not use it this way.\r\n\r\n``` python\r\nfrom cloudmesh.common.Benchmark import Benchmark\r\nimport time\r\n  \r\ndef b():\r\n  Benchmark.Start()\r\n  time.sleep(3)\r\n  Benchmark.Stop()\r\n\r\ndef c():\r\n  Benchmark.Start()\r\n  time.sleep(1)\r\n  Benchmark.Stop()\r\n\r\n b()\r\n c()\r\n\r\nBenchmark.print()\r\n```\r\n\r\n* See also: [cloudmesh.common.StopWatch](https://github.com/cloudmesh/cloudmesh-common/blob/main/cloudmesh/common/StopWatch.py)\r\n\r\n\r\n## dotdict\r\n\r\n\r\n* [cloudmesh.common.dotdict](https://github.com/cloudmesh/cloudmesh-common/blob/main/cloudmesh/common/dotdict.py)\r\n\r\nOne dimensional Dictionaries in dot format. \r\n\r\n```python\r\nfrom cloudmesh.common.dotdict import dotdict\r\n\r\n# convert a simple dict to a dotdict\r\nd = dotdict({\"name\": \"Gregor\"})\r\n# Now you can say\r\nprint(d[\"name\"])\r\nprint(d.name)\r\n```\r\n\r\n## ssh\r\n\r\nAllows for a robust configuration of secure-shell (remote access to hosts)\r\n\r\n* [cloudmesh.common.ssh](https://github.com/cloudmesh/cloudmesh-common/blob/main/cloudmesh/common/ssh)\r\n\r\n  * managing ssh config files\r\n  * managing authorized keys\r\n\r\n## util\r\n\r\nVery useful functions are included in util\r\n\r\n\r\n* [cloudmesh.common.util](https://github.com/cloudmesh/cloudmesh-common/blob/main/cloudmesh/common/util.py)\r\n\r\nEspecially useful are\r\n\r\n  * `generate_password` \r\n    * generates a random password from letters and numbers\r\n  * `banner` and `str_banner`\r\n    * outputs a prominent message in the console for debugging and cohesiveness\r\n  * `yn_choice`\r\n    * to ask the user \"yes\" or \"no\" and account for various answers like \"Y\"\r\n  * `path_expand`\r\n    * to automatically replace path symbols such as `~` with the home dir\r\n    * works cross-platform across OS's\r\n  * `grep`\r\n    * simple line matching but as a python method\r\n  * `HEADING`\r\n    * which, without parameter, identifies the name of the function and \r\n  prints its name within a banner\r\n\r\n## Changes\r\n\r\n* added support for terminals with dark background\r\n\r\n## Acknowledgments\r\n\r\nContinued work was in part funded by the NSF\r\nCyberTraining: CIC: CyberTraining for Students and Technologies\r\nfrom Generation Z with the award numbers 1829704 and 2200409.\r\n",
    "bugtrack_url": null,
    "license": "Apache License Version 2.0, January 2004 http://www.apache.org/licenses/  Copyright 2017-2021 Gregor von Laszewski, Indiana University Copyright 2021,2022 Gregor von Laszewski, University of Virginia  Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ",
    "summary": "A set of useful APIs for cloudmesh",
    "version": "5.0.62",
    "project_urls": {
        "Changelog": "https://github.com/cloudmesh/cloudmesh-common/blob/main/CHANGELOG.md",
        "Documentation": "https://github.com/cloudmesh/cloudmesh-common/blob/main/README.md",
        "Homepage": "https://github.com/cloudmesh/cloudmesh-common",
        "Issues": "https://github.com/cloudmesh/cloudmesh-common/issues",
        "Repository": "https://github.com/cloudmesh/cloudmesh-common.git"
    },
    "split_keywords": [
        "helper library",
        " cloudmesh"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9b66085e322027a03ed59a3448379096970adaefa916cf2df44465f5fae2328c",
                "md5": "59b7a18e9c2f6aa5b02556a24a125412",
                "sha256": "ef1790a96df52169bbc445d87074327ea41a08300ee6fbedd4076a298ce88241"
            },
            "downloads": -1,
            "filename": "cloudmesh_common-5.0.62-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "59b7a18e9c2f6aa5b02556a24a125412",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.8",
            "size": 113140,
            "upload_time": "2025-01-16T23:37:19",
            "upload_time_iso_8601": "2025-01-16T23:37:19.375037Z",
            "url": "https://files.pythonhosted.org/packages/9b/66/085e322027a03ed59a3448379096970adaefa916cf2df44465f5fae2328c/cloudmesh_common-5.0.62-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "31b308545050deeadd2d555809cf496e98d773264347c819128ebe1e613f2f16",
                "md5": "218ca16bab5147e22663d4b6ed416b7f",
                "sha256": "ebf09f3ef788d2bb59db8b8f4cea1d130cfeb33bf8d722e53b47bb8e099a1cc2"
            },
            "downloads": -1,
            "filename": "cloudmesh_common-5.0.62.tar.gz",
            "has_sig": false,
            "md5_digest": "218ca16bab5147e22663d4b6ed416b7f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 114075,
            "upload_time": "2025-01-16T23:37:22",
            "upload_time_iso_8601": "2025-01-16T23:37:22.341682Z",
            "url": "https://files.pythonhosted.org/packages/31/b3/08545050deeadd2d555809cf496e98d773264347c819128ebe1e613f2f16/cloudmesh_common-5.0.62.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-16 23:37:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cloudmesh",
    "github_project": "cloudmesh-common",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "python-dateutil",
            "specs": []
        },
        {
            "name": "humanize",
            "specs": []
        },
        {
            "name": "oyaml",
            "specs": []
        },
        {
            "name": "pyfiglet",
            "specs": []
        },
        {
            "name": "python-hostlist",
            "specs": []
        },
        {
            "name": "requests",
            "specs": []
        },
        {
            "name": "simplejson",
            "specs": []
        },
        {
            "name": "tabulate",
            "specs": []
        },
        {
            "name": "tqdm",
            "specs": []
        },
        {
            "name": "pyyaml",
            "specs": []
        },
        {
            "name": "psutil",
            "specs": []
        },
        {
            "name": "pywin32",
            "specs": []
        },
        {
            "name": "pyuac",
            "specs": []
        },
        {
            "name": "tzlocal",
            "specs": []
        },
        {
            "name": "rich",
            "specs": []
        }
    ],
    "tox": true,
    "lcname": "cloudmesh-common"
}
        
Elapsed time: 0.65912s