filecamo 0.0.1 → 0.0.3

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: cc867e4a005a911f06b95fc7a483ab8321a517c3
4
- data.tar.gz: 8229c95f127d9e938ff75ea31c24a817a30099d3
3
+ metadata.gz: 9be848c7a1ffd0d7dd68b7a831c8ead63ac70d4e
4
+ data.tar.gz: e0f0b6d6ecf2d834530819d67478543d162808ce
5
5
  SHA512:
6
- metadata.gz: 2a1af293cb02a0e77998337a2c75e348f0578c3abcedf93c421ea7de885ec207141112f2465dc35ed52e7be08ed8d32f042002ae10c5c4a2d37b73341996d8fc
7
- data.tar.gz: 3f3a3363e9d00aa1006e3174ff700d643449bdf13541a892ba65f274004736d1fa3ecb9fc07ff700afd8b2afe87cf741ff9580a5db37898ae0d53072d9e86952
6
+ metadata.gz: e3dd9871ba8738d57e5ba10f943374fb4d291eaffafbdc60424d2cba7f62a7a875a47df9ee79807954212f12b88b2df41b2d1ecbfe65454c9b1f28432830e24a
7
+ data.tar.gz: fcce6592f7541729d53268719a856fa72372b73a07a864060e7b631bc6a4582cc99d76521c31b76ed9e9269e4a063b1237a5f5f38e82ec03e87621ead76d2618
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,23 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ filecamo (0.0.1)
5
+ better_bytes (~> 0.0.1)
6
+ literate_randomizer (~> 0.4.0)
7
+ ruby-filemagic (~> 0.7.1)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ better_bytes (0.0.1)
13
+ literate_randomizer (0.4.0)
14
+ ruby-filemagic (0.7.1)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ filecamo!
21
+
22
+ BUNDLED WITH
23
+ 1.12.5
data/README.md CHANGED
@@ -1 +1,28 @@
1
- # filecamo
1
+ ![Screen capture usage](img/usage.gif)
2
+
3
+ ### Installation
4
+
5
+ ```shell
6
+ gem install filecamo
7
+ ```
8
+
9
+ ### Generating Files
10
+
11
+ Filecamo can generate any number of binary or text files, automatically generating a deep directory
12
+ tree of random content and size. This is an excellent way to establish a corpus of files to use when
13
+ testing various upload or download services.
14
+
15
+ ### Changing Files
16
+
17
+ Filecamo can intelligently insert new lines into text files, complete with prefixing the lines with
18
+ language-aware comment prefixes. This is an excellent way to conditionally modify some sets of files
19
+ when testing various change management or source control systems.
20
+
21
+ Currently, the following is a list of content languages Filecamo will detect:
22
+
23
+ * Ruby
24
+ * Python
25
+ * Javascript
26
+ * C#
27
+ * Shell
28
+ * HTML
data/bin/filecamo CHANGED
@@ -3,6 +3,10 @@
3
3
  require_relative '../lib/filecamo'
4
4
 
5
5
  BN = File.basename($0, '.rb')
6
+ usage = "usage: #{BN} [--debug]"
7
+
8
+ logger = Logger.new($stdout)
9
+ logger.level = ARGV.delete('--debug') ? Logger::DEBUG : Logger::INFO
6
10
 
7
11
  cmd = ARGV.shift
8
12
  if cmd == 'gen'
@@ -17,7 +21,7 @@ if cmd == 'gen'
17
21
 
18
22
  $stderr.puts <<EOF
19
23
 
20
- usage: #{BN} gen [-d <destination_path>] <minimum_size> <maximum_size> <count> <depth> [<percent_text>]
24
+ #{usage} gen [-d <destination_path>] <minimum_size> <maximum_size> <count> <depth> [<percent_text>]
21
25
 
22
26
  The size MAY end with a unit label:
