ptf 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d061046d970e40aa337b3d7c22d6694c86218ed1
4
- data.tar.gz: 2d7f5790adb59b3384be8ee40a8a750a16519202
3
+ metadata.gz: b064a82fc522d39a16f0e27203cdfdd38a75c6fb
4
+ data.tar.gz: 162fc849a41882f39ceee43bbae6c35d1e7abbcc
5
5
  SHA512:
6
- metadata.gz: 2227f3d74a214e752cb2fe504d8a7824a31b949123807c7305127be1f9f172ad2169fc1025cd191d0c05e6a62879f159f591f9f04bef52643b6522403f5398e1
7
- data.tar.gz: 5dc3cd5181bedc740c02c8036884b24bd0d936a49c5589426a9e68d8e3ca5298fbc922fd037f6bc7634e5ed7a0a3ea19d17ecca0bc8e4ccd4d71f64b7af01731
6
+ metadata.gz: f348ea5ab25b189b8ac0f01a29e3a639836d17adc8c555111c3d592b67b1089e287718b771784bd5243d9711986ef94984773e70093118c1f21341a2e1c5c35c
7
+ data.tar.gz: 88e2b468612959d5e32271ed38bd14e36d22732f7a3b7f423caa8f775c045f32a27a157915f25457274fad59845667dafc46b6af6d0d861572a20ffa7d4f0dd4
data/lib/ptf.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  require 'ptf/version'
2
2
  require 'ptf/client'
3
3
  require 'ptf/config'
4
- require 'ptf/utilities'
5
- require 'ptf/data'
4
+ require 'ptf/date'
5
+ require 'ptf/file_system'
6
+ require 'ptf/data_file'
7
+ require 'ptf/group'
8
+ require 'ptf/metadata_file'
6
9
  require 'ptf/commands'
7
10
 
8
11
  module Ptf
@@ -16,7 +16,7 @@ module Ptf
16
16
  LONGDESC
17
17
  option :f, :type => :boolean
18
18
  def init
19
- Ptf::Commands::Init.init(options[:f])
19
+ puts Ptf::Commands::Init.init(options[:f])
20
20
  end
21
21
 
22
22
  desc "task", "Subcommand to manage tasks"
@@ -26,8 +26,10 @@ module Ptf
26
26
  subcommand "group", Group
27
27
 
28
28
  desc "list DELIMIT", "List tasks. Given 'all' or a group name"
29
+ option :open, :type => :boolean, :aliases => :o
30
+ option :closed, :type => :boolean, :aliases => :c
29
31
  def list(delimiter)
30
- Ptf::Commands::List.list(delimiter)
32
+ puts Ptf::Commands::List.list(delimiter, options[:open], options[:closed])
31
33
  end
32
34
 
33
35
  desc "summary", "Subcommand to manage a summary of all tasks"
@@ -2,19 +2,14 @@ module Ptf
2
2
  module Cli
3
3
  class Group < Thor
4
4
 
5
- desc "group add GROUP ABBREVIATION", "Create a new group"
5
+ desc "add GROUP ABBREVIATION", "Create a new group"
6
6
  def add(group, abbrev)
7
- Ptf::Commands::Group::Add.add(group, abbrev)
7
+ puts Ptf::Commands::Group::Add.add(group, abbrev)
8
8
  end
9
9
 
10
- desc "group remove", "Remove a group"
11
- def remove
12
- puts "remove group not implemented"
13
- end
14
-
15
- desc "group transfer", "Transfer a group to another"
16
- def transfer
17
- puts "transfer group not implemented"
10
+ desc "remove GROUP", "Remove a group"
11
+ def remove(group)
12
+ puts Ptf::Commands::Group::Remove.remove(group)
18
13
  end
19
14
 
20
15
  end
@@ -2,17 +2,17 @@ module Ptf
2
2
  module Cli
3
3
  class Summary < Thor
4
4
 
5
- desc "summary create", "Create a summary"
5
+ desc "create", "Create a summary"
6
6
  def create
