worktrack 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,58 @@
1
+ ##worktrack
2
+
3
+ worktrack is provides a small binary that tracks one of your directories for file changes. Assuming your directory has many directories being git repositories underneath.
4
+
5
+ Whenever a file is modified, removed or added worktrack will search for the git respository this file belongs to and make an entry into it's own database with a timestamp.
6
+
7
+ ###Installation
8
+
9
+ Install the gemfile
10
+
11
+ gem install worktrack
12
+
13
+ Start worktrack
14
+
15
+ worktrack
16
+
17
+ worktrack will add a directory called ".worktrack" under your home directory with a config.yml file containing the configuration. By default it will start monitoring the directory ~/Documents for changes and store these changes to a SQLite database under ~/.worktrack/changes.db.
18
+
19
+ ###Show work done
20
+
21
+ Running the command
22
+
23
+ worktrack -show
24
+
25
+ will show a list of changes made like this:
26
+
27
+ worktrack - another great nedeco idea
28
+
29
+ 18 changes in 1 Repositories
30
+ worktrack:
31
+ test added on 2013-02-16 22:09:07 +0100
32
+ test removed on 2013-02-16 22:09:08 +0100
33
+ worktrack.rb modified on 2013-02-16 22:15:16 +0100
34
+ worktrack.rb modified on 2013-02-16 22:15:36 +0100
35
+ worktrack.rb modified on 2013-02-16 22:16:29 +0100
36
+ worktrack.rb modified on 2013-02-16 22:16:31 +0100
37
+ worktrack.rb modified on 2013-02-16 22:16:40 +0100
38
+ worktrack.rb modified on 2013-02-16 22:16:55 +0100
39
+ index modified on 2013-02-16 22:19:26 +0100
40
+ d177bb10f5dbc889c1c4a273ff36b1e8a7e77b added on 2013-02-16 22:19:26 +0100
41
+ COMMIT_EDITMSG modified on 2013-02-16 22:19:33 +0100
42
+ index modified on 2013-02-16 22:19:33 +0100
43
+ b894001457bf96372e39512655f1303332d9c2 added on 2013-02-16 22:19:33 +0100
44
+ 2c9d823c762424fa79ad53b693e1c9edcc5b1b added on 2013-02-16 22:19:33 +0100
45
+ master modified on 2013-02-16 22:19:33 +0100
46
+ master modified on 2013-02-16 22:19:33 +0100
47
+ HEAD modified on 2013-02-16 22:19:33 +0100
48
+ 5faa2138e310a1b86f129e00b9fa03f3bf94fe added on 2013-02-16 22:19:33 +0100
49
+
50
+ ###Credits
51
+
52
+ Thanks to the team around guard to provide the listen gem. Thanks to Jan for treating me to track the time spent on work for customers better ;)
53
+
54
+ ###Todo
55
+
56
+ Fork, branch, change, commit merge requests.
57
+
58
+ This is a starting point that shows an idea. It needs much more work to become a usefull tool.
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ require 'worktrack'
3
+
4
+ tracker = WorkTrack.new
5
+ if ARGV[0] == "-show"
6
+ tracker.dump_changes
7
+ else
8
+ tracker.run
9
+ end
Binary file
@@ -0,0 +1,2 @@
1
+ db_file: /Users/abalsam/.changes.db
2
+ watch_dir: /Users/abalsam/Documents/projects/
@@ -0,0 +1,116 @@
1
+ # really lazy checking of your daily work
2
+ #
3
+ require 'rubygems'
4
+ require 'listen'
5
+ require 'time'
6
+ require 'yaml'
7
+ require 'sequel'
8
+ require 'etc'
9
+
10
+ class WorkTrack
11
+ def check_config(dir)
12
+ if !File.exist?("#{dir}/.worktrack/config.yml")
13
+ open("#{dir}/.worktrack/config.yml", 'a') { |conf|
14
+ conf << "db_file: #{dir}/.worktrack/changes.db\n"
15
+ conf << "watch_dir: #{dir}/Documents/\n"
16
+ }
17
+ end
18
+ end
19
+
20
+ def initialize()
21
+ @user_dir=Etc.getpwuid.dir
22
+ @gem_dir=File.dirname(File.expand_path(__FILE__))
23
+
24
+ if !File.directory? "#{@user_dir}/.worktrack"
25
+ Dir::mkdir("#{@user_dir}/.worktrack")
26
+ end
27
+ check_config("#{@user_dir}")
28
+
29
+ @cnf = YAML::load(File.open("#{@user_dir}/.worktrack/config.yml"))
30
+ @DB = Sequel.sqlite(@cnf['db_file'])
31
+
32
+ # quick fix to make sure directory ends with /
33
+ if @cnf['watch_dir'].split(//).last(1).join.to_s != "/"
34
+ @cnf['watch_dir'] = "#{@cnf['watch_dir']}/"
35
+ end
36
+
37
+ # bind models to database. has to be done after db connection is created
38
+ require 'worktrack/models'
39
+
40
+ # create an Change table if not exists
41
+ @DB.create_table? :changes do
42
+ primary_key :id
43
+ foreign_key :repo_id
44
+ String :action
45
+ String :filename
46
+ Time :timestamp
47
+ end
48
+
49
+ @DB.create_table? :repos do
50
+ primary_key :id
51
+ String :name
52
+ String :path
53
+ end
54
+ end
55
+
56
+ def find_repo(name,path)
57
+ #puts "try to find repo with #{name} under #{path}"
58
+ repo = Repo.where(:name => name).first
59
+ if repo.nil?
60
+ Repo.insert(:name => name, :path => path)
61
+ repo = Repo.where(:name => name).first
62
+ end
63
+ puts "Repository is #{repo.name}"
64
+ return repo
65
+ end
66
+
67
+ def analyse(info,action)
68
+ info.each { |f|
69
+ f.slice! @cnf['watch_dir']
70
+ @mylist=f.split("/")
71
+ for i in 0..(@mylist.length - 1)
72
+ @dir=""
73
+ for j in 0..(i-1)
74
+ if @mylist[j] != ""
75
+ @dir = @dir + @mylist[j]+ "/"
76
+ end
77
+ end
78
+ @dir=@cnf['watch_dir'] + @dir
79
+ if File.directory? "#{@dir}.git"
80
+ @repo = find_repo(@mylist[j],@dir)
81
+ @repo.add_change(:action => action, :filename => @mylist[@mylist.length - 1], :timestamp => Time.now)
82
+ puts "\t#{Time.now} tracked #{@mylist[@mylist.length - 1]} in #{@dir}"
83
+ end
84
+ end
85
+ }
86
+ end
87
+
88
+ def dump_changes()
89
+ puts "worktrack - another great nedeco idea\n\n"
90
+ puts "#{Change.all.count} changes in #{Repo.all.count} Repositories"
91
+
92
+ if Repo.all.count == 0
93
+ puts "go and do some work before you want to earn respect"
94
+ else
95
+ Repo.all.each {|rep|
96
+ puts "#{rep.name}:"
97
+ rep.changes.each {|change|
98
+ puts "\t #{change.filename} #{change.action} on #{change.timestamp}"
99
+ }
100
+ }
101
+ end
102
+ end
103
+
104
+ def run
105
+ puts "going to monitor files in #{@cnf['watch_dir']}"
106
+ Listen.to(@cnf['watch_dir'], :ignore => /history|changes.db/) do |modified, added, removed|
107
+ # puts "modified: #{modified.inspect}" unless modified.length == 0
108
+ # puts "added: #{added.inspect}" unless added.length == 0
109
+ # puts "removed: #{removed.inspect}" unless removed.length == 0
110
+
111
+ analyse(modified,"modified") unless modified.length == 0
112
+ analyse(added,"added") unless added.length == 0
113
+ analyse(removed,"removed") unless removed.length == 0
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,7 @@
1
+ class WorkTrack::Repo < Sequel::Model(:repos)
2
+ one_to_many :changes
3
+ end
4
+
5
+ class WorkTrack::Change < Sequel::Model(:changes)
6
+ many_to_one :repo
7
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: worktrack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexander Balsam
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: listen
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: sequel
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: worktrack is a gem to monitor your projects directory to track work done
47
+ within all repos within this directory
48
+ email: alexander@balsam.de
49
+ executables:
50
+ - worktrack
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - bin/worktrack
55
+ - lib/changes.db
56
+ - lib/config.yml
57
+ - lib/worktrack/models.rb
58
+ - lib/worktrack.rb
59
+ - README.md
60
+ homepage: http://development.nedeco.de
61
+ licenses: []
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 1.8.24
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: track your work in git repositories
84
+ test_files: []