23
27
  * BINARY labels (#{bm} multiplier): #{bin.join(', ')}
@@ -36,24 +40,27 @@ EOF
36
40
  end
37
41
 
38
42
  min, max, count, depth, percent_text = ARGV
39
- generator = Filecamo::Generator.new
43
+ generator = Filecamo::Generator.new(logger: logger)
40
44
  generator.generate(min, max, count, depth,
41
45
  percent_text: percent_text, destination_path: dst_path) do |path, len|
42
46
  puts "#{BetterBytes.humanize(len, precision: 6.1)} => #{path}"
43
47
  end
48
+ msg_len = 0
44
49
  generator.wait do |txt_count, bin_count|
45
- $stdout.printf "\rWaiting for #{txt_count} txt and #{bin_count} bin jobs "\
46
- "to complete..." + (' '*10)
50
+ msg = "\rWaiting for #{txt_count} txt and #{bin_count} bin jobs to complete..."
51
+ $stdout.printf(msg + (' ' * msg_len))
47
52
  $stdout.flush
53
+ msg_len = msg.size
48
54
  end
49
- $stdout.puts
55
+ $stdout.printf("\r" + (' ' * msg_len) + "\r")
50
56
  generator.kill
57
+ puts generator.stats
51
58
 
52
59
  elsif cmd == 'muck'
53
60
  if ARGV.size < 3
54
61
  $stderr.puts <<EOF
55
62
 
56
- usage: #{BN} muck <percent_select> <percent_change> <path> [<path>...]
63
+ #{usage} muck <percent_select> <percent_change> <path> [<path>...]
57
64
 
58
65
  The percent select should be a value from 1 to 100 indicating how likely a given file will be
59
66
  modified.
@@ -69,15 +76,16 @@ EOF
69
76
  end
70
77
 
71
78
  percent_select, percent_change, *paths = ARGV
72
- mucker = Filecamo::TextMucker.new(" #{BN}: ")
79
+ mucker = Filecamo::TextMucker.new(" #{BN}: ", logger: logger)
73
80
  mucker.muck(percent_select, percent_change, paths) do |fn, lang, line_nums|
74
81
  puts "Modified #{fn} (#{lang}): #{line_nums.join(',')}"
75
82
  end
83
+ puts mucker.stats
76
84
 
77
85
  else
78
86
  $stderr.puts <<EOF
79
87
 
80
- usage: #{BN} { gen | muck } ...
88
+ #{usage} { gen | muck } ...
81
89
 
82
90
  EOF
83
91
  exit 1
File without changes
data/img/usage.gif ADDED
Binary file
data/lib/filecamo.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Filecamo
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.3'
3
3
  end
4
4
 
5
5
  require_relative './filecamo/generator'
@@ -13,6 +13,7 @@ module Filecamo
13
13
  @gen = Random.new
14
14
  @logger = logger
15
15
  @words_generated = {}
16
+ @stats = {txt: 0, bin: 0}
16
17
 
17
18
  @txt_work_q = SizedQueue.new(txt_workers[:queue_size])
18
19
  @txt_workers = start_workers(:txt, @txt_work_q, txt_workers[:count]) do |file, len|
@@ -21,6 +22,7 @@ module Filecamo
21
22
  line.slice!(len..-1)
22
23
  len -= file.write(line)
23
24
  end
25
+ @stats[:txt] += 1
24
26
  end
25
27
 
26
28
  @bin_work_q = SizedQueue.new(bin_workers[:queue_size])
@@ -28,9 +30,12 @@ module Filecamo
28
30
  while len > 0
29
31
  len -= file.write(@gen.bytes(len < 32768 ? len : 32768))
30
32
  end
33
+ @stats[:bin] += 1
31
34
  end
32
35
  end
33
36
 
37
+ attr_reader :stats
38
+
34
39
  def generate(min, max, count, depth, percent_text: 0, destination_path: nil, &block)
35
40
  min = BetterBytes.dehumanize(min)
36
41
  max = BetterBytes.dehumanize(max)
@@ -2,6 +2,8 @@ require 'logger'
2
2
  require 'filemagic'
3
3
  require 'literate_randomizer'
4
4
 
5
+ # TODO: add option to change existing markers instead (or in addition to?) adding lines
6
+
5
7
  module Filecamo
6
8
  class TextMucker
7
9
  MAX_FILE_SIZE = 128 * 1024
@@ -15,21 +17,17 @@ module Filecamo
15
17
  plain: '#',
16
18
  }
17
19
 
18
- # todo: fix parsable types, somethign like the following
19
- # (figure out how to insert, perhaps deep iterater and counters?)
20
- # (figure out types to insert, (i.e. would be bad to insert string into number array))
21
- LANG_PARSERS = {
22
- json: ->(fn){}
23
- }
24
-
25
20
  def initialize(comment_prefix, logger: Logger.new($stdout))
26
21
  @marks = LANG_MARKS.clone
27
22
  @marks.each_value{|m| m << comment_prefix}
28
23
  @logger = logger
29
24
  @magic = FileMagic.new
30
25
  @mime = FileMagic.mime
26
+ @stats = {files_selected: 0, lines_added: 0}
31
27
  end
32
28
 
29
+ attr_reader :stats
30
+
33
31
  def muck(percent_select, percent_lines, paths)
34
32
  select_chance = percent_select.to_f / 100
35
33
  lines_chance = percent_lines.to_f / 100
@@ -82,6 +80,8 @@ module Filecamo
82
80
  next
83
81
  end
84
82
 
83
+ @stats[:files_selected] += 1
84
+
85
85
  new_lines = {}
86
86
  new_bytes_needed = (fn_size * lines_chance).floor
87
87
  while new_bytes_needed > 0
@@ -91,6 +91,7 @@ module Filecamo
91
91
  new_bytes_needed -= new_line.bytesize
92
92
  end
93
93
  new_lines = new_lines.sort
94
+ @stats[:lines_added] += new_lines.size
94
95
 
95
96
  body = ''
96
97
  line_nums = []
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filecamo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Robel-Forrest
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-01 00:00:00.000000000 Z
11
+ date: 2016-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: better_bytes
@@ -60,9 +60,12 @@ executables:
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
+ - Gemfile
64
+ - Gemfile.lock
63
65
  - README.md
64
66
  - bin/filecamo
65
- - filecamo.gempec
67
+ - filecamo.gemspec
68
+ - img/usage.gif
66
69
  - lib/filecamo.rb
67
70
  - lib/filecamo/generator.rb
68
71
  - lib/filecamo/text_mucker.rb