7
7
  puts "summary create not implemented"
8
8
  end
9
9
 
10
- desc "summary edit", "Edit summary"
10
+ desc "edit", "Edit summary"
11
11
  def edit
12
12
  puts "summary edit not implemented"
13
13
  end
14
14
 
15
- desc "summary show", "Show summary"
15
+ desc "show", "Show summary"
16
16
  def show
17
17
  puts "summary show not implemented"
18
18
  end
@@ -2,33 +2,33 @@ module Ptf
2
2
  module Cli
3
3
  class Task < Thor
4
4
 
5
- desc "task create", "Create a new task"
5
+ desc "create", "Create a new task"
6
6
  option :title, :type => :string, :required => true, :aliases => :t
7
7
  option :group, :type => :string, :aliases => :g
8
8
  option :date, :type => :string, :aliases => :d
9
9
  option :estimate, :type => :numeric, :aliases => :e
10
10
  def create
11
- Ptf::Commands::Task::Create.create(options[:title], options[:group], options[:date], options[:estimate])
11
+ puts Ptf::Commands::Task::Create.create(options[:title], options[:group], options[:date], options[:estimate])
12
12
  end
13
13
 
14
- desc "task edit ID", "Edit a task"
14
+ desc "edit ID", "Edit a task"
15
15
  def edit(id)
16
- Ptf::Commands::Task::Edit.edit(id.to_i)
16
+ puts Ptf::Commands::Task::Edit.edit(id.to_i)
17
17
  end
18
18
 
19
- desc "task show ID", "Show a task"
19
+ desc "show ID", "Show a task"
20
20
  def show(id)
21
- Ptf::Commands::Task.show(id)
21
+ puts Ptf::Commands::Task.show(id)
22
22
  end
23
23
 
24
- desc "task close ID", "Mark a task a completed"
24
+ desc "close ID", "Mark a task a completed"
25
25
  def close(id)
26
- Ptf::Commands::Task.close(id)
26
+ puts Ptf::Commands::Task.close(id)
27
27
  end
28
28
 
29
- desc "task reopen ID", "Reopen a closed task"
29
+ desc "reopen ID", "Reopen a closed task"
30
30
  def reopen(id)
31
- Ptf::Commands::Task.reopen(id)
31
+ puts Ptf::Commands::Task.reopen(id)
32
32
  end
33
33
 
34
34
  end
@@ -1,4 +1,5 @@
1
1
  require 'ptf/commands/group/add'
2
+ require 'ptf/commands/group/remove'
2
3
 
3
4
  module Ptf
4
5
  module Commands
@@ -5,41 +5,36 @@ module Ptf
5
5
  class << self
6
6
 
7
7
  def add(group, abbrev)
8
- if Ptf::Data::Group.group_exist?(group)
9
- puts "Group already exists using the name #{group}."
10
- return
11
- elsif Ptf::Data::Group.group_exist?(abbrev)
12
- puts "Group already exists using the abbreviation #{abbrev}."
13
- return
8
+ if Ptf::Group.group_exist?(group)
9
+ return "Group already exists using the name #{group}."
10
+ elsif Ptf::Group.group_exist?(abbrev)
11
+ return "Group already exists using the abbreviation #{abbrev}."
14
12
  end
15
13
 
16
14
  if abbrev.length > 4
17
- puts "Abbreviation cannot be longer than 4 characters."
18
- return
15
+ return "Abbreviation cannot be longer than 4 characters."
19
16
  end
20
17
 
21
18
  if group != group.downcase
22
- puts "Group names must be entirely lowercase."
23
- return
19
+ return "Group names must be entirely lowercase."
24
20
  elsif abbrev != abbrev.upcase
25
- puts "Group abbreviations must be entirely uppercase."
26
- return
21
+ return "Group abbreviations must be entirely uppercase."
27
22
  end
28
23
 
29
- new_group = Ptf::Data::Group.new(group, abbrev)
24
+ new_group = Ptf::Group.new(group, abbrev)
30
25
 
31
- group_file = Ptf::Utilities::FileSystem.group_list_file
26
+ group_file = Ptf::FileSystem.group_list_file
32
27
 
33
28
  File.open(group_file, 'a') { |f| f.write("#{new_group.to_s}\n") }
34
29
 
35
- open_dir = Ptf::Utilities::FileSystem.metadata_open_dir
36
- closed_dir = Ptf::Utilities::FileSystem.metadata_closed_dir
30
+ open_dir = Ptf::FileSystem.metadata_open_dir
31
+ closed_dir = Ptf::FileSystem.metadata_closed_dir
37
32
 
38
33
  [open_dir, closed_dir].each do |d|
39
- Dir.mkdir(File.join(d, new_group.name), Ptf::Utilities::FileSystem.file_permission)
34
+ Dir.mkdir(File.join(d, new_group.name), Ptf::FileSystem.file_permission)
40
35
  end
41
36
 
42
- puts "Added group #{new_group.to_s} successfully!"
37
+ return "Added group #{new_group.to_s} successfully!"
43
38
  end
44
39
 
45
40
  end
@@ -0,0 +1,52 @@
1
+ module Ptf
2
+ module Commands
3
+ module Group
4
+ module Remove
5
+ class << self
6
+
7
+ def remove(group)
8
+ if !Ptf::Group.group_exist?(group)
9
+ return "Group #{group} does not exist. Add it with ptf group add GROUP ABBREVIATION."
10
+ end
11
+
12
+ group = Ptf::Group.get_group(group)
13
+
14
+ if group.is_default?
15
+ return "#{group.to_s} is the default group. It cannot be removed."
16
+ end
17
+
18
+ # Prompt for user confirmation
19
+ puts "Are you sure you want to remove #{group.to_s}? This will delete ALL tasks associated with this group."
20
+ confirm = STDIN.gets.chomp
21
+
22
+ if confirm.downcase != "y" && confirm.downcase != "yes"
23
+ return "Group removal aborted."
24
+ end
25
+
26
+ # Remove from group_list
27
+ tmp_file = "#{Ptf::FileSystem.group_list_file}.tmp"
28
+ File.open(Ptf::FileSystem.group_list_file, "r") do |original|
29
+ File.open(tmp_file, "w") do |tmp|
30
+ original.each_line do |line|
31
+ tmp.write(line) unless line.gsub(/\s+/, "") == group.to_s
32
+ end
33
+ end
34
+ end
35
+
36
+ File.rename(tmp_file, Ptf::FileSystem.group_list_file)
37
+
38
+ # Remove from info/open/[group]
39
+ FileUtils.rm_r File.join(Ptf::FileSystem.metadata_open_dir, group.name)
40
+
41
+ # Remove from info/closed/[group]
42
+ FileUtils.rm_r File.join(Ptf::FileSystem.metadata_closed_dir, group.name)
43
+
44
+ return "Group removed."
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+
@@ -5,57 +5,56 @@ module Ptf
5
5
 
6
6
  def init(force_override = false)
7
7
 
8
- default_permissions = Ptf::Utilities::FileSystem.file_permission
9
- default_group = Ptf::Data::Group.default_group
10
- default_counter = Ptf::Utilities::FileSystem.id_counter_starting_content
8
+ default_permissions = Ptf::FileSystem.file_permission
9
+ default_group = Ptf::Group.default_group
10
+ default_counter = Ptf::FileSystem.id_counter_starting_content
11
11
 
12
- base_dir = Ptf::Utilities::FileSystem.base_dir
12
+ base_dir = Ptf::FileSystem.base_dir
13
13
 
14
+ return_prefix = ""
14
15
  if Dir.exist? base_dir
15
16
  if force_override
16
- puts "PTF workspace existed, erasing..."
17
- `rm -r #{base_dir}`
17
+ FileUtils.rm_r base_dir
18
+ return_prefix = "PTF workspace existed, erasing...\n"
18
19
  else
19
- puts "A PTF workspace has already been initialized."
20
- return
20
+ return "A PTF workspace has already been initialized."
21
21
  end
22
22
  end
23
23
 
24
24
  begin
25
25
  Dir.mkdir(base_dir, default_permissions)
26
26
 
27
- info_dir = Ptf::Utilities::FileSystem.metadata_dir
27
+ info_dir = Ptf::FileSystem.metadata_dir
28
28
  Dir.mkdir(info_dir, default_permissions)
29
29
 
30
- data_dir = Ptf::Utilities::FileSystem.data_dir
30
+ data_dir = Ptf::FileSystem.data_dir
31
31
  Dir.mkdir(data_dir, default_permissions)
32
32
 
33
- tmp_dir = Ptf::Utilities::FileSystem.tmp_dir
33
+ tmp_dir = Ptf::FileSystem.tmp_dir
34
34
  Dir.mkdir(tmp_dir, default_permissions)
35
35
 
36
- open_dir = Ptf::Utilities::FileSystem.metadata_open_dir
36
+ open_dir = Ptf::FileSystem.metadata_open_dir
37
37
  Dir.mkdir(open_dir, default_permissions)
38
38
 
39
- closed_dir = Ptf::Utilities::FileSystem.metadata_closed_dir
39
+ closed_dir = Ptf::FileSystem.metadata_closed_dir
40
40
  Dir.mkdir(closed_dir, default_permissions)
41
41
 
42
42
  Dir.mkdir(File.join(open_dir, default_group.name), default_permissions)
43
43
  Dir.mkdir(File.join(closed_dir, default_group.name), default_permissions)
44
44
 
45
- counter_file = File.new(Ptf::Utilities::FileSystem.id_counter_file, "w")
45
+ counter_file = File.new(Ptf::FileSystem.id_counter_file, "w")
46
46
  counter_file.puts default_counter
47
47
  counter_file.close
48
48
 
49
- group_file = File.new(Ptf::Utilities::FileSystem.group_list_file, "w")
49
+ group_file = File.new(Ptf::FileSystem.group_list_file, "w")
50
50
  group_file.puts default_group.to_s
51
51
  group_file.close
52
- rescue Exception => e
53
- puts "Failed to create PTF workspace."
54
- `rm -r #{base_dir}`
55
- raise e
52
+ rescue
53
+ FileUtils.rm_r base_dir
54
+ return return_prefix + "Failed to create PTF workspace."
56
55
  end
57
56
 
58
- puts "Created PTF workspace at #{base_dir} successfully!"
57
+ return return_prefix + "Created PTF workspace at #{base_dir} successfully!"
59
58
  end
60
59
 
61
60
  end
@@ -3,24 +3,41 @@ module Ptf
3
3
  module List
4
4
  class << self
5
5
 
6
- def get_metadata_for_group(group)
7
- raise ArgumentError, "Group #{group} does not exist." unless Ptf::Data::Group.group_exist?(group)
6
+ def get_metadata_for_group(group, flag)
7
+ raise ArgumentError, "Group #{group} does not exist." unless Ptf::Group.group_exist?(group)
8
8
 
9
- group_name = Ptf::Data::Group.get_group(group).name
10
- open_group_path = File.join(Ptf::Utilities::FileSystem.metadata_open_dir, group_name)
9
+ group_name = Ptf::Group.get_group(group).name
10
+ open_group_path = File.join(Ptf::FileSystem.metadata_open_dir, group_name)
11
11
  open_group_dir = Dir.new(open_group_path)
12
- # closed_group_dir = File.join(Ptf::Utilities::FileSystem.metadata_closed_dir, group)
12
+ closed_group_path = File.join(Ptf::FileSystem.metadata_closed_dir, group_name)
13
+ closed_group_dir = Dir.new(closed_group_path)
14
+
15
+ open_tasks = []
16
+ closed_tasks = []
17
+ if flag == :open || flag == :both
18
+ open_group_dir.to_a.each do |file|
19
+ path = File.join(open_group_path, file)
20
+
21
+ if File.file? path
22
+ open_tasks.push Ptf::MetadataFile.create_from_file(path)
23
+ end
24
+ end
25
+ end
13
26
 
14
- open_tasks = open_group_dir.to_a[2..-1].collect do |file|
15
- path = File.join(open_group_path, file)
27
+ if flag == :closed || flag == :both
28
+ closed_group_dir.to_a.each do |file|
29
+ path = File.join(closed_group_path, file)
16
30
 
17
- Ptf::Data::MetadataFile.create_from_file(path)
31
+ if File.file? path
32
+ closed_tasks.push Ptf::MetadataFile.create_from_file(path)
33
+ end
34
+ end
18
35
  end
19
36
 
20
- open_tasks
37
+ [open_tasks, closed_tasks]
21
38
  end
22
39
 
23
- def sort_task_arr(task_arr)
40
+ def sort_open_task_arr(task_arr)
24
41
  sorted_arr = task_arr
25
42
 
26
43
  sorted_arr.sort! do |a,b|
@@ -38,10 +55,20 @@ module Ptf
38
55
  sorted_arr
39
56
  end
40
57
 
41
- def generate_list_display(tasks)
58
+ def sort_closed_task_arr(task_arr)
59
+ sorted_arr = task_arr
60
+
61
+ sorted_arr.sort! do |a,b|
62
+ b.completed_at <=> a.completed_at
63
+ end
64
+
65
+ sorted_arr
66
+ end
67
+
68
+ def generate_list_display(open, closed)
42
69
  list_display = ""
43
70
  first = true, past_due = false, have_due_date = true
44
- tasks.each do |t|
71
+ open.each do |t|
45
72
  if have_due_date && t.due_date.nil?
46
73
  have_due_date = false
47
74
  list_display += "\n" unless first
@@ -65,23 +92,51 @@ module Ptf
65
92
  list_display += "#{t.due_date_list_format} #{t.title} (#{t.group.abbreviation} #{t.id})\n"
66
93
  end
67
94
 
95
+ show_closed_banner = true
96
+ closed.each do |t|
97
+ if show_closed_banner
98
+ list_display += "\n" unless list_display == ""
99
+ list_display += "=========== Closed ===========\n\n"
100
+ show_closed_banner = false
101
+ end
102
+
103
+ list_display += "#{t.completed_at_list_format} #{t.title} (#{t.group.abbreviation} #{t.id})\n"
104
+ end
105
+
68
106
  list_display
69
107
  end
70
108
 
71
- def list(delimiter)
72
- if delimiter.downcase == "all"
73
- puts "List all not yet implemented"
109
+ def list(delimiter, open, closed)
110
+ if open && closed
111
+ flag = :both
112
+ elsif closed
113
+ flag = :closed
74
114
  else
75
- if !Ptf::Data::Group.group_exist?(delimiter)
76
- puts "Group #{delimiter} does not exist."
77
- return
115
+ flag = :open
116
+ end
117
+
118
+ if delimiter.downcase == "all"
119
+ all_groups = Ptf::Group.all_groups
120
+
121
+ open_tasks = []
122
+ closed_tasks = []
123
+ all_groups.each do |g|
124
+ open, closed = get_metadata_for_group(g.name, flag)
125
+ open_tasks.concat open
126
+ closed_tasks.concat closed
78
127
  end
79
128
 
80
- tasks = get_metadata_for_group(delimiter)
81
- tasks = sort_task_arr(tasks)
129
+ else
130
+ if !Ptf::Group.group_exist?(delimiter)
131
+ return "Group #{delimiter} does not exist."
132
+ end
82
133
 
83
- puts generate_list_display(tasks)
134
+ open_tasks, closed_tasks = get_metadata_for_group(delimiter, flag)
84
135
  end
136
+
137
+ open_tasks = sort_open_task_arr(open_tasks)
138
+ closed_tasks = sort_closed_task_arr(closed_tasks)
139
+ return generate_list_display(open_tasks, closed_tasks)
85
140
  end
86
141
 
87
142
  end