Permalink
Browse files

More work on the CLI

  • Loading branch information...
1 parent d08bdb1 commit c89b11cebba46b140bd2cba0b2aaebc3a85179d8 Sebastian Ruml committed Feb 9, 2012
Showing with 39 additions and 11 deletions.
  1. +36 −7 src/cli.py
  2. +1 −1 src/configuration.py
  3. +1 −1 src/fswatcher.py
  4. +1 −2 src/web_server.py
View
@@ -28,7 +28,7 @@ def __init__(self, args, options):
self._args = args
self._options = options
- self._usage = "usage: %prog start|stop|restart"
+ self._usage = "usage: pythondrop start|stop|restart|create|status|config|factoryreset|help"
self._app = AppManager(self.pid_file(), debug=self._options.debugmode)
self._config = self._app._config
@@ -38,8 +38,8 @@ def __init__(self, args, options):
def parseArgs(self):
# Check for the correct numbers of arguments
- if len(self._args) != 1:
- print self._usage
+ if len(self._args) < 1:
+ self.print_help_message()
sys.exit(2)
if self._args[0] == 'start':
@@ -54,7 +54,11 @@ def parseArgs(self):
self.status()
elif self._args[0] == 'config':
self.config()
- elif self.args[0] == 'factoryreset':
+ elif self._args[0] == 'factoryreset':
+ pass
+ elif self._args[0] == 'help':
+ self.help()
+ elif self._args[0] == 'rm':
pass
else:
print "Unknown command"
@@ -84,8 +88,15 @@ def restart(self):
self.start()
def create(self):
- if len(self._args) < 4:
- print "Error"
+ if len(self._args) is not 5:
+ print "False number of arguments!"
+ return
+
+ # Add new repository
+ self._config.add_share(self._args[1], self._args[2], self._args[3], self._args[4])
+
+ # Restart PythonDrop
+ self.restart()
def status(self):
print "PythonDrop v" + self._globs.version
@@ -104,9 +115,11 @@ def config(self):
print " - Web Server Listen IP: " + self._config.webServerListenIp
print " - Web Server Listen Port: " + str(self._config.webServerListenPort)
print " - Systray Enabled: " + str(self._config.enableSystray)
+ elif len(self._args) > 1:
+ pass
def help(self):
- pass
+ self.print_help_message()
def running(self):
return self._app.running()
@@ -116,3 +129,19 @@ def stopped(self):
def pid_file(self):
return "/tmp/pythondrop.pid"
+
+ def print_help_message(self):
+ print self._usage
+ print "Type pythondrop -h or pythondrop --help to see all options"
+ print
+ print "Arguments:"
+ print " start: Start PythonDrop"
+ print " stop: Stop PythonDrop"
+ print " restart: Restart PythonDrop"
+ print " create: Create and add a new share."
+ print " Usage: create sync_directory remote_host remote_directory remote_user"
+ print " rm: Removes the specified share"
+ print " status: Shows the current status"
+ print " config: Shows the current configuration"
+ print " factoryreset: Resets all settings"
+ print " help: Prints this help message"
View
@@ -113,7 +113,7 @@ def add_share(self, syncFolder, remoteHost, remotePath, remoteUser):
self._dbSession.add(share)
self._dbSession.commit()
- def remove_share(self, id):
+ def remove_share(self, syncFolder):
pass
def get_shares(self):
View
@@ -1,4 +1,4 @@
-# Copyright (C) 2010 - 2011 Sebastian Ruml <sebastian.ruml@gmail.com>
+# Copyright (C) 2010 - 2012 Sebastian Ruml <sebastian.ruml@gmail.com>
#
# This file is part of the PythonDrop project
#
View
@@ -56,7 +56,7 @@ def shares(share_id=None, dir=None):
error = None
if share_id == None:
- error = "No share id given"
+ error = "No share id found!"
return render_template('dir.html', error=error)
share = get_share_by_id(share_id)
@@ -70,7 +70,6 @@ def shares(share_id=None, dir=None):
# FIXME: Add support for mode type
if request.form.get('action', None) == 'ok': # Create folder
dirName = request.form['dirName']
- share = get_share_by_id(share_id)
if not None and len(dirName) > 0 and share != None:
if dir != None:
dirPath = os.path.join(os.path.join(share.sync_folder, dir), dirName)

0 comments on commit c89b11c

Please sign in to comment.