summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xobnam16
-rw-r--r--obnamlib/__init__.py3
-rw-r--r--obnamlib/app.py9
-rw-r--r--obnamlib/vfs_sftp.py12
4 files changed, 32 insertions, 8 deletions
diff --git a/obnam b/obnam
index 59ccd3a3..aaf5b23f 100755
--- a/obnam
+++ b/obnam
@@ -15,5 +15,19 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import logging
+import sys
+import traceback
+
import obnamlib
-obnamlib.App().run()
+try:
+ obnamlib.App().run()
+except obnamlib.AppException, e:
+ logging.critical(str(e))
+ sys.stderr.write('Error: %s\n' % str(e))
+ sys.exit(1)
+except BaseException, e:
+ logging.critical(traceback.format_exc())
+ sys.stderr.write(traceback.format_exc())
+ sys.exit(1)
+
diff --git a/obnamlib/__init__.py b/obnamlib/__init__.py
index 57c811e0..9c6077f7 100644
--- a/obnamlib/__init__.py
+++ b/obnamlib/__init__.py
@@ -17,6 +17,9 @@
import _obnam
from pluginmgr import PluginManager
+class AppException(Exception):
+ pass
+
from hooks import Hook, HookManager
from cfg import Configuration
from interp import Interpreter
diff --git a/obnamlib/app.py b/obnamlib/app.py
index 985d7bd5..76b60daa 100644
--- a/obnamlib/app.py
+++ b/obnamlib/app.py
@@ -34,6 +34,9 @@ class App(object):
self.pm = obnamlib.PluginManager()
self.pm.locations = [self.plugins_dir()]
self.pm.plugin_arguments = (self,)
+
+ self.interp = obnamlib.Interpreter()
+ self.register_command = self.interp.register
self.hooks.new('plugins-loaded')
self.hooks.new('shutdown')
@@ -55,6 +58,10 @@ class App(object):
self.hooks.call('plugins-loaded')
self.config.load()
self.setup_logging()
- print 'args:', self.config.args
+ if self.config.args:
+ self.interp.execute(self.config.args[0], self.config.args[1:])
+ else:
+ raise obnamlib.AppException('Usage error: '
+ 'must give operation on command line')
self.hooks.call('shutdown')
diff --git a/obnamlib/vfs_sftp.py b/obnamlib/vfs_sftp.py
index cf862132..13f71293 100644
--- a/obnamlib/vfs_sftp.py
+++ b/obnamlib/vfs_sftp.py
@@ -67,17 +67,17 @@ class SftpFS(obnamlib.VirtualFileSystem):
known_hosts = os.path.expanduser('~/.ssh/known_hosts')
keys = paramiko.util.load_host_keys(known_hosts)
if hostname not in keys:
- raise obnamlib.Exception("Host key for %s not found" % hostname)
+ raise obnamlib.AppException("Host key for %s not found" % hostname)
elif not keys[hostname].has_key(key.get_name()):
- raise obnamlib.Exception("Unknown host key for %s" % hostname)
+ raise obnamlib.AppException("Unknown host key for %s" % hostname)
elif keys[hostname][key.get_name()] != key:
print '*** WARNING: Host key has changed!!!'
- raise obnamlib.Exception("Host key has changed for %s" % hostname)
+ raise obnamlib.AppException("Host key has changed for %s" % hostname)
def authenticate(self, username):
if self.authenticate_via_agent(username):
return
- raise obnamlib.Exception("Can't authenticate to SSH server.")
+ raise obnamlib.AppException("Can't authenticate to SSH server.")
def authenticate_via_agent(self, username):
agent = paramiko.Agent()
@@ -104,7 +104,7 @@ class SftpFS(obnamlib.VirtualFileSystem):
self.write_file(lockname, "")
except IOError, e:
if e.errno == errno.EEXIST:
- raise obnamlib.Exception("Lock %s already exists" % lockname)
+ raise obnamlib.AppException("Lock %s already exists" % lockname)
else:
raise
@@ -134,7 +134,7 @@ class SftpFS(obnamlib.VirtualFileSystem):
self.sftp.utime(self.join(relative_path), (atime, mtime))
def link(self, existing, new):
- raise obnamlib.Exception("Cannot link on SFTP. Sorry.")
+ raise obnamlib.AppException("Cannot link on SFTP. Sorry.")
def readlink(self, relative_path):
return self.sftp.readlink(self.join(relative_path))