Skip to content

Commit

Permalink
External activities
Browse files Browse the repository at this point in the history
- added possibility to export activities to external source using command line
  • Loading branch information
gsobczyk committed Aug 3, 2020
1 parent 0719e23 commit a085949
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- x: toggle export flag
* Gathering activities from external source (right now only Jira and only via dbus)
* Export activities as worklogs to jira
* Export activities to external source from command line (`hamster export external` command)

## Changes in 3.0.2

Expand Down
4 changes: 2 additions & 2 deletions src/hamster-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def assist(self, *args):
if assist_command == "start":
hamster_client._activities(" ".join(args[1:]))
elif assist_command == "export":
formats = "html tsv xml ical hamster".split()
formats = "html tsv xml ical hamster external".split()
chosen = sys.argv[-1]
formats = [f for f in formats if not chosen or f.startswith(chosen)]
print("\n".join(formats))
Expand Down Expand Up @@ -422,7 +422,7 @@ def version(self):
* list [start-date [end-date]]: List activities
* search [terms] [start-date [end-date]]: List activities matching a search
term
* export [html|tsv|ical|xml|hamster] [start-date [end-date]]: Export activities with
* export [html|tsv|ical|xml|hamster|external] [start-date [end-date]]: Export activities with
the specified format
* current: Print current activity
* activities: List all the activities names, one per line.
Expand Down
21 changes: 21 additions & 0 deletions src/hamster/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from string import Template
from textwrap import dedent

from hamster import client
from hamster.lib import datetime as dt
from hamster.lib.configuration import runtime
from hamster.lib import stuff
Expand Down Expand Up @@ -57,6 +58,8 @@ def simple(facts, start_date, end_date, format, path = None):
writer = ICalWriter(report_path)
elif format == "hamster":
writer = HamsterWriter(report_path)
elif format == "external":
writer = ExternalWriter(report_path)
else: #default to HTML
writer = HTMLWriter(report_path, start_date, end_date)

Expand Down Expand Up @@ -168,6 +171,24 @@ def _write_fact(self, fact):
def _finish(self, facts):
pass

class ExternalWriter(ReportWriter):
def __init__(self, path):
ReportWriter.__init__(self, path)
self.storage = client.Storage()

def _write_fact(self, fact):
exported = self.storage.export_fact(fact.id)
if exported:
self.file.write(_("Exported: %s - %s") % (fact.activity, fact.delta) + "\n")
fact.exported = True
self.storage.update_fact(fact.id, fact, False)
pass
else:
self.file.write(_("Fact not exported: %s" % fact.activity) + "\n")

def _finish(self, facts):
pass

class XMLWriter(ReportWriter):
def __init__(self, path):
ReportWriter.__init__(self, path)
Expand Down

0 comments on commit a085949

Please sign in to comment.