{ "info": { "author": "Robpol86", "author_email": "robpol86@robpol86.com", "bugtrack_url": null, "classifiers": [], "description": "========\nrobutils\n========\n\nrobutils is a Python module that provides a handful of convenient classes mainly for command line applications, but\nwill work in any Python script. It is designed for **Python 2.7.3** on **Linux** systems, and may work on OS X and\nother Unix-based systems. robutils may also work on other platforms and Python versions but this is not supported.\n\nSome of the features of robutils are:\n\n* Wrapper for executing external commands over SSH (paramiko) or locally (subprocess) with timeouts.\n* Enforce single instances using locking PID files.\n* Color text on Bash terminals, demonizing the main process, console redirects (for Altiris), logging, and email.\n* Centralizing exit messages for different exit codes. Also useful for Altiris.\n* Progress bar with ETA.\n\nInstallation\n============\n\nThe following Python packages are required as prerequisites:\n\n* `psutil `_ >= 0.6.1\n* `paramiko `_ >= 1.9.0\n* `pandas `_ >= 0.9.1\n\nTo install run one of the following commands::\n\n pip install robutils\n easy_install robutils\n git clone https://github.com/Robpol86/robutils.git; cp -r robutils/robutils /usr/lib/python2.7/site-packages/\n\nOnce installed, additional documentation is available within docstrings::\n\n >>> import robutils; help(robutils)\n\nQuick links\n===========\n\n* `Home page `_\n* `Download `_\n\nExamples\n========\n\n|kjVlbuk|_\n\n.. |kjVlbuk| image:: http://i.imgur.com/kjVlbukm.png\n.. _kjVlbuk: http://i.imgur.com/kjVlbuk.png\n\n|pPI3ePX|_\n\n.. |pPI3ePX| image:: http://i.imgur.com/pPI3ePXm.png\n.. _pPI3ePX: http://i.imgur.com/pPI3ePX.png\n\n|Avdq73Y|_\n\n.. |Avdq73Y| image:: http://i.imgur.com/Avdq73Ym.png\n.. _Avdq73Y: http://i.imgur.com/Avdq73Y.png\n\n|du2IWZ6|_\n\n.. |du2IWZ6| image:: http://i.imgur.com/du2IWZ6m.png\n.. _du2IWZ6: http://i.imgur.com/du2IWZ6.png\n\n|uOQVrxB|_\n\n.. |uOQVrxB| image:: http://i.imgur.com/uOQVrxBm.png\n.. _uOQVrxB: http://i.imgur.com/uOQVrxB.png\n\nMessage\n-------\n\n1. Easy to use color syntax for Linux Bash terminals (.term() hides the class instance from the interactive console)::\n\n >>> from robutils.Message import Message\n >>> message = Message()\n >>> message('Sample text.')\n Sample text.\n \n >>> message('Colors: [red]red[/red] and [hiblue]multi[hired]colored[bgyellow]text[/all].').term()\n Colors: red and multicoloredtext.\n >>>\n\n2. Print messages to stdout, stderr, and/or log to file (with colors)::\n\n >>> from robutils.Message import Message\n >>> message = Message(log_file='/tmp/test.log', log_level='error')\n >>> message('Regular stdout non-logged text.').term()\n Regular stdout non-logged text.\n >>> message('stderr non-logged text.', stderr=True).term()\n stderr non-logged text.\n >>> message('stdout and logged as info.').log().term()\n stdout and logged as info.\n >>> message('[red]only logged as error[/all].', quiet=True).log('error').term()\n >>> message('stdout, but not logged since debug < error').log('debug').term()\n stdout, but not logged since debug < error\n >>>\n\n3. Centralize messages for different exit codes. Also supports terminating the script with different exit codes::\n\n [testuser@localhost ~]$ ~/python27/bin/python\n Python 2.7.3 (default, Nov 24 2012, 23:17:40)\n [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2\n Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n >>> from robutils.Message import Message\n >>> message = Message()\n >>> message.retcodes[1] = 'An error occurred.'\n >>> message.retcodes[5] = 'Error doing x, check file y.'\n >>> message.retcodes[6] = 'Error doing a, check file b.'\n >>> message.quit(5)\n \n \n QUITTING: Error doing x, check file y.\n [testuser@localhost ~]$\n\n4. Send email via SMTP or local sendmail. Supports a tail of the log and/or file attachments::\n\n >>> from robutils.Message import Message\n >>> message = Message(mail_smtp='smtp-server.austin.rr.com',\n ... mail_from='test@gmail.com',\n ... mail_to='robpol86@robpol86.com')\n >>> message.mail('Test Email', body='This is a test email.').term()\n >>>\n\n5. Demonize scripts and/or redirect stdout/stderr to a file (useful for Altiris scripts)::\n\n from robutils.Message import Message\n message = Message(daemon=True, redirect='/tmp/redir.txt')\n message(\"[hiblue]This is a test[/all]\")\n message.retcodes[1] = 'Exiting sample script.'\n message.quit(1)\n\nExternalCmd\n-----------\n\n1. Run external commands on the local machine::\n\n >>> from robutils.ExternalCmd import ExternalCmd\n >>> cmd = ExternalCmd('echo \"test1\\ntest2\\ntest3\\n\" | grep test2')\n >>> cmd.run_local()\n >>> cmd.stdout\n 'test2\\n'\n >>> cmd.code\n 0\n >>> cmd = ExternalCmd('echo test1 && echo test2')\n >>> cmd.run_local()\n >>> cmd.stdout\n 'test1\\ntest2\\n'\n >>> cmd = ExternalCmd(['ls', '-lahd', '/tmp'])\n >>> cmd.run_local()\n >>> cmd.stdout\n 'drwxrwxrwt 4 root root 32K Nov 20 04:02 /tmp\\n'\n >>> \n\n2. Run external commands on a remote host using SSH::\n\n >>> from robutils.ExternalCmd import ExternalCmd\n >>> cmd = ExternalCmd('echo first && sleep 10 && echo done')\n >>> cmd.run_remote('localhost')\n >>> (cmd.code, cmd.stdout)\n (None, '')\n >>> time.sleep(10)\n >>> (cmd.code, cmd.stdout)\n (0, 'first\\ndone\\n')\n >>> \n\nProgress\n--------\n\n1. Create a progress bar and manually display the summary periodically::\n\n >>> from robutils.Progress import Progress\n >>> from robutils.Message import Message\n >>> message = Message()\n >>> progress = Progress(43)\n >>> while progress.total_percent < 80:\n ... time.sleep(1)\n ... progress.inc_pass() if random.randint(1, 5) < 5 else progress.inc_fail()\n >>> message(progress.summary())\n 81% (35/43) [######################## ] eta 0:00:06 - 14% ( 5/35) failed\n >>> message(progress.summary(hide_failed=True))\n 81% (35/43) [####################################### ] eta 0:00:03 \\\n >>> message(progress.summary(max_width=70))\n 81% (35/43) [################ ] eta 0:00:01 | 14% ( 5/35) failed\n >>> message(progress.summary(hide_failed=True, eta_countdown=False))\n 81% (35/43) [################################# ] eta 11:45:30 PM CST /\n >>> while progress.total_percent < 100: progress.inc_pass()\n >>> message(progress.summary())\n 100% (43/43) [##############################] eta 0:00:00 - 11% ( 5/43) failed\n >>> \n\n2. Have the progress bar print periodically in the provided threaded method::\n\n >>> from robutils.Progress import Progress\n >>> from robutils.Message import Message\n >>> message = Message()\n >>> progress = Progress(43)\n >>> progress.threaded_summary(message, hide_failed=True)\n >>> while progress.total_percent < 100:\n ... time.sleep(1)\n ... progress.inc_pass() if random.randint(1, 5) < 5 else progress.inc_fail()\n >>> print\n 100% (43/43) [#################################################] eta 0:00:00 /\n\nInstance\n--------\n::\n\n >>> from robutils import Instance\n >>> instance = Instance('/var/tmp/example_script.pid')\n >>> if not instance.single_instance_success:\n ... if instance.old_pid_exists: print 'Another instance is running.'\n ... if not instance.pdir_exists: print \"PID file parent dir doesn't exist.\"\n ... if not instance.can_write: print 'No write permissions.'\n\n\nSupplemental Installation Steps\n===============================\n\nThis section details how I setup my custom Python environment, which includes packages unrelated to robutils.\n\nCentOS 6.3\n----------\n\nRun this as a non-root user::\n\n sudo yum install gcc gcc-c++ autoconf automake make\n sudo yum install sqlite-devel bzip2-devel tk-devel readline-devel ncurses-devel openssl-devel gdbm-devel\n sudo yum install libxslt-devel atlas-devel gcc-gfortran\n mkdir -p Python27_Build/python27 && cd Python27_Build\n curl http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2 |tar --strip-components=1 -xj\n vim Modules/_sqlite/connection.c # CentOS, http://bugs.python.org/issue14572\n ./configure --prefix=\"$(pwd)/python27\" && make clean && make\n make install\n wget \"http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg\"\n (export PATH=/bin:/usr/bin:$(pwd)/python27/bin; sh setuptools-0.6c11-py2.7.egg)\n ./python27/bin/easy_install pip\n ./python27/bin/pip install nose docutils distribute NumPy\n ./python27/bin/pip install SciPy pandas\n ./python27/bin/pip install pytz lxml psutil paramiko mutagen winpdb robutils\n find ./python27 \\( -name '*.pyc' -o -name '*.pyo' \\) -exec rm {} \\;\n find ./python27 -name *egg-info* -exec rm -r {} \\;\n tar -czf python27-$(date +%Y%m%d).tar.gz python27\n\nWindows 7/8\n-----------\n\nThis is out of scope for this project since Windows is not supported, but I left it here for future reference::\n\n rem Root: %localappdata%\\python27\n rem http://www.enthought.com/products/epd_free.php (includes Python)\n rem http://www.wxpython.org/download.php#binaries\n easy_install pip pytz pygments\n easy_install http://pypi.python.org/packages/source/p/python-dateutil/python-dateutil-1.5.tar.gz\n pip install winpdb\n rem http://pypi.python.org/pypi/pandas\n ipython notebook --pylab=inline", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://code.google.com/p/robutils/", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "robutils", "package_url": "https://pypi.org/project/robutils/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/robutils/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://code.google.com/p/robutils/" }, "release_url": "https://pypi.org/project/robutils/1.0.1/", "requires_dist": null, "requires_python": null, "summary": "Convenience classes for CLI Python applications.", "version": "1.0.1" }, "last_serial": 799007, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "f7fe3442584e5c20d8de0bc61d44d423", "sha256": "cc96d263ad37a4ebd034901b8327361a6ceb33e685aaafd4e98faddb1334bcd5" }, "downloads": -1, "filename": "robutils-1.0.0.tar.gz", "has_sig": false, "md5_digest": "f7fe3442584e5c20d8de0bc61d44d423", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23747, "upload_time": "2012-12-02T07:46:58", "url": "https://files.pythonhosted.org/packages/d0/3d/172a43d760778f86c24e9ab8538049c27d20ec615e99a9f0c687799f441d/robutils-1.0.0.tar.gz" } ], "1.0.1": [] }, "urls": [] }