diff options
author | Filipp Lepalaan <f@0x00.co> | 2012-12-29 10:48:09 +0200 |
---|---|---|
committer | Filipp Lepalaan <f@0x00.co> | 2012-12-29 10:48:09 +0200 |
commit | 8abe84f846cdb751931a4b890c3bc4ec91f2db69 (patch) | |
tree | 5ce6dc68f75f483e3122882ced825587efc7e4b1 | |
parent | b5e50f8a4c798a444c7b619e37f8f564f3f768d4 (diff) | |
download | simpleton-master.tar.gz simpleton-master.tar.bz2 simpleton-master.zip |
-rw-r--r-- | README.md | 19 | ||||
-rwxr-xr-x | simpleton.py | 53 |
2 files changed, 33 insertions, 39 deletions
@@ -8,21 +8,16 @@ Installation ============ 1. Install prerequisites: - sudo pip install pyyaml termcolor + sudo pip install termcolor -2. Create your ~/.simpleton.yaml file: +2. Create your ~/.simpleton file: - HTTP: - - http://intra.example.com + http://intra.example.com + smtp://mail.example.com + ftp://files.example.com + afp://username:password@files.example.com/share - SMTP: - - mail.example.com - - FTP: - - files.example.com - - AFP: - - username:password@files.example.com/share +3. Run simpleton.py Todo ==== diff --git a/simpleton.py b/simpleton.py index a025749..5f8a3aa 100755 --- a/simpleton.py +++ b/simpleton.py @@ -12,40 +12,39 @@ import sys import urllib import ftplib import smtplib -import yaml +import urlparse import subprocess import tempfile from termcolor import colored, cprint if len(sys.argv) < 2 or not os.path.exists(sys.argv[1]): - fh = open(os.path.join(os.getenv('HOME'), '.simpleton.yaml')) + fh = open(os.path.join(os.getenv('HOME'), '.simpleton')) -services = yaml.load(fh) tests, passed, started = (0, 0, time.time()) -for k, v in services.items(): - for u in v: - tests += 1 - msg = '* testing %s: %s' % (k, u) - out = colored(msg, 'green') - try: - if k == 'HTTP': - urllib.urlopen(u) - if k == 'FTP': - ftplib.FTP(u) - if k == 'SMTP': - smtplib.SMTP(u) - if k == 'AFP': - tmp_path = tempfile.mkdtemp() - subprocess.check_call(['/sbin/mount_afp', '-o', 'nobrowse', u, tmp_path]) - subprocess.check_call(['/sbin/umount', tmp_path]) - os.rmdir(tmp_path) - - passed += 1 - except Exception, e: - print e - out = colored(msg, 'red') - - print out +for l in fh.readlines(): + url = l.strip() + parsed = urlparse.urlparse(url) + tests += 1 + msg = '* testing %s' % (url) + out = colored(msg, 'green') + + try: + if parsed.scheme == 'http': + urllib.urlopen(url) + if parsed.scheme == 'ftp': + ftplib.FTP(parsed.netloc) + if parsed.scheme == 'smtp': + smtplib.SMTP(parsed.netloc) + if parsed.scheme == 'afp': + tmp_path = tempfile.mkdtemp() + subprocess.check_call(['/sbin/mount_afp', '-o', 'nobrowse', url, tmp_path]) + subprocess.check_call(['/sbin/umount', tmp_path]) + os.rmdir(tmp_path) + passed += 1 + except Exception, e: + out = colored(msg, 'red') + + print out print '%d of %d tests passed in %d seconds' % (passed, tests, int(time.time() - started)) |