pug 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/pug.rb ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+ require "pug"
3
+ require "tracker"
4
+ require "configuration"
5
+ require "commands/commandcontext"
6
+ require "commands/initcommand"
7
+ require "commands/addcommand"
8
+ require "commands/helpcommand"
9
+ require "commands/diffcommand"
10
+ require "commands/listcommand"
11
+
12
+ onprompt = lambda do |text|
13
+ puts text
14
+ $stdin.gets.chomp
15
+ end
16
+ onoutput = lambda do |o|
17
+ puts o.to_s
18
+ end
19
+ onerror = lambda do |e|
20
+ puts e
21
+ end
22
+ onexit = lambda do |x|
23
+ exit(x)
24
+ end
25
+
26
+ commandcontext = Commands::CommandContext.new(ARGV, onerror, onoutput, onprompt, onexit)
27
+ commandname = commandcontext.pop_argument!("Missing command, try help ;-)")
28
+
29
+ configuration = Configuration.new('.')
30
+
31
+ # make sure that we are configured
32
+ if commandname == 'init' || !configuration.has_globalconfiguration?
33
+ puts "There is no configuration available, please provide me with some info..." if commandname != "init"
34
+ Commands::InitCommand.new(configuration).run commandcontext
35
+ exit 0 if commandname == 'init'
36
+ end
37
+
38
+ if commandname == nil
39
+ commandname = 'help'
40
+ end
41
+
42
+ globalconfiguration = configuration.get_globalconfiguration()
43
+
44
+ # path to directory should be read from .pug_global
45
+ pugspath = globalconfiguration.pugspath
46
+ tracker = Tracker.new(pugspath)
47
+
48
+ command = Meta::command_from_name(commandname, tracker)
49
+ if command != nil
50
+ command.run commandcontext
51
+ exit 0
52
+ else
53
+ puts "Unknown command #{commandname}"
54
+ exit 1
55
+ end
data/bin/pugdiff.rb ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+ require "pug"
3
+ require "erb"
4
+
5
+ #$:.unshift(File.dirname(__FILE__))
6
+
7
+ require "tracker"
8
+ require "deltatracker"
9
+
10
+ class DeltasModel
11
+ def initialize(deltas)
12
+ @deltas = deltas
13
+ end
14
+
15
+ def get_binding
16
+ binding
17
+ end
18
+ end
19
+
20
+ type = ARGV.shift
21
+ pugspath_is = ARGV.shift
22
+ pugspath_was = ARGV.shift
23
+ templatepath = ARGV.shift
24
+
25
+ tracker_is = Tracker.new(pugspath_is)
26
+ tracker_was = Tracker.new(pugspath_was)
27
+
28
+ deltatracker = DeltaTracker.new
29
+ diffs = []
30
+ deltatracker.get(type, tracker_is, tracker_was){|d| diffs.push(d)}
31
+
32
+ model = DeltasModel.new(diffs)
33
+ templatecontent = File.read(templatepath)
34
+ template = ERB.new(templatecontent)
35
+
36
+ report = template.result(model.get_binding)
37
+ puts report
@@ -0,0 +1,25 @@
1
+ $:.unshift(File.expand_path('../../', __FILE__))
2
+ require "meta"
3
+ require "parse"
4
+
5
+ module Commands
6
+
7
+ class AddCommand
8
+ def initialize(tracker)
9
+ @tracker = tracker
10
+ end
11
+
12
+ def run(commandcontext)
13
+ type = commandcontext.pop_argument! 'Missing type'
14
+ status = commandcontext.pop_argument! 'Missing status'
15
+
16
+ title = commandcontext.prompt "Enter a title"
17
+
18
+ @tracker.add(type, status, title)
19
+ end
20
+
21
+ def help(commandcontext)
22
+ commandcontext.output 'Use pug add <type of report> <initial status>'
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,56 @@
1
+ $:.unshift(File.expand_path('../../', __FILE__))
2
+ require 'time'
3
+ require "commands/headlesscommandcontext"
4
+
5
+ module Commands
6
+ class CommandContext
7
+ attr_accessor :output_lambda, :prompt_lambda, :now_lambda
8
+
9
+ def initialize(arguments, onerror, onoutput, onprompt, onexit)
10
+ @arguments = arguments
11
+ @headless = (@arguments.any? { |arg| arg == '--headless' })
12
+ @onerror = onerror
13
+ @onexit = onexit
14
+ @onoutput = onoutput
15
+ @onprompt = onprompt
16
+ @now_lambda = lambda {|| DateTime.now }
17
+ end
18
+
19
+ def pop_argument!(text_when_missing = nil)
20
+ if number_of_arguments == 0
21
+ @onerror.call(text_when_missing)
22
+ @onexit.call(1)
23
+ end
24
+ @arguments.shift
25
+ end
26
+
27
+ def number_of_arguments
28
+ @arguments.length
29
+ end
30
+
31
+ def output(s)
32
+ @onoutput.call(s)
33
+ end
34
+
35
+ def error(s)
36
+ @onerror.call(s)
37
+ end
38
+
39
+ def prompt(text)
40
+ if @headless
41
+ raise HeadLessCommandContextException.new()
42
+ end
43
+ @onprompt.call(text)
44
+ end
45
+
46
+ #def prompt_as_lambda
47
+ # lambda {|field, text, defaultvalue| prompt field, text, defaultvalue }
48
+ #end
49
+
50
+ def get_now
51
+ @now_lambda.call
52
+ end
53
+
54
+
55
+ end
56
+ end
@@ -0,0 +1,24 @@
1
+ $:.unshift(File.expand_path('../../', __FILE__))
2
+
3
+ require "tracker"
4
+ require "deltatracker"
5
+
6
+ module Commands
7
+
8
+ class DiffCommand
9
+ def initialize(tracker)
10
+ @tracker_is = tracker
11
+ end
12
+
13
+ def run(commandcontext)
14
+ type = commandcontext.pop_argument! 'Missing type'
15
+ pugspath_was = commandcontext.pop_argument! 'Missing path to pugs'
16
+ tracker_was = Tracker.new(pugspath_was)
17
+ DeltaTracker.new().get(type, @tracker_is, tracker_was){|d| commandcontext.output(d) }
18
+ end
19
+
20
+ def help(commandcontext)
21
+ commandcontext.output 'Use pug diff <type> <path to pugs to compare to>'
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,4 @@
1
+ module Commands
2
+ class HeadLessCommandContextException < Exception
3
+ end
4
+ end
@@ -0,0 +1,28 @@
1
+ $:.unshift(File.expand_path('../../', __FILE__))
2
+ require "meta"
3
+
4
+ module Commands
5
+
6
+ class HelpCommand
7
+ def initialize(tracker)
8
+ @tracker = tracker
9
+ end
10
+
11
+ def run(commandcontext)
12
+ if commandcontext.number_of_arguments == 0
13
+ help(commandcontext)
14
+ else
15
+ commandname = commandcontext.pop_argument!("")
16
+ command = Meta::command_from_name(commandname, @tracker)
17
+ if command != nil
18
+ command.help(commandcontext)
19
+ end
20
+ end
21
+ end
22
+
23
+ def help(commandcontext)
24
+ commandcontext.output 'Use pug help <command>'
25
+ Meta::list_of_commands.each {|command| commandcontext.output command}
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,22 @@
1
+ $:.unshift(File.expand_path('../../', __FILE__))
2
+
3
+ require "configuration"
4
+
5
+ module Commands
6
+ class InitCommand
7
+ def initialize(configuration)
8
+ @configuration = configuration
9
+ end
10
+
11
+ def run(commandcontext)
12
+ globalconfiguration = GlobalConfiguration.new
13
+ globalconfiguration.pugspath = commandcontext.prompt "Enter full path to where pugs will be placed"
14
+ @configuration.set_globalconfiguration(globalconfiguration)
15
+ end
16
+
17
+ def help(commandcontext)
18
+ commandcontext.output 'Use pug init'
19
+ commandcontext.output 'Configures settings file'
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ $:.unshift(File.expand_path('../../', __FILE__))
2
+
3
+ require "tracker"
4
+ require "deltatracker"
5
+
6
+ module Commands
7
+
8
+ class ListCommand
9
+ def initialize(tracker)
10
+ @tracker = tracker
11
+ end
12
+
13
+ def run(commandcontext)
14
+ type = commandcontext.pop_argument!.downcase if commandcontext.number_of_arguments > 0
15
+ status = commandcontext.pop_argument!.downcase if commandcontext.number_of_arguments > 0
16
+
17
+ @tracker.all {|x|
18
+ if (x.type.downcase == type || type == nil) && (x.status.downcase == status || status == nil)
19
+ commandcontext.output(x)
20
+ end
21
+ }
22
+ end
23
+
24
+ def help(commandcontext)
25
+ commandcontext.output 'Use pug list [type [status]]'
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,47 @@
1
+ require "yaml"
2
+
3
+ class GlobalConfiguration
4
+ attr_accessor :pugspath
5
+
6
+ def initialize
7
+ @pugspath = ''
8
+ end
9
+ end
10
+
11
+ class Configuration
12
+ def initialize(path)
13
+ @path = path
14
+ end
15
+
16
+ def _globalconfiguration_filename()
17
+ File.join(@path, '.pug_global')
18
+ end
19
+
20
+ def has_globalconfiguration?
21
+ File.exists?(_globalconfiguration_filename)
22
+ end
23
+
24
+ def set_globalconfiguration(model)
25
+ content = model.to_yaml
26
+ begin
27
+ file = File.new(_globalconfiguration_filename, 'w')
28
+ file.write(content)
29
+ ensure
30
+ file.close
31
+ end
32
+
33
+ if !Dir.exists?(model.pugspath)
34
+ Dir.mkdir(model.pugspath)
35
+ end
36
+ end
37
+
38
+ def get_globalconfiguration()
39
+ begin
40
+ file = File.open(_globalconfiguration_filename)
41
+ model = YAML::load(file) if file != nil
42
+ model
43
+ ensure
44
+ file.close if file != nil
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,35 @@
1
+
2
+ class Delta
3
+ attr_accessor :is, :was
4
+
5
+ def to_s
6
+ if was == nil
7
+ diff = "void => #{is.status}"
8
+ elsif is == nil
9
+ diff = "#{was.status} => void"
10
+ else
11
+ diff = "#{was.status} => #{is.status}"
12
+ end
13
+ "-#{is.title}\n" +
14
+ " #{diff}"
15
+ end
16
+ end
17
+
18
+ class DeltaTracker
19
+ def get(type, tracker_is, tracker_was)
20
+ tracker_is.all() {|is|
21
+ delta = Delta.new
22
+ delta.is = is
23
+ delta.was = tracker_was.find(is.filename)
24
+
25
+ yield delta if is.type.downcase == type.downcase && (delta.was == nil || delta.is.status != delta.was.status)
26
+ }
27
+ tracker_was.all() {|was|
28
+ delta = Delta.new
29
+ delta.was = was
30
+ delta.is = tracker_is.find(was.filename)
31
+
32
+ yield delta if was.type.downcase == type.downcase && delta.is == nil
33
+ }
34
+ end
35
+ end
data/lib/format.rb ADDED
@@ -0,0 +1,10 @@
1
+ module Format
2
+ def Format.compact_datetime(dt)
3
+ "%04d%02d%02d%02d%02d" % [dt.year, dt.month, dt.day, dt.hour, dt.minute]
4
+ end
5
+
6
+ def Format.safe_for_filename(s)
7
+ s.gsub(/[ ]/, '_')
8
+ .gsub(/[(){}:]/, '')
9
+ end
10
+ end
data/lib/meta.rb ADDED
@@ -0,0 +1,16 @@
1
+
2
+ module Meta
3
+
4
+ def Meta.command_from_name(commandname, tracker)
5
+ begin
6
+ klass = Commands.const_get(commandname.capitalize + 'Command')
7
+ klass.new tracker
8
+ rescue NameError
9
+ nil
10
+ end
11
+ end
12
+
13
+ def Meta.list_of_commands()
14
+ Commands.constants.select{|x| x =~ /Command$/ }.map{|c| c.to_s.gsub /Command$/, '' }
15
+ end
16
+ end
data/lib/parse.rb ADDED
@@ -0,0 +1,12 @@
1
+ module Parse
2
+ def Parse.option_to_name_and_value(option)
3
+ splitted = option.split('=')
4
+ name = splitted[0]
5
+ name = name.gsub(/[-]/, '')
6
+
7
+ value = splitted[1]
8
+ value = value.gsub(/^"/, '').gsub(/"$/, '')
9
+
10
+ { :name => name, :value => value }
11
+ end
12
+ end
data/lib/pug.rb ADDED
@@ -0,0 +1,6 @@
1
+ root = File.expand_path(File.dirname(__FILE__))
2
+ Dir.glob(File.join(root, '*.rb')).select do |f|
3
+ ! f.match(/^pug.rb$/)
4
+ end.each do |f|
5
+ require f
6
+ end
data/lib/pugversion.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Pug
2
+ VERSION = '0.2.0'
3
+ end
data/lib/tracker.rb ADDED
@@ -0,0 +1,125 @@
1
+ require "date"
2
+ require "find"
3
+
4
+ require "format"
5
+
6
+ class Tracked
7
+ attr_accessor :filepath, :type, :status, :title, :filename
8
+
9
+ def to_s
10
+ "-#{title}\n" +
11
+ " #{type}:#{status}\n" +
12
+ " #{filepath}"
13
+ end
14
+ end
15
+
16
+ class Tracker
17
+ attr_reader :root
18
+
19
+ def initialize(root)
20
+ @root = root
21
+ raise "#{root} is not a directory" if !File.directory?root
22
+ end
23
+
24
+ def filename_from(title)
25
+ nowpart = Format::compact_datetime(DateTime.now)
26
+ titlepart = Format::safe_for_filename(title)
27
+ filename = "#{titlepart}_#{nowpart}.txt"
28
+ end
29
+
30
+ def ensure_directory_exists(directory)
31
+ Dir.mkdir(directory) if !File.directory?(directory)
32
+ end
33
+
34
+ def add(type, status, title)
35
+ directory = File.join(@root, type)
36
+ ensure_directory_exists directory
37
+ directory = File.join(directory, status)
38
+ ensure_directory_exists directory
39
+ filename = filename_from(title)
40
+ filepath = File.join(directory, filename)
41
+ begin
42
+ file = File.new(filepath, 'w')
43
+ file.puts title
44
+ ensure
45
+ file.close
46
+ end
47
+
48
+ tracked = Tracked.new()
49
+ tracked.type = type
50
+ tracked.status = status
51
+ tracked.title = title
52
+ tracked.filepath = filepath
53
+ tracked.filename = filename
54
+
55
+ tracked
56
+ end
57
+
58
+
59
+ def get(type, status, filename)
60
+ filepath = File.join(@root, type, status, filename)
61
+ title = nil
62
+ File.open(filepath) {|f| title = f.readline }
63
+ title = title.gsub(/\n/, '')
64
+
65
+ tracked = Tracked.new()
66
+ tracked.type = type
67
+ tracked.status = status
68
+ tracked.filepath = filepath
69
+ tracked.filename = filename
70
+ tracked.title = title
71
+
72
+ tracked
73
+ end
74
+
75
+ def all()
76
+ if File.directory?@root
77
+ Find.find(@root) do |path|
78
+ if FileTest.directory?(path)
79
+ if File.basename(path)[0] == '.'
80
+ Find.prune
81
+ else
82
+ next
83
+ end
84
+ else
85
+ if File.file?(path)
86
+ # split into parts to extract status
87
+ parts = path.split(File::SEPARATOR).reverse
88
+ trackedfilename = parts.shift
89
+ trackedstatus = parts.shift
90
+ trackedtype = parts.shift
91
+ yield get(trackedtype, trackedstatus, trackedfilename)
92
+ else
93
+ next
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
99
+
100
+ def find(filename)
101
+ return nil if !File.directory?@root
102
+
103
+ Find.find(@root) do |path|
104
+ if FileTest.directory?(path)
105
+ if File.basename(path)[0] == '.'
106
+ Find.prune
107
+ else
108
+ next
109
+ end
110
+ else
111
+ if File.basename(path) == filename
112
+ # split into parts to extract status
113
+ parts = path.split(File::SEPARATOR).reverse
114
+ parts.shift # pops filename
115
+ status = parts.shift
116
+ type = parts.shift
117
+ return get type, status, filename
118
+ else
119
+ next
120
+ end
121
+ end
122
+ end
123
+ nil
124
+ end
125
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pug
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - 2hdddg
9
+ - wallymathieu
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-02-26 00:00:00.000000000Z
14
+ dependencies: []
15
+ description: Pug is a simple light-weight distributed issue tracker, main purpose
16
+ is to automatically create release reports.
17
+ email: []
18
+ executables:
19
+ - pug.rb
20
+ - pugdiff.rb
21
+ extensions: []
22
+ extra_rdoc_files: []
23
+ files:
24
+ - lib/commands/addcommand.rb
25
+ - lib/commands/commandcontext.rb
26
+ - lib/commands/diffcommand.rb
27
+ - lib/commands/headlesscommandcontext.rb
28
+ - lib/commands/helpcommand.rb
29
+ - lib/commands/initcommand.rb
30
+ - lib/commands/listcommand.rb
31
+ - lib/configuration.rb
32
+ - lib/deltatracker.rb
33
+ - lib/format.rb
34
+ - lib/meta.rb
35
+ - lib/parse.rb
36
+ - lib/pug.rb
37
+ - lib/pugversion.rb
38
+ - lib/tracker.rb
39
+ - bin/pug.rb
40
+ - bin/pugdiff.rb
41
+ homepage: https://github.com/2hdddg/pug
42
+ licenses: []
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: 1.9.3
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ segments:
60
+ - 0
61
+ hash: -183053119
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 1.7.2
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Light-weight issue tracker
68
+ test_files: []