Compare commits

..

No commits in common. "900fb9f0c044c06753bb6fc8c88899d0635aafb8" and "ad4b909cf3d66aac6265e3ac6af21bab90dd5f91" have entirely different histories.

View File

@ -94,7 +94,7 @@ def list_categories(search):
results = get_categories(search=search)
for r in results:
click.echo('@{0[0]}: {0[1]}'.format(r))
click.echo('@{0[0]}: {0[1]}'.format(r))
@categories.command('delete')
@ -129,8 +129,8 @@ def delete_categories(ids):
@categories.command('rename')
@click.argument('id_', metavar='ID')
@click.argument('name')
@click.argument('id_', metavar='ID')
@click.argument('name')
def rename_category(id_, name):
""" Rename a category """
@ -143,7 +143,6 @@ def rename_category(id_, name):
c.execute(sql, (name, r[0]))
conn.commit()
@categories.command('activities')
@click.argument('ids', nargs=-1)
def list_category_activities(ids):
@ -163,10 +162,10 @@ def list_category_activities(ids):
seq=','.join(['?'] * len(ids))
)
results = c.execute(sql, ids)
results = c.execute(sql, ids)
for r in results:
click.echo('@{0[0]}: {0[2]} » {0[1]}'.format(r))
click.echo('@{0[0]}: {0[2]} » {0[1]}'.format(r))
@cli.group()
@ -231,7 +230,7 @@ def move(category_id, ids):
click.secho('Moving to "@{0[0]}: {0[1]}":'.format(category), fg='green')
for r in results:
click.secho('@{0[3]}: {0[2]} » @{0[0]}: {0[1]}'.format(r), fg='blue')
click.secho('@{0[3]}: {0[2]} » @{0[0]}: {0[1]}'.format(r), fg='blue')
click.confirm('Do you want to continue?', abort=True)
@ -281,8 +280,7 @@ def list_facts(ids):
results = c.execute(sql, (r[0],))
for r in results:
click.secho('@{0[0]}, {0[1]}'.format(r), fg='blue')
click.secho('@{0[0]}, {0[1]}'.format(r), fg='blue')
@activities.command()
@click.argument('from_id')
@ -315,7 +313,7 @@ def move_facts(from_id, to_id):
results = c.execute(sql, (from_id,))
for r in results:
click.secho('@{0[0]}, {0[1]}'.format(r), fg='blue')
click.secho('@{0[0]}, {0[1]}'.format(r), fg='blue')
click.confirm('Do you want to continue?', abort=True)
@ -329,8 +327,7 @@ def move_facts(from_id, to_id):
click.secho('Moved {0} facts'.format(results.rowcount), fg='green')
click.confirm(
'Would you like to delete @{0[2]} » @{0[0]}: {0[1]}?'.format(
from_activity),
'Would you like to delete @{0[2]} » @{0[0]}: {0[1]}?'.format(from_activity),
abort=True
)
@ -363,8 +360,7 @@ def find_duplicates():
results = c.execute(sql)
for r in results:
click.secho(
'@{0[0]}: {0[1]} » @{0[2]}: {0[3]} ({0[4]})'.format(r), fg='blue')
click.secho('@{0[0]}: {0[1]} » @{0[2]}: {0[3]} ({0[4]})'.format(r), fg='blue')
@cli.group()
@ -434,12 +430,9 @@ def sync(username, api_key, just_errors, ignore_activities, mapping_path=None):
'X-AUTH-TOKEN': api_key
}
customers = requests.get(
f'{kimai_api_url}/customers?visible=3', headers=auth_headers).json()
projects = requests.get(
f'{kimai_api_url}/projects?visible=3', headers=auth_headers).json()
activities = requests.get(
f'{kimai_api_url}/activities?visible=3', headers=auth_headers).json()
customers = requests.get(f'{kimai_api_url}/customers?visible=3', headers=auth_headers).json()
projects = requests.get(f'{kimai_api_url}/projects?visible=3', headers=auth_headers).json()
activities = requests.get(f'{kimai_api_url}/activities?visible=3', headers=auth_headers).json()
found_customers = []
found_projects = []
@ -448,47 +441,38 @@ def sync(username, api_key, just_errors, ignore_activities, mapping_path=None):
for row in mapping_data:
# Check if each mapping still exists in Kimai
matching_customers = list(
filter(lambda x: x['name'] == row[0], customers))
matching_customers = list(filter(lambda x: x['name'] == row[0], customers))
if row[0] in found_customers:
just_errors or click.secho(
"Skipping existing customer '{0}'".format(row[0]), fg='green')
just_errors or click.secho("Skipping existing customer '{0}'".format(row[0]), fg='green')
else:
if len(matching_customers) > 1:
click.secho(
"More than one match for customer '{0}'".format(row[0]), fg='red')
click.secho("More than one match for customer '{0}'".format(row[0]), fg='red')
continue
elif len(matching_customers) < 1:
click.secho("Missing customer '{0}'".format(
row[0]), fg='yellow')
click.secho("Missing customer '{0}'".format(row[0]), fg='yellow')
continue
else:
just_errors or click.secho(
"Found customer '{0}'".format(row[0]), fg='green')
just_errors or click.secho("Found customer '{0}'".format(row[0]), fg='green')
found_customers.append(row[0])
project_str = ':'.join(row[0:2])
matching_projects = list(filter(
lambda x: x['name'] == row[1] and
x['customer'] == matching_customers[0]['id'],
x['customer'] == matching_customers[0]['id'],
projects)
)
if project_str in found_projects:
just_errors or click.secho(
"Skipping existing project '{0}'".format(project_str), fg='green')
just_errors or click.secho("Skipping existing project '{0}'".format(project_str), fg='green')
else:
if len(matching_projects) > 1:
click.secho("More than one match for project '{0}'".format(
project_str), fg='red')
click.secho("More than one match for project '{0}'".format(project_str), fg='red')
continue
elif len(matching_projects) < 1:
click.secho("Missing project '{0}'".format(
project_str), fg='yellow')
click.secho("Missing project '{0}'".format(project_str), fg='yellow')
continue
else:
just_errors or click.secho(
"Found project '{0}'".format(project_str), fg='green')
just_errors or click.secho("Found project '{0}'".format(project_str), fg='green')
found_projects.append(project_str)
if ignore_activities:
@ -496,24 +480,20 @@ def sync(username, api_key, just_errors, ignore_activities, mapping_path=None):
activity_str = ':'.join(row)
if activity_str in found_activities:
just_errors or click.secho(
"Skipping existing activity '{0}'".format(activity_str), fg='green')
just_errors or click.secho("Skipping existing activity '{0}'".format(activity_str), fg='green')
else:
matching_activities = list(filter(
lambda x: x['name'] == row[2]
and x['project'] == matching_projects[0]['id'],
lambda x: x['name'] == row[2]
and x['project'] == matching_projects[0]['id'],
activities
))
if len(matching_activities) > 1:
click.secho("More than one match for activity '{0}'".format(
activity_str), fg='red')
click.secho("More than one match for activity '{0}'".format(activity_str), fg='red')
elif len(matching_activities) < 1:
click.secho("Missing activity '{0}'".format(
activity_str), fg='yellow')
click.secho("Missing activity '{0}'".format(activity_str), fg='yellow')
else:
just_errors or click.secho(
"Found activity '{0}'".format(activity_str), fg='green')
just_errors or click.secho("Found activity '{0}'".format(activity_str), fg='green')
found_activities.append(activity_str)
@ -606,8 +586,7 @@ def _import(username, mapping_path=None, output=None, category_search=None, afte
except KeyError:
if show_missing:
output_writer.writerow([fact[6], fact[5]])
click.secho(
"Can't find mapping for '{0}', skipping".format(k), fg='yellow')
click.secho("Can't find mapping for '{0}', skipping".format(k), fg='yellow')
continue
if show_missing:
@ -631,18 +610,18 @@ def _import(username, mapping_path=None, output=None, category_search=None, afte
output_writer.writerow([
date_start.strftime('%Y-%m-%d'),
date_start.strftime('%H:%M'),
'', # To (time)
'', # To (time)
duration,
'', # Rate
'', # Rate
username,
mapping_[0],
mapping_[1],
mapping_[2],
fact[3] or '',
'0', # Exported
'0', # Exported
mapping_[3],
'', # Hourly rate
'', # Fixed rate
'', # Hourly rate
'', # Fixed rate
])
output_file.close()