-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle importerrors when f.x. we are installing
- Loading branch information
Showing
1 changed file
with
39 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,50 @@ | ||
import logging | ||
|
||
import click | ||
from lockfile import LockFile, LockTimeout | ||
try: | ||
import click | ||
from lockfile import LockFile, LockTimeout | ||
except ImportError: | ||
click = None | ||
|
||
logger = logging.getLogger('spoppy.main') | ||
|
||
|
||
def get_version(): | ||
return '1.1.0' | ||
|
||
|
||
@click.command() | ||
@click.argument('username', required=False) | ||
@click.argument('password', required=False) | ||
def main(username, password): | ||
# Ignore error, logging set up in logging utils | ||
from . import logging_utils | ||
from .navigation import Leifur | ||
from .config import get_config, set_config, get_config_from_user | ||
|
||
lock = LockFile('/tmp/spoppy.lock') | ||
try: | ||
# Try for 5s to acquire the lock | ||
lock.acquire(5) | ||
except LockTimeout: | ||
click.echo('Could not acquire lock, is spoppy running?') | ||
else: | ||
|
||
if username and password: | ||
set_config(username, password) | ||
else: | ||
username, password = get_config() | ||
if not (username and password): | ||
username, password = get_config_from_user() | ||
if click: | ||
@click.command() | ||
@click.argument('username', required=False) | ||
@click.argument('password', required=False) | ||
def main(username, password): | ||
# Ignore error, logging set up in logging utils | ||
from . import logging_utils | ||
from .navigation import Leifur | ||
from .config import get_config, set_config, get_config_from_user | ||
|
||
lock = LockFile('/tmp/spoppy.lock') | ||
try: | ||
navigator = Leifur(username, password) | ||
navigator.start() | ||
# Try for 5s to acquire the lock | ||
lock.acquire(5) | ||
except LockTimeout: | ||
click.echo('Could not acquire lock, is spoppy running?') | ||
else: | ||
|
||
if username and password: | ||
set_config(username, password) | ||
else: | ||
username, password = get_config() | ||
if not (username and password): | ||
username, password = get_config_from_user() | ||
try: | ||
navigator = Leifur(username, password) | ||
navigator.start() | ||
finally: | ||
navigator.shutdown() | ||
logger.debug('Finally, bye!') | ||
finally: | ||
navigator.shutdown() | ||
logger.debug('Finally, bye!') | ||
finally: | ||
if lock.i_am_locking(): | ||
lock.release() | ||
if lock.i_am_locking(): | ||
lock.release() | ||
else: | ||
def main(*args, **kwargs): | ||
print('Something went horribly wrong, missing requirements...') |