Skip to content

Commit 3e56082

Browse files
committed
External activities
- added possibility to export activities to external source using command line
1 parent b6e0c8d commit 3e56082

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- x: toggle export flag
77
* Gathering activities from external source (right now only Jira and only via dbus)
88
* Export activities as worklogs to jira
9+
* Export activities to external source from command line (`hamster export external` command)
910

1011
## Changes in 3.0.2
1112

src/hamster-cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def assist(self, *args):
237237
if assist_command == "start":
238238
hamster_client._activities(" ".join(args[1:]))
239239
elif assist_command == "export":
240-
formats = "html tsv xml ical hamster".split()
240+
formats = "html tsv xml ical hamster external".split()
241241
chosen = sys.argv[-1]
242242
formats = [f for f in formats if not chosen or f.startswith(chosen)]
243243
print("\n".join(formats))
@@ -422,7 +422,7 @@ def version(self):
422422
* list [start-date [end-date]]: List activities
423423
* search [terms] [start-date [end-date]]: List activities matching a search
424424
term
425-
* export [html|tsv|ical|xml|hamster] [start-date [end-date]]: Export activities with
425+
* export [html|tsv|ical|xml|hamster|external] [start-date [end-date]]: Export activities with
426426
the specified format
427427
* current: Print current activity
428428
* activities: List all the activities names, one per line.

src/hamster/reports.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from string import Template
3030
from textwrap import dedent
3131

32+
from hamster import client
3233
from hamster.lib import datetime as dt
3334
from hamster.lib.configuration import runtime
3435
from hamster.lib import stuff
@@ -57,6 +58,8 @@ def simple(facts, start_date, end_date, format, path = None):
5758
writer = ICalWriter(report_path)
5859
elif format == "hamster":
5960
writer = HamsterWriter(report_path)
61+
elif format == "external":
62+
writer = ExternalWriter(report_path)
6063
else: #default to HTML
6164
writer = HTMLWriter(report_path, start_date, end_date)
6265

@@ -168,6 +171,24 @@ def _write_fact(self, fact):
168171
def _finish(self, facts):
169172
pass
170173

174+
class ExternalWriter(ReportWriter):
175+
def __init__(self, path):
176+
ReportWriter.__init__(self, path)
177+
self.storage = client.Storage()
178+
179+
def _write_fact(self, fact):
180+
exported = self.storage.export_fact(fact.id)
181+
if exported:
182+
self.file.write(_("Exported: %s - %s") % (fact.activity, fact.delta) + "\n")
183+
fact.exported = True
184+
self.storage.update_fact(fact.id, fact, False)
185+
pass
186+
else:
187+
self.file.write(_("Fact not exported: %s" % fact.activity) + "\n")
188+
189+
def _finish(self, facts):
190+
pass
191+
171192
class XMLWriter(ReportWriter):
172193
def __init__(self, path):
173194
ReportWriter.__init__(self, path)

0 commit comments

Comments
 (0)