After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 547052 - Commandline task tracking
Commandline task tracking
Status: RESOLVED FIXED
Product: hamster-applet
Classification: Deprecated
Component: usability
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: hamster-applet-maint
hamster-applet-maint
Depends on:
Blocks:
 
 
Reported: 2008-08-09 10:14 UTC by Anirudh Sanjeev
Modified: 2012-03-26 15:50 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Basic Hamster-CLI (3.00 KB, patch)
2009-11-22 16:39 UTC, Arwyn Hainsworth
reviewed Details | Review
A command line client for the hamster applet. (17.90 KB, patch)
2010-03-18 18:56 UTC, Matías Ribecky
reviewed Details | Review
A command line client for the hamster applet. (18.36 KB, patch)
2010-03-23 13:13 UTC, Matías Ribecky
none Details | Review
The suggestions from the review. (1.78 KB, patch)
2010-03-23 13:15 UTC, Matías Ribecky
none Details | Review
Moved the commands into classes (15.52 KB, patch)
2010-03-23 13:19 UTC, Matías Ribecky
none Details | Review
The format for the listing table is now dynamic. (18.38 KB, patch)
2010-03-23 13:47 UTC, Matías Ribecky
none Details | Review
Moved the tests into the /tests folder. (11.70 KB, patch)
2010-03-23 13:48 UTC, Matías Ribecky
none Details | Review
A command line client for the hamster applet. (20.18 KB, patch)
2010-04-06 14:49 UTC, Matías Ribecky
reviewed Details | Review

Description Anirudh Sanjeev 2008-08-09 10:14:53 UTC
Since I spend quite a bit of time in the commandline. I'd like to be able to set a new task from the commandline, or see a quick list of the recent tasks.

So I can go like

$ hamster Refactoring my code
Done.

and it'll add a new task
or even

$ hamster --name=Refactoring code --cat=Project Work
Done.

and

$hamster --list
Task             Time
=======================
Do Laundry       15 min
Other stuff      10 min
Work > Code      30 min

... and so on.
Comment 1 Patryk Zawadzki 2008-08-10 17:09:41 UTC
I'd like to implement that by introducing a DBus session service and hamster as the remote client (similar to what gajim and gajim-remote do).
Comment 2 Anirudh Sanjeev 2008-08-10 18:17:39 UTC
I'm working on the commandline client already (you can assign this to me if you want)

I feel that writing a easy remote access wrapper will be really useful. Particularly if you want to have a web based frontend and to make writing plugins easier.

If you can write a basic dbus session service, I can write a commandline client and I have tons more ideas for this project.
Comment 3 Arwyn Hainsworth 2009-11-22 16:39:48 UTC
Created attachment 148278 [details] [review]
Basic Hamster-CLI

Wrote a basic CLI for Hamster. Uses the D-Bus service to communicate.

Supports modifying current activity and adding a completed activity.

TODO:
* List activity history
* View current activity
* Edit/Delete past activities.
Comment 4 jzacsh 2010-02-25 00:49:31 UTC
What is the status of this? I'd love to start manipulating hamster from the command line/writing a script to post contents to my server.
Comment 5 Matías Ribecky 2010-03-18 18:56:35 UTC
Created attachment 156500 [details] [review]
A command line client for the hamster applet.

First of all let me explain this is the first contribution to open source I make, so any feedback is appreciated.
  hamster-client.patch
I have been working on this the past week, this is what I came up with. I went for the "hamster-client" name to follow the rhythmbox devs that named their cli program "rhythmbox-client".

$ hamster-client --help
Usage: hamster-client start [START_TIME[-END_TIME]] ACTIVITY
       hamster-client stop
       hamster-client list [START_TIME[-END_TIME]]

Client for controlling the hamster-applet.

Actions:
    * start (default): Start tracking an activity.
    * stop: Stop tracking current activity.
    * list: List activities.
    * list-activities: List all the activities names, one per line.
    * list-categories: List all the categories names, one per line.

Times formats:
    * 'YYYY-MM-DD hh:mm:ss': Absolute time. Defaulting to 0 for the time
            values missing, and current day for date values.
            E.g. (considering 2010-03-09 16:30:20 as current date, time):
                2010-03 13:15:40 is 2010-03-09 13:15:40
                2010-03-09 13:15 is 2010-03-09 13:15:00
                2010-03-09 13    is 2010-03-09 00:13:00
                2010-02 13:15:40 is 2010-02-09 13:15:40
                13:20            is 2010-03-09 13:20:00
                20               is 2010-03-09 00:20:00
    * '-hh:mm:ss': Relative time. From the current date and time. Defaulting
            to 0 for the time values missing, same as in absolute time.


Options:
  -h, --help  show this help message and exit
$ hamster-client list
 Start - End   | Activity                    Elapsed time
---------------+------------------------------------------
 10:09 - 11:08 | Hamster@Proyectos           59min
 11:12 - 11:59 | Reddit@Ocio                 46min
 13:11 - 13:23 | contrase@Trabajo            11min
 13:23 - 14:14 | Leer las noticias@Trabajo   50min
 14:15 - 14:21 | contrase@Trabajo            5min
 14:30 -       | Hamster@Proyectos           51min
$ hamster-client stop
$ hamster-client start Hamster@Proyectos, Sample usage
Comment 6 Toms Bauģis 2010-03-18 20:45:38 UTC
Review of attachment 156500 [details] [review]:

Thank you for the patch!

I did not try running the script yet - just ran through and read it.
We can well use the script in it's current state, but I would appreciate if you consider my review below and post an updated version.

Right now gnome is entering the last two weeks of the freeze for 2.30, and i'm bit lazy to branch out. So the plan is not to touch git master for now. But as soon as we are out of freeze, could merge this one in!


Oh also, came to my mind that since this is command line, it could have some more brains to make it easier to use.
One idea is to have zero delta syntax, as in "start - something": that should mean "start something and set start time to the end of the last activity.
Just an idea, anyway - maybe Patryk will have some more of these... ideas :)

::: /dev/null
@@ +66,3 @@
+    pass
+
+def main(argv):

would expect main function at the bottom of the file

@@ +152,3 @@
+def start_action(hamster, arg):
+    '''Start a new activity.'''
+    start_date, end_date, arg = parse_datetime_range(arg)

could use hamster.stuff.parse_activity_input here (patched with your supreme regexps for the datetime parsing)

@@ +235,3 @@
+        return datetime.datetime.combine(date, time), rest
+
+def stop_action(hamster, arg):

looks like commands could be moved in a class, where the constructor would initiate the d-bus connection

@@ +292,3 @@
+        spent_string = format_spent_time(fact_start_date, fact_end_date)
+
+        print ' %s - %s | %s %s' % (start_string,

in 2.29+ we introduced tags too so i guess would be nice if they would appear here too

@@ +299,3 @@
+    return 0
+
+def same_day(lhs, rhs):

could use more verbose variable names here - does "lhs" stand for "left hours"?

@@ +343,3 @@
+    return start_string, end_string
+
+def format_spent_time(start_date, end_date):

same as above - perhaps could reuse hamster.stuff.format_duration

@@ +368,3 @@
+
+if __DEBUG__:
+    import unittest

we have /tests folder where the unit test could be moved out perhaps
Comment 7 Matías Ribecky 2010-03-23 13:13:11 UTC
Created attachment 156856 [details] [review]
A command line client for the hamster applet.
Comment 8 Matías Ribecky 2010-03-23 13:15:08 UTC
Created attachment 156858 [details] [review]
The suggestions from the review.
Comment 9 Matías Ribecky 2010-03-23 13:19:20 UTC
Created attachment 156859 [details] [review]
Moved the commands into classes

It looks more clean now, and allows for options for single commands.
Comment 10 Matías Ribecky 2010-03-23 13:47:54 UTC
Created attachment 156867 [details] [review]
The format for the listing table is now dynamic.

Theres now a {-f,--format} option to the list action that allows to control the output. Hopefully the description in the help is enough to understand it:

Table formatting:
    For the list action you can specify a format option to control the layout
    of the columns. Each letter in the format represents a column, the '|' is
    a vertical separator and the '>' indicates to left adjust the next column.
    All other characters are printed without modification. For an example, the
    default format is ' >s - e | >a@c d | t'. The columns are as follows:
        * a: Activity
        * c: Category
        * t: Tags
        * s: Start
        * e: End
        * d: Duration

An example output:
 Start - End   | Activity@Category  Duration | Tags
---------------+-----------------------------+-----
 07:10 - 08:16 |   Reddit@Ocio      1h 6min  |     
 08:38 - 12:24 |  Hamster@Proyectos 3h 46min |     
 12:36 - 13:51 |   comida@Día a día 1h 15min |     
 17:26 - 17:49 |    Video@Ocio      22min    |
Comment 11 Matías Ribecky 2010-03-23 13:48:59 UTC
Created attachment 156868 [details] [review]
Moved the tests into the /tests folder.
Comment 12 Matías Ribecky 2010-03-23 14:09:31 UTC
> Oh also, came to my mind that since this is command line, it could have some
> more brains to make it easier to use.
> One idea is to have zero delta syntax, as in "start - something": that should
> mean "start something and set start time to the end of the last activity.
> Just an idea, anyway - maybe Patryk will have some more of these... ideas :)

That sounds grate.

> @@ +152,3 @@
> +def start_action(hamster, arg):
> +    '''Start a new activity.'''
> +    start_date, end_date, arg = parse_datetime_range(arg)
> 
> could use hamster.stuff.parse_activity_input here (patched with your supreme
> regexps for the datetime parsing)

Oh, I don't think that's a good idea. Although I find it easy to write complex
regexes, I really dislike them. They are really hard to maintain, unreadable
(did you understand what I did?) and don't scale. The one I used already fell
short on a couple inputs, and probably has corner cases where it would screw up.
On top of that, the hamster.stuff.parse_activity_input is deeply linked to the
completion in the applet.
Not to mention that the date syntax is really awkward, just to say yesterday you
have to put the year and month. It would be cool to be able to say -2 days,
or -2d.
Comment 13 Toms Bauģis 2010-03-24 12:32:57 UTC
two notes on the patches - 

the purpose of moving things into class was in order to avoid passing around the connection. right now it's a bit more extreme - i doubt if really the base and inheritance classes are needed.

the dynamic listing certainly does too much for the task - cheapest way out if you would like to add dynamic listing, would be use of named variables and advanced python formatting.


note about my method of reviewing - i'm reviewing on basis that i'll have to be comfortable with the code to maintain it afterwards (not trusting anybody until continuous support has been demonstrated). for that reason my choices might seem to be too picky.

as said before - the code is usable in every stage.
if you prefer, i can take from here on and do the tweaks myself.
if you still would like to go on (which i'd love to see), maybe a quick chat might fasten things - i'm using google talk with this email.
Comment 14 Matías Ribecky 2010-04-06 14:49:43 UTC
Created attachment 158050 [details] [review]
A command line client for the hamster applet.

First of all, I applied your suggestions. Moved all the actions into a single class, each action is a method. If the method has a '-', it is transformed into a '_' to have a valid method name. If the method <action name>_configure exists, it is called after parsing the arguments, useful for actions with arguments or options.
Then the formatting for the listing was simplified, for this the fixed width columns (i.e. the times and duration) were moved to the left. Ending up with something like this:

 Start -   End (Duration) | Activity@Category Tags
--------------------------+------------------------
 xx:xx - xx:xx (xh xxmin) | Xxxxxx@Xxxxxx #xxxx #xxxx

Tags are represented with "#<tagname>", I thought this might be a familiar way for users to represent tags. Which, by the way, there's no way to apply tags from the dbus api.
I also went ahead and i18n the application since I needed to determine the columns headers length to format the table. Not sure how you handle the l10n, so I'll leave that to you.
Comment 15 Toms Bauģis 2010-04-11 14:17:19 UTC
Review of attachment 158050 [details] [review]:

reviewed
Comment 16 Toms Bauģis 2010-04-11 14:24:47 UTC
I've committed modified version of the patch, so we have a ground to start with.
Changes performed by me:

* Reworked the whole class business
* Dropped optparse as the structure of the interface was as much as 
  ./hamster-client.py <command> <optional arguments>
  For such trivial cases using optparse is rather inefficient
* Dropped logging so to match the general style of non-squeakiness

Due to the rather big changes in the code i did not commit unit tests as they are most probably broken and i can't be bothered to update them. Hope you don't mind :)

There are a few quirks here and the code looks bit quick and dirty. I intend to revisit it later. But you are welcome to improve at any moment.

Notable TODO's:

* i'm doing sys.exit in the constructor of the class if we can't connect via dbus
* there is something about the whole UTC offset business, as start tracking from 
  commandline for me works 1 hour back

I think i will close this bug now.

Thanks everyone for contributing. Please keep doing it.
Special thanks to Matias.
Comment 17 Toms Bauģis 2010-04-11 14:25:23 UTC
Review of attachment 148278 [details] [review]:

this is now obsolete
Comment 18 Neal McBurnett 2012-03-26 15:05:24 UTC
The hamster-cli tool is in the code now, so this looks like it has been addressed.  Thanks, folks!

Toms, you said you'd close this, but it is still listed as "NEW".
Comment 19 Toms Bauģis 2012-03-26 15:50:32 UTC
hmm, i wonder. one of these days - i promise, i'll fix all bugs! :)
Comment 20 Toms Bauģis 2012-03-26 15:50:51 UTC
oh and thanks a lot Neal for going through the list!