Commit 3befc40c authored by Romain Bignon's avatar Romain Bignon

request login only when needed

parent 7231858c
......@@ -27,3 +27,4 @@ Commands
Here is a list of every commands you can run with the 'bnporc.py' program:
list List every available accounts
coming <ID> Display all futur operations
......@@ -73,26 +73,33 @@ class Application:
parser.print_help()
sys.exit(1)
if not options.password:
options.password = self.prompt_password('Password: ')
self.options = options
if not options.password.isdigit():
print >>sys.stderr, 'Error: please enter a numeric password'
return 1
return self.command(arguments[0], *arguments[1:])
config = SafeConfigParser()
config.add_section('auth')
config.set('auth', 'login', options.login)
with open(self.CONFIG_FILE, 'wb') as configfile:
config.write(configfile)
def login(func):
def inc(self):
if not self.options.password:
self.options.password = self.prompt_password('Password: ')
try:
self.bnp.login(options.login, options.password)
except LoginError, err:
print >>sys.stderr, 'Error: %s' % err
return 1
if not self.options.password.isdigit():
print >>sys.stderr, 'Error: please enter a numeric password'
return 1
return self.command(arguments[0], *arguments[1:])
config = SafeConfigParser()
config.add_section('auth')
config.set('auth', 'login', self.options.login)
with open(self.CONFIG_FILE, 'wb') as configfile:
config.write(configfile)
try:
self.bnp.login(self.options.login, self.options.password)
except LoginError, err:
print >>sys.stderr, 'Error: %s' % err
return 1
return func(self)
return inc
def getMethods(self, prefix):
services = {}
......@@ -110,6 +117,8 @@ class Application:
commands = self.getMethods('command_')
if not command in commands:
print >>sys.stderr, "No such command: %s" % command
self.command_help()
return 1
try:
return commands[command](*args)
except TypeError, e:
......@@ -119,6 +128,13 @@ class Application:
print >>sys.stderr, '%s' % e
return 1
def command_help(self):
print 'Available commands are:'
print ' list List every available accounts'
print ' coming <ID> Display all future operations'
print 'BNPorc is a free software. Copyright(C) 2009 Romain Bignon'
@login
def command_list(self):
accounts = self.bnp.get_accounts_list()
......@@ -133,6 +149,7 @@ class Application:
return 0
@login
def command_coming(self, id):
try:
account = self.bnp.get_account(int(id))
......@@ -151,6 +168,7 @@ class Application:
print ' %8s %-50s %11.2f' % (operation.date,
operation.label,
operation.amount)
return 0
if __name__ == '__main__':
app = Application()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment