Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def handle_error():
try:
yield
except exceptions.TodomanException as e:
click.echo(e)
sys.exit(e.EXIT_CODE)
def todo(self, id, read_only=False):
# XXX: DON'T USE READ_ONLY
result = self._conn.execute('''
SELECT todos.*, files.list_name, files.path
FROM todos, files
WHERE files.path = todos.file_path
AND todos.id = ?
''', (id,)
).fetchone()
if not result:
raise exceptions.NoSuchTodo(id)
if not read_only:
count = self._conn.execute('''
SELECT count(id) AS c
FROM files, todos
WHERE todos.file_path = files.path
AND path=?
''', (result['path'],)
).fetchone()
if count['c'] > 1:
raise exceptions.ReadOnlyTodo(result['path'])
return self._todo_from_db(result)
ctx.formatter_class = formatters.PorcelainFormatter
else:
ctx.formatter_class = formatters.DefaultFormatter
color = color or ctx.config['main']['color']
if color == 'always':
click_ctx.color = True
elif color == 'never':
click_ctx.color = False
paths = [
path for path in glob.iglob(expanduser(ctx.config["main"]["path"]))
if isdir(path)
]
if len(paths) == 0:
raise exceptions.NoListsFound(ctx.config["main"]["path"])
ctx.db = Database(paths, ctx.config['main']['cache_path'])
# Make python actually use LC_TIME, or the user's locale settings
locale.setlocale(locale.LC_TIME, "")
''', (id,)
).fetchone()
if not result:
raise exceptions.NoSuchTodo(id)
if not read_only:
count = self._conn.execute('''
SELECT count(id) AS c
FROM files, todos
WHERE todos.file_path = files.path
AND path=?
''', (result['path'],)
).fetchone()
if count['c'] > 1:
raise exceptions.ReadOnlyTodo(result['path'])
return self._todo_from_db(result)