[Assorted-commits] SF.net SVN: assorted:[956] sharing-gateway/trunk
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-08-28 17:45:02
|
Revision: 956 http://assorted.svn.sourceforge.net/assorted/?rev=956&view=rev Author: yangzhang Date: 2008-08-28 17:45:09 +0000 (Thu, 28 Aug 2008) Log Message: ----------- added more documentation; tidied up gateway.py a bit Modified Paths: -------------- sharing-gateway/trunk/README sharing-gateway/trunk/src/gateway.py Modified: sharing-gateway/trunk/README =================================================================== --- sharing-gateway/trunk/README 2008-08-28 16:34:12 UTC (rev 955) +++ sharing-gateway/trunk/README 2008-08-28 17:45:09 UTC (rev 956) @@ -6,25 +6,42 @@ can then be re-exported. Part of this acts like `mount -a` in mounting/unmounting a set of filesystems, -but features: +but: -- YAML configuration file format +- uses a simple YAML configuration file format - can handle hostnames instead of IPs for CIFS shares - can create the mountpoint directories The rest of this is mostly documentation on how to configure your own servers -to do what you want. +for the gateway. Setup ----- +### Gateway Controller + +This is currently used for mounting, unmounting, and indexing. + Requirements: -- Python -- Python YAML +- [Python] +- [Python YAML] +[Python]: http://python.org/ +[Python YAML]: http://pyyaml.org/ + ### Web Frontend +Requirements: + +- [Apache httpd] 2.2 +- [mod_ssl] 2.8 +- [openssl] 2.2 + +[Apache httpd]: http://httpd.apache.org/ +[mod_ssl]: http://www.modssl.org/ +[openssl]: http://openssl.org/ + #### Create certificates The following is a summary of [Creating Certificate Authorities and self-signed Modified: sharing-gateway/trunk/src/gateway.py =================================================================== --- sharing-gateway/trunk/src/gateway.py 2008-08-28 16:34:12 UTC (rev 955) +++ sharing-gateway/trunk/src/gateway.py 2008-08-28 17:45:09 UTC (rev 956) @@ -1,7 +1,13 @@ #!/usr/bin/env python -'Manage a sharing gateway: enable/disable sharing networks.' +""" +Manage a sharing gateway: enable/disable sharing networks. Available commands: +- mount: mount all shares +- umount: unmount all shares +- index: generate indexes +""" + from __future__ import with_statement from commons.startup import run_main from commons.structs import structs2dicts, dicts2structs @@ -10,6 +16,7 @@ from path import path from socket import gethostbyname from subprocess import Popen, PIPE +from sys import stderr import yaml class my_exception( Exception ): pass @@ -25,7 +32,7 @@ raise my_exception( 'command failed with error code %s: %s' % ( p.returncode, cmd ) ) def main( argv ): - parser = OptionParser( usage = '%prog [OPTIONS] start | stop' ) + parser = OptionParser( usage = '%prog [OPTIONS] mount | umount | index' ) parser.add_option( '-c', '--config', default = '/etc/sharing-gateway.yaml', help = 'the YAML configuration file to read from' ) @@ -36,23 +43,29 @@ mountdir = path( cfg.gateway.mountdir ) indexdir = path( cfg.gateway.indexdir ) - if cmd == 'start': + if cmd == 'mount': for s in cfg.shares: if s.type == 'cifs': d = structs2dicts( s ) d[ 'ip' ] = gethostbyname( s.host ) mountpt = mountdir / s.name - run( [ 'sudo', 'mkdir', '-p', mountpt ] ) - run( 'sudo mount -t cifs -o'.split() + - [ 'user=%(user)s,pass=%(pass)s,ip=%(ip)s' % d, s.share, mountpt ] ) + try: + run( [ 'sudo', 'mkdir', '-p', mountpt ] ) + run( 'sudo mount -t cifs -o'.split() + + [ 'user=%(user)s,pass=%(pass)s,ip=%(ip)s' % d, s.share, mountpt ] ) + except: + print >> stderr, 'error mounting', s.name else: raise my_exception( 'unknown share type: %s' % s.type ) - elif cmd == 'stop': + elif cmd == 'umount': for s in cfg.shares: mountpt = mountdir / s.name - run( [ 'sudo', 'umount', mountpt ] ) - run( [ 'sudo', 'rmdir', mountpt ] ) - elif cmd == 'index': # requires super user + try: + run( [ 'sudo', 'umount', mountpt ] ) + run( [ 'sudo', 'rmdir', mountpt ] ) + except: + print >> stderr, 'error unmounting', s.name + elif cmd == 'index': for s in cfg.shares: print 'indexing', s.name mountpt = mountdir / s.name @@ -61,7 +74,7 @@ with file( index, 'w' ) as f: runout( [ 'ls', '-lR', mountpt ], f ) except: - pass + print >> stderr, 'error indexing', s.name else: raise my_exception( 'unknown command: %s' % cmd ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |