wlog 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3b808a1daa10b7f6cb1f1998ce32b99557b2c5c3
4
+ data.tar.gz: f3617644d86f9bc7e9dac4527d061b298e849cbe
5
+ SHA512:
6
+ metadata.gz: 25837321ff609d5ebd0206a010ae4bc25858f09d9cd3782b44a6f7043dd32dcc80bd43ae970576d19a5e080ec0204adc2a6019e131094a57345b7eb2669efbb7
7
+ data.tar.gz: 5239206cd3ffa64dc979acf86ceadc42b7f8704eae1c89d719051584b7e433076ee9855aab219d46b4d57f2e66e3b7177673ac35f75c7890d49a0c98b6d2a6d2
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.swp
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wlog.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # wlog
2
+
3
+ wlog (worklog) is a small utility to track tasks in command line. I use this
4
+ for things I work on and need to submit a list of stuff done on a particular
5
+ day.
6
+
7
+ Disclaimer: Some of the things in this software assume an ANSI terminal. So you
8
+ might get weird characters if you're not on an ANSI terminal.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'wlog'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install wlog
23
+
24
+ ## Usage
25
+
26
+ On command line write
27
+
28
+ wlog
29
+
30
+ When you specify nothing, the default database is used. If you want to store
31
+ tasks in different databases (lets say you have project1, project2), then execute
32
+ the following line:
33
+
34
+ wlog project2
35
+
36
+ The databases are located here:
37
+
38
+ $HOME/.config/wlog/data/
39
+
40
+ And you should be in a command line interface. In the interface you can type in
41
+
42
+ help
43
+
44
+ To see a list of actions that you can do.
45
+
46
+ Usually you'll just need to write:
47
+
48
+ new
49
+
50
+ And enter the work description that you wish. You can add tags like this too
51
+ in order to tag units of work:
52
+
53
+ new
54
+
55
+ Enter work description:
56
+ I did something very productive today. #bugfix #completed #feature
57
+
58
+ The tags can be pretty much anything you want, and for now are not very
59
+ important. In the future however they might be used for something more useful.
60
+
61
+ ## Contributing
62
+
63
+ 1. Fork it
64
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
66
+ 4. Push to the branch (`git push origin my-new-feature`)
67
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/wlog ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'wlog/cli_interface.rb'
4
+
5
+ include Wlog
6
+
7
+ puts "Worktime logger"
8
+
9
+ if ARGV.size > 0
10
+ case ARGV[0]
11
+ when "list"
12
+ CliInterface.list_databases_command
13
+
14
+ end
15
+ else
16
+ CliInterface.new.run
17
+ end
@@ -0,0 +1,149 @@
1
+ require 'wlog/log_entry.rb'
2
+
3
+ module Wlog
4
+ # Author :: Simon Symeonidis
5
+ class CliInterface
6
+
7
+ # Run the interface
8
+ def run
9
+ cmd = "default"
10
+ until cmd == "end" do
11
+ print "[wlog::] "
12
+ cmd = $stdin.gets
13
+ cmd ||= "end"
14
+ cmd.chomp!
15
+
16
+ case cmd
17
+ when "new"
18
+ puts "Enter work description:"
19
+ print " "
20
+ new_entry_command
21
+ puts "ok"
22
+
23
+ when "show"
24
+ puts "Showing latest log entries"
25
+ show_entries_command
26
+
27
+ when "outcsv"
28
+ puts "Exporting to CSV."
29
+ fh = File.open("out.csv", "w")
30
+ fh.write(make_csv)
31
+ fh.close
32
+
33
+ when "delete"
34
+ print "Remove task with id: "
35
+ delete_entry_command
36
+
37
+ when "search"
38
+ search_term
39
+
40
+ when "concat"
41
+ concat_description
42
+
43
+ when "replace"
44
+ replace_pattern
45
+
46
+ when "help"
47
+ print_help
48
+ end
49
+ end
50
+ end
51
+
52
+ # TODO the commands should be factored out
53
+ def self.list_databases_command
54
+ puts "Available Worklog databases: "
55
+ Dir["#{StaticConfigurations::DATA_DIRECTORY}*"].each do |n|
56
+ print "[%8d bytes]" % File.size(n)
57
+ print " "
58
+ print n
59
+ puts
60
+ end
61
+ end
62
+
63
+ private
64
+
65
+ # Print the help of the cli app
66
+ def print_help
67
+ ["new", "Create a new log entry",
68
+ "outcsv", "Export everything to CSV",
69
+ "help", "print this dialog",
70
+ "concat", "Add a string at the end of a previous entry",
71
+ "end", "Exit the progam",
72
+ "search", "Search for a string in the log description text",
73
+ "delete", "Remove the task with a given id"].each_with_index do |el,ix|
74
+ print " " if 1 == ix % 2
75
+ puts el
76
+ end
77
+ end
78
+
79
+ # new entry command
80
+ def new_entry_command
81
+ description = $stdin.gets.chomp!
82
+ log_entry = LogEntry.new
83
+ log_entry.description = description
84
+ log_entry.insert
85
+ end
86
+
87
+ def show_entries_command
88
+ print_entries(LogEntry.find_all)
89
+ end
90
+
91
+ def print_entries(entries_arr)
92
+ date_collections = entries_arr.group_by{|le| le.date.strftime("%Y-%m-%d")}
93
+ date_collections.each_key do |k|
94
+ print "\x1b[32;1m#{k}\x1b[0m - "
95
+ print "\x1b[33;1m#{date_collections[k].first.date.strftime("%A")}\x1b[0m "
96
+ puts "[\x1b[35;1m#{date_collections[k].count}\x1b[0m]"
97
+ date_collections[k].each do |le|
98
+ puts " #{le}"
99
+ end
100
+ end
101
+ end
102
+
103
+ def search_term
104
+ print "Term to search: "
105
+ term = $stdin.gets.chomp!
106
+ print_entries(LogEntry.search_descriptions(term))
107
+ end
108
+
109
+ def delete_entry_command
110
+ LogEntry.delete($stdin.gets.to_i)
111
+ end
112
+
113
+ def make_csv
114
+ str = String.new
115
+ LogEntry.find_all.group_by{|el| el.date.strftime("%Y-%m-%d")}.each_pair do |key,value|
116
+ str.concat("#{value.first.date.strftime("%A")} {key}\n")
117
+ value.each do |entry|
118
+ str.concat(",\"#{entry.description}\"")
119
+ end
120
+ end
121
+ str
122
+ end
123
+
124
+ # Concatenate an aggregate description to a previous item
125
+ def concat_description
126
+ print "ID of task to concatenate to: "
127
+ id = $stdin.gets.to_i
128
+ log_entry = LogEntry.find(id)
129
+ print "Information to concatenate: "
130
+ str = $stdin.gets.chomp!
131
+ log_entry.description.concat(str)
132
+ log_entry.update
133
+ end
134
+
135
+ # Replace a pattern from a description of a log entry
136
+ def replace_pattern
137
+ print "ID of task to perform replace: "
138
+ id = $stdin.gets.to_i
139
+ print "replace : "
140
+ pattern1 = $stdin.gets.chomp!
141
+ print "with : "
142
+ pattern2 = $stdin.gets.chomp!
143
+
144
+ log_entry = LogEntry.find(id)
145
+ log_entry.description.gsub!(pattern1,pattern2)
146
+ log_entry.update
147
+ end
148
+ end
149
+ end # module Wlog
@@ -0,0 +1,52 @@
1
+ require 'singleton'
2
+ require 'sqlite3'
3
+ require 'fileutils'
4
+
5
+ require 'wlog/static_configurations.rb'
6
+
7
+ module Wlog
8
+ # Author :: Simon Symeonidis
9
+ # The db registry, using sqlite3
10
+ class DbRegistry
11
+ include Singleton
12
+
13
+ def initialize
14
+ make_dirs
15
+ make_tables = !database_exists?
16
+
17
+ @db_handle = SQLite3::Database.new(
18
+ "#{StaticConfigurations::DATA_DIRECTORY}"\
19
+ "#{ARGV[0] || StaticConfigurations::DEFAULT_DATABASE}")
20
+
21
+ if make_tables
22
+ execute(@@log_entry_sql)
23
+ end
24
+ end
25
+
26
+ def execute(*sql)
27
+ @db_handle.execute(*sql)
28
+ end
29
+
30
+ # the database handle
31
+ attr_accessor :db_handle
32
+
33
+ private
34
+ # NOTE this concern could be encapsulated in another class
35
+ def make_dirs
36
+ # Does the data dir path not exist?
37
+ unless File.exists? StaticConfigurations::DATA_DIRECTORY
38
+ FileUtils.mkdir_p StaticConfigurations::DATA_DIRECTORY
39
+ end
40
+ end
41
+
42
+ def database_exists?
43
+ File.exists?\
44
+ "#{StaticConfigurations::DATA_DIRECTORY}#{ARGV[0]\
45
+ || StaticConfigurations::DEFAULT_DATABASE}"
46
+ end
47
+
48
+ @@log_entry_sql =\
49
+ "CREATE TABLE log_entries (id INTEGER PRIMARY KEY AUTOINCREMENT,"\
50
+ "description TEXT, date DATETIME);"
51
+ end
52
+ end # module Wlog
@@ -0,0 +1,28 @@
1
+ module Wlog
2
+ # @author Simon Symeonidis
3
+ # @date Wed Jul 10 17:37:24 EDT 2013
4
+ # This contains a few helper methods that may be used by any part in the
5
+ # application.
6
+ class Helpers
7
+
8
+ # Break the string to a different line
9
+ # @param string is the string that we want processed.
10
+ # @param numchars is the amount of characters max per line.
11
+ def self.break_string(string,numchars)
12
+ desc = ""
13
+ cl = 0
14
+ string.split.each do |word|
15
+ if cl + word.length + 1 > numchars
16
+ cl = 0
17
+ desc.concat($/)
18
+ end
19
+ desc.concat(word).concat(" ")
20
+ cl += word.length + 1
21
+ end
22
+
23
+ desc.chomp!
24
+ desc
25
+ end
26
+
27
+ end
28
+ end # module Wlog
@@ -0,0 +1,102 @@
1
+ require 'wlog/db_registry.rb'
2
+ require 'wlog/helpers.rb'
3
+
4
+ module Wlog
5
+ # Author :: Simon Symeonidis
6
+ # Active Record Domain object for a log entry
7
+ class LogEntry
8
+
9
+ def initialize
10
+ @date = Time.new
11
+ end
12
+
13
+ def self.find(id)
14
+ row = DbRegistry.instance.execute(@@select,id).first
15
+ le = LogEntry.new
16
+ le.id = row[0]
17
+ le.description = row[1]
18
+ le.date = Time.at(row[2])
19
+ le
20
+ end
21
+
22
+ def self.find_all
23
+ all = Array.new
24
+ DbRegistry.instance.execute(@@select_all).each do |row|
25
+ le = LogEntry.new
26
+ le.id = row[0]
27
+ le.description = row[1]
28
+ le.date = Time.at(row[2])
29
+ all.push le
30
+ end
31
+ all
32
+ end
33
+
34
+ def self.delete(id)
35
+ DbRegistry.instance.execute(@@delete_sql,id)
36
+ end
37
+
38
+ # TODO this shouldn't be here
39
+ def self.create_table
40
+ DbRegistry.instance.execute(@@create_sql)
41
+ end
42
+
43
+ # update the entry
44
+ def update
45
+ DbRegistry.instance.execute(@@update_sql,@description,@id)
46
+ end
47
+
48
+ # Search by string to find a matching description with 'LIKE'.
49
+ def self.search_descriptions(term)
50
+ all = Array.new
51
+ DbRegistry.instance.execute(@@select_description_like,"%#{term}%").each do |row|
52
+ le = LogEntry.new
53
+ le.id = row[0]
54
+ le.description = row[1]
55
+ le.date = Time.at(row[2])
56
+ all.push le
57
+ end
58
+ all
59
+ end
60
+
61
+ def insert
62
+ DbRegistry.instance.execute(@@insert_sql,@description,@date.to_i)
63
+ end
64
+
65
+ # Delete the loaded log entry currently in memory, by passing its id
66
+ def delete
67
+ self.delete(self.id)
68
+ end
69
+
70
+ # Print things nicely formmated no more than 80 cars (well, unless you stick
71
+ # the time in the end which is not counted for).
72
+ def to_s
73
+ str = "[#{id}] "
74
+ tmp = @description + " [#{@date.strftime("%H:%M:%S")}]"
75
+ desc = Wlog::Helpers.break_string(tmp,80)
76
+ indent = " " * (id.to_s.split('').count + 5)
77
+ desc.gsub!(/#{$/}/, "#{$/}#{indent}")
78
+ str.concat(desc)
79
+ str
80
+ end
81
+
82
+ # The identity field for the log entry DO
83
+ attr_accessor :id
84
+
85
+ # Text description for the log entry
86
+ attr_accessor :description
87
+
88
+ # Date the entry was created
89
+ attr_accessor :date
90
+
91
+ ## SQL ##
92
+ @@table_name = "log_entries"
93
+ @@insert_sql = "INSERT INTO #{@@table_name} (description,date) values (?,?);"
94
+ @@delete_sql = "DELETE FROM #{@@table_name} WHERE id = ? ;"
95
+ @@select_all = "SELECT * FROM #{@@table_name} ORDER BY date ASC;"
96
+ @@update_sql = "UPDATE #{@@table_name} SET description=? WHERE id=?;"
97
+ #@@select_all = "SELECT * FROM #{@@table_name} WHERE date >=#{Time.now.to_i - 604800 - 24 * 60 * 60} ORDER BY date ASC"
98
+ @@select = "SELECT * FROM #{@@table_name} WHERE id = ? ;"
99
+ @@select_description_like = "SELECT * FROM #{@@table_name} WHERE description LIKE ?;"
100
+
101
+ end
102
+ end # module Wlog
@@ -0,0 +1,21 @@
1
+ module Wlog
2
+ # Author :: Simon Symeonidis
3
+ # Licenses :: GPL v3.0
4
+ # Static path data.
5
+ module StaticConfigurations
6
+ # The application name
7
+ APPLICATION_NAME = "wlog"
8
+
9
+ # Absolute path to the configuration directory
10
+ CONFIGURATION_DIRECTORY = "#{ENV['HOME']}/.config/"
11
+
12
+ # Absolute path to the application directory
13
+ APPLICATION_DIRECTORY = "#{CONFIGURATION_DIRECTORY}#{APPLICATION_NAME}/"
14
+
15
+ # Absolute path to the data directory
16
+ DATA_DIRECTORY = "#{APPLICATION_DIRECTORY}data/"
17
+
18
+ # Default database name (when unspecified)
19
+ DEFAULT_DATABASE = "default"
20
+ end
21
+ end # module Wlog
@@ -0,0 +1,3 @@
1
+ module Wlog
2
+ VERSION = "0.0.3"
3
+ end
data/lib/wlog.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "wlog/version"
2
+
3
+ module Wlog
4
+ # Your code goes here...
5
+ end
data/wlog.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wlog/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wlog"
8
+ spec.version = Wlog::VERSION
9
+ spec.authors = ["psyomn"]
10
+ spec.email = ["lethaljellybean@gmail.com"]
11
+ spec.description = %q{Track tasks and time on the command line.}
12
+ spec.summary = %q{A light ruby script to help track tasks and time}
13
+ spec.homepage = "http://github.com/psyomn/wlog"
14
+ spec.license = "GPL v3.0"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_runtime_dependency "sqlite3", ">= 1.3.7"
24
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wlog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - psyomn
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.3.7
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.7
55
+ description: Track tasks and time on the command line.
56
+ email:
57
+ - lethaljellybean@gmail.com
58
+ executables:
59
+ - wlog
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - README.md
66
+ - Rakefile
67
+ - bin/wlog
68
+ - lib/wlog.rb
69
+ - lib/wlog/cli_interface.rb
70
+ - lib/wlog/db_registry.rb
71
+ - lib/wlog/helpers.rb
72
+ - lib/wlog/log_entry.rb
73
+ - lib/wlog/static_configurations.rb
74
+ - lib/wlog/version.rb
75
+ - wlog.gemspec
76
+ homepage: http://github.com/psyomn/wlog
77
+ licenses:
78
+ - GPL v3.0
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.0.3
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: A light ruby script to help track tasks and time
100
+ test_files: []
101
+ has_rdoc: