sample_tasks 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +0 -2
- data/lib/tap/tasks/print_tree.rb +7 -11
- metadata +5 -8
- data/lib/tap/tasks/concat.rb +0 -78
- data/lib/tap/tasks/copy.rb +0 -53
- data/lib/tap/tasks/grep.rb +0 -54
data/MIT-LICENSE
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
Copyright (c) 2006-2008, Regents of the University of Colorado.
|
2
|
-
Developer:: Simon Chiang, Biomolecular Structure Program, Hansen Lab
|
3
|
-
Support:: CU Denver School of Medicine Deans Academic Enrichment Fund
|
4
2
|
|
5
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
6
4
|
software and associated documentation files (the "Software"), to deal in the Software
|
data/lib/tap/tasks/print_tree.rb
CHANGED
@@ -29,12 +29,12 @@ module Tap
|
|
29
29
|
ARM_MAP["`"] = " "
|
30
30
|
|
31
31
|
config :hidden_files, false, &c.switch # Flag to print hidden files.
|
32
|
-
|
33
|
-
def process(
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
|
33
|
+
def process(path=".", target=$stdout)
|
34
|
+
@target = target
|
35
|
+
visit(Pathname.new("."), "", "", "", Pathname.new(path))
|
36
|
+
@target = nil
|
37
|
+
target
|
38
38
|
end
|
39
39
|
|
40
40
|
# Returns true if the path is hidden. If the hidden_files
|
@@ -47,13 +47,9 @@ module Tap
|
|
47
47
|
|
48
48
|
protected
|
49
49
|
|
50
|
-
def default_task_block # :nodoc:
|
51
|
-
lambda {|line| puts line }
|
52
|
-
end
|
53
|
-
|
54
50
|
# slightly modified from the original algorithm
|
55
51
|
def visit(path, leader, tie, arm, node) # :nodoc:
|
56
|
-
|
52
|
+
@target << "#{leader}#{arm}#{tie}#{node}\n" unless hidden?(node)
|
57
53
|
visitChildren(path + node, leader + ARM_MAP[arm])
|
58
54
|
end
|
59
55
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sample_tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Chiang
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-11-02 01:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -18,9 +18,9 @@ dependencies:
|
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
|
-
- -
|
21
|
+
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.
|
23
|
+
version: "0.11"
|
24
24
|
version:
|
25
25
|
description:
|
26
26
|
email: simon.chiang@uchsc.edu
|
@@ -35,9 +35,6 @@ files:
|
|
35
35
|
- MIT-LICENSE
|
36
36
|
- README
|
37
37
|
- lib/tap/support/simple_table.rb
|
38
|
-
- lib/tap/tasks/concat.rb
|
39
|
-
- lib/tap/tasks/copy.rb
|
40
|
-
- lib/tap/tasks/grep.rb
|
41
38
|
- lib/tap/tasks/print_tree.rb
|
42
39
|
- lib/tap/tasks/table_task.rb
|
43
40
|
- tap.yml
|
@@ -63,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
60
|
requirements: []
|
64
61
|
|
65
62
|
rubyforge_project: tap
|
66
|
-
rubygems_version: 1.
|
63
|
+
rubygems_version: 1.3.0
|
67
64
|
signing_key:
|
68
65
|
specification_version: 2
|
69
66
|
summary: Sample Tap Tasks
|
data/lib/tap/tasks/concat.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'erb'
|
2
|
-
|
3
|
-
module Tap
|
4
|
-
module Tasks
|
5
|
-
# :startdoc::manifest concatenate files with formatting
|
6
|
-
#
|
7
|
-
# Concatenates a list of files into the specified target. Raises an error
|
8
|
-
# for non-existant, non-file inputs. Concat allows a variety configurable
|
9
|
-
# separators to be specified. These strings are formatted using ERB so
|
10
|
-
# that you can concat and insert text at the same time. For instance
|
11
|
-
# with source files:
|
12
|
-
#
|
13
|
-
# [one.txt]
|
14
|
-
# contents of file one
|
15
|
-
#
|
16
|
-
# [two.txt]
|
17
|
-
# contents of file two
|
18
|
-
#
|
19
|
-
# And configurations:
|
20
|
-
#
|
21
|
-
# pre: "# <%= File.basename(source) %>\n"
|
22
|
-
# post: "\n"
|
23
|
-
#
|
24
|
-
# You obtain the following:
|
25
|
-
#
|
26
|
-
# [concat.txt]
|
27
|
-
# # one.txt
|
28
|
-
# contents of file one
|
29
|
-
#
|
30
|
-
# # two.txt
|
31
|
-
# contents of file two
|
32
|
-
#
|
33
|
-
# The ERB binding (and hence each insert configuration) has access to all
|
34
|
-
# task methods and the following variables:
|
35
|
-
# target the target file
|
36
|
-
# source the current source
|
37
|
-
# sources an array of the source files
|
38
|
-
#
|
39
|
-
class Concat < Tap::FileTask
|
40
|
-
config :before, "", &c.string # string before all entries
|
41
|
-
config :pre, "", &c.string # separator before each entry
|
42
|
-
config :post, "", &c.string # separator after each entry
|
43
|
-
config :after, "", &c.string # string after all entries
|
44
|
-
|
45
|
-
# Alias for self. Allows self to be accessed within separator ERB.
|
46
|
-
def task
|
47
|
-
self
|
48
|
-
end
|
49
|
-
|
50
|
-
def process(target, *sources)
|
51
|
-
# prepare backs up the target to allow rollback on error,
|
52
|
-
# and ensures the target parent directory exists.
|
53
|
-
prepare(target)
|
54
|
-
log_basename :prepare, target
|
55
|
-
|
56
|
-
# open the output file and read the file contents
|
57
|
-
# of each input file into the output
|
58
|
-
File.open(target, "wb" ) do |output|
|
59
|
-
output << ERB.new(before).result(binding) unless before.empty?
|
60
|
-
|
61
|
-
sources.each do |source|
|
62
|
-
raise "Not a file: #{source}" unless File.exists?(source) && File.file?(source)
|
63
|
-
|
64
|
-
log_basename :concat, source
|
65
|
-
output << ERB.new(pre).result(binding) unless pre.empty?
|
66
|
-
output << File.read(source)
|
67
|
-
output << ERB.new(post).result(binding) unless post.empty?
|
68
|
-
end
|
69
|
-
|
70
|
-
output << ERB.new(after).result(binding) unless after.empty?
|
71
|
-
end
|
72
|
-
|
73
|
-
# return the concatenated file
|
74
|
-
target
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
data/lib/tap/tasks/copy.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
module Tap
|
2
|
-
module Tasks
|
3
|
-
# :startdoc::manifest copies files
|
4
|
-
#
|
5
|
-
# Copies a list of files to the specified directory. The files will
|
6
|
-
# be copied using the relative filepath from Dir.pwd, or the file
|
7
|
-
# basename if the filepath is not relative to Dir.pwd. For example:
|
8
|
-
# when copying to '/target_dir' from Dir.pwd = '/dir':
|
9
|
-
#
|
10
|
-
# source path target path
|
11
|
-
# /dir/path/to/file.txt /target_dir/path/to/file.txt
|
12
|
-
# /path/to/file.txt /target_dir/file.txt
|
13
|
-
#
|
14
|
-
# Existing files are backed up as '<file>_before_<timestamp>'
|
15
|
-
# into the standard backup directory. Up-to-date files are not copied.
|
16
|
-
# Raises an error for non-existing and non-file input files, as well
|
17
|
-
# as a non-directory target_dir.
|
18
|
-
#
|
19
|
-
class Copy < Tap::FileTask
|
20
|
-
|
21
|
-
# Determines the copy filepath using the target_dir and the
|
22
|
-
# relative filepath from Dir.pwd to path. Uses the basename
|
23
|
-
# of path if path is not relative to Dir.pwd.
|
24
|
-
def copy_filepath(target_dir, path)
|
25
|
-
relative_path = Root.relative_filepath(Dir.pwd, path) || File.basename(path)
|
26
|
-
File.join(target_dir, relative_path)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Determines a backup filepath by adding a timestamp to the input path.
|
30
|
-
def backup_filepath(path)
|
31
|
-
extname = File.extname(path)
|
32
|
-
File.expand_path("#{path.chomp(extname)}_before_#{Time.now.strftime(timestamp)}#{extname}")
|
33
|
-
end
|
34
|
-
|
35
|
-
def process(target_dir, *filepaths)
|
36
|
-
filepaths.collect do |filepath|
|
37
|
-
target = copy_filepath(target_dir, filepath)
|
38
|
-
|
39
|
-
if uptodate?(target, filepath)
|
40
|
-
log_basename :skip, filepath, Logger::DEBUG
|
41
|
-
else
|
42
|
-
prepare target
|
43
|
-
|
44
|
-
log_basename :cp, filepath
|
45
|
-
FileUtils.cp(filepath, target)
|
46
|
-
end
|
47
|
-
|
48
|
-
target
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
data/lib/tap/tasks/grep.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
module Tap
|
2
|
-
module Tasks
|
3
|
-
# :startdoc::manifest search for lines matching a pattern
|
4
|
-
#
|
5
|
-
# A simple line-matching task patterned after the *nix grep utility.
|
6
|
-
# Grep find and prints all lines matching the regexp pattern in files
|
7
|
-
# matched by the globs.
|
8
|
-
#
|
9
|
-
class Grep < Tap::Task
|
10
|
-
|
11
|
-
config :case_insensitive, false, :short => :i, &c.switch # set case-insensitive matching
|
12
|
-
config :extended, false, :short => :e, &c.switch # set extended matching
|
13
|
-
config :multiline, false, :short => :m, &c.switch # set multiline matching
|
14
|
-
config :escape, false, &c.flag # escape pattern beforehand
|
15
|
-
|
16
|
-
# Returns an array of the regexp options specified by the config.
|
17
|
-
def regexp_options
|
18
|
-
[ case_insensitive ? Regexp::IGNORECASE : nil,
|
19
|
-
extended ? Regexp::EXTENDED : nil,
|
20
|
-
multiline ? Regexp::MULTILINE : nil
|
21
|
-
].compact
|
22
|
-
end
|
23
|
-
|
24
|
-
def process(pattern, *globs)
|
25
|
-
pattern = Regexp.escape(pattern) if escape
|
26
|
-
regexp = Regexp.new(pattern, *regexp_options)
|
27
|
-
|
28
|
-
input_files = Tap::Root.glob(*globs)
|
29
|
-
input_files.each do |input_file|
|
30
|
-
next unless File.exists?(input_file) && File.file?(input_file)
|
31
|
-
|
32
|
-
File.open(input_file) do |file|
|
33
|
-
line_num = -1
|
34
|
-
file.each_line do |line|
|
35
|
-
line_num += 1
|
36
|
-
next unless line =~ regexp
|
37
|
-
task_block.call(self, input_file, line_num, line)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
input_files
|
43
|
-
end
|
44
|
-
|
45
|
-
protected
|
46
|
-
|
47
|
-
def default_task_block # :nodoc:
|
48
|
-
lambda do |task, filepath, line_num, line|
|
49
|
-
task.log "#{File.basename(filepath)} (#{line_num})", line.strip
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|