pakman 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,10 +2,51 @@
2
2
 
3
3
  * [geraldb.github.com/pakman](http://geraldb.github.com/pakman)
4
4
 
5
- ## Usage
5
+ ## Usage - Ruby Code
6
6
 
7
- TBD
7
+ Fetch a template pack:
8
8
 
9
+ ```ruby
10
+ Pakman::Fetcher.new( logger ).fetch_pak( src, pakpath )
11
+ ```
12
+
13
+ Copy a template pack from your cache:
14
+
15
+ ```ruby
16
+ Pakman::Copier.new( logger ).copy_pak( src, pakpath )
17
+ ```
18
+
19
+ List all template packs in your cache (using passed in search path):
20
+
21
+ ```ruby
22
+ patterns = [
23
+ "#{File.expand_path('~/.pak')}/*.txt",
24
+ "#{File.expand_path('~/.pak')}/*/*.txt",
25
+ "*.txt",
26
+ "*/*.txt"
27
+ ]
28
+
29
+ Pakman::Finder.new( logger ).find_manifests( patterns )
30
+ ```
31
+
32
+
33
+ ## Usage - Command Line
34
+
35
+ The `pakman` gem includes a little command line tool. Try `pakman -h` for details:
36
+
37
+ ```
38
+ pakman - Lets you manage template packs.
39
+
40
+ Usage: pakman [options]
41
+ -f, --fetch URI Fetch Templates
42
+ -t, --template MANIFEST Generate Templates
43
+ -l, --list List Installed Templates
44
+ -c, --config PATH Configuration Path (default is ~/.pak)
45
+ -o, --output PATH Output Path (default is .)
46
+ -v, --version Show version
47
+ --verbose Show debug trace
48
+ -h, --help Show this message
49
+ ```
9
50
 
10
51
  ## Install
11
52
 
@@ -21,8 +21,12 @@ class List
21
21
  end
22
22
  puts ' include:'
23
23
 
24
- manifests.each do |manifest|
25
- puts "%16s (%s)" % [manifest[0], manifest[1]]
24
+ if manifests.empty?
25
+ puts " -- none --"
26
+ else
27
+ manifests.each do |manifest|
28
+ puts "%16s (%s)" % [manifest[0], manifest[1]]
29
+ end
26
30
  end
27
31
  end
28
32
 
@@ -26,7 +26,12 @@ module ManifestHelper
26
26
  end
27
27
 
28
28
  def installed_template_manifests
29
- Finder.new( logger ).find_manifests( installed_template_manifest_patterns )
29
+ excludes = [
30
+ "Manifest.txt",
31
+ "*/Manifest.txt"
32
+ ]
33
+
34
+ Finder.new( logger ).find_manifests( installed_template_manifest_patterns, excludes )
30
35
  end
31
36
 
32
37
  end # module ManifestHelper
@@ -10,26 +10,37 @@ class Copier
10
10
 
11
11
  def copy_pak( manifestsrc, pakpath )
12
12
 
13
+ start = Time.now
14
+
15
+ # downcase and remove .txt (if anywhere in name)
16
+ # e.g. welcome.quick.txt becomes welcome.quick
17
+ # welcome.txt.quick becomse welcome.quick
18
+ pakname = File.basename( manifestsrc ).downcase.gsub( '.txt', '' )
19
+
20
+ puts "Copying template pack '#{pakname}'"
21
+
13
22
  manifest = Manifest.load_file( logger, manifestsrc )
14
23
 
15
24
  # expand output path in current dir (if relative) and make sure output path exists
16
25
  outpath = File.expand_path( pakpath )
17
26
  logger.debug "outpath=#{outpath}"
18
- FileUtils.makedirs( outpath ) unless File.directory? outpath
27
+ FileUtils.makedirs( outpath ) unless File.directory?( outpath )
19
28
 
20
29
  manifest.each do |entry|
21
30
  dest = entry[0]
22
31
  source = entry[1]
23
32
 
24
- puts "Copying to #{dest} from #{source}..."
33
+ puts " Copying to #{dest} from #{source}..."
25
34
  FileUtils.copy( source, with_output_path( dest, outpath ) )
26
35
  end
27
36
 
28
- puts "Done."
37
+ puts "Done (in #{Time.now-start} s)."
29
38
  end # method copy_pak
30
39
 
31
40
  private
32
41
 
42
+ ############################
43
+ ## fix/todo: cleanup needed
33
44
  ## fix: remove with_output_path helper (code it directly w/o helper)
34
45
 
35
46
  def with_output_path( dest, output_path )
@@ -11,6 +11,8 @@ class Fetcher
11
11
 
12
12
  def fetch_pak( manifestsrc, pakpath )
13
13
 
14
+ start = Time.now
15
+
14
16
  # src = 'http://github.com/geraldb/slideshow/raw/d98e5b02b87ee66485431b1bee8fb6378297bfe4/code/templates/fullerscreen.txt'
15
17
  # src = 'http://github.com/geraldb/sandbox/raw/13d4fec0908fbfcc456b74dfe2f88621614b5244/s5blank/s5blank.txt'
16
18
  uri = URI.parse( manifestsrc )
@@ -18,22 +20,25 @@ class Fetcher
18
20
  logger.debug "scheme: #{uri.scheme}, host: #{uri.host}, port: #{uri.port}, path: #{uri.path}"
19
21
 
20
22
  dirname = File.dirname( uri.path )
21
- basename = File.basename( uri.path, '.*' ) # e.g. fullerscreen (without extension)
22
23
  filename = File.basename( uri.path ) # e.g. fullerscreen.txt (with extension)
23
24
 
24
- logger.debug "dirname: #{dirname}"
25
- logger.debug "basename: #{basename}, filename: #{filename}"
25
+ # downcase and remove .txt (if anywhere in name)
26
+ # e.g. welcome.quick.txt becomes welcome.quick
27
+ # welcome.txt.quick becomse welcome.quick
28
+ pakname = File.basename( uri.path ).downcase.gsub( '.txt', '' )
29
+
30
+ logger.debug "dirname >#{dirname}<"
31
+ logger.debug "pakname >#{pakname}<, filename >#{filename}<"
26
32
 
27
33
  dlbase = "#{uri.scheme}://#{uri.host}:#{uri.port}#{dirname}"
28
-
29
34
  logger.debug "dlpath: #{dlbase}"
30
35
  logger.debug "pakpath: #{pakpath}"
31
-
32
- FileUtils.makedirs( pakpath ) unless File.directory? pakpath
33
-
34
- puts "Fetching template package '#{basename}'"
35
- puts " : from '#{dlbase}'"
36
- puts " : saving to '#{pakpath}'"
36
+
37
+ FileUtils.makedirs( pakpath ) unless File.directory?( pakpath )
38
+
39
+ puts "Fetching template pack '#{pakname}'"
40
+ puts " from '#{dlbase}'"
41
+ puts " saving to '#{pakpath}'"
37
42
 
38
43
  # download manifest
39
44
  dest = "#{pakpath}/#{filename}"
@@ -52,7 +57,7 @@ class Fetcher
52
57
 
53
58
  # make sure path exists
54
59
  destpath = File.dirname( dest )
55
- FileUtils.makedirs( destpath ) unless File.directory? destpath
60
+ FileUtils.makedirs( destpath ) unless File.directory?( destpath )
56
61
 
57
62
  src = "#{dlbase}/#{file}"
58
63
 
@@ -60,7 +65,7 @@ class Fetcher
60
65
  fetch_file( src, dest )
61
66
  end
62
67
  end
63
- puts "Done."
68
+ puts "Done (in #{Time.now-start} s)."
64
69
  end # method fetch_pak
65
70
 
66
71
  private
@@ -8,20 +8,39 @@ class Finder
8
8
  @logger = logger
9
9
  end
10
10
 
11
- def find_manifests( patterns )
11
+ def find_manifests( patterns, excludes=[] )
12
12
  manifests = []
13
13
 
14
14
  patterns.each do |pattern|
15
15
  pattern.gsub!( '\\', '/') # normalize path; make sure all path use / only
16
- logger.debug "Checking #{pattern}"
16
+ logger.debug "Checking >#{pattern}<"
17
17
  Dir.glob( pattern ) do |file|
18
- logger.debug " Found manifest: #{file}"
19
- manifests << [ File.basename( file ), file ]
18
+ logger.debug " Found manifest candidate >#{file}<"
19
+ if File.directory?( file ) # NB: do not include directories
20
+ logger.debug " Skipping match; it's a directory"
21
+ else
22
+ unless exclude?( file, excludes ) # check for excludes; skip if excluded
23
+ logger.debug " Adding match >#{file}<"
24
+ manifests << [ File.basename( file ), file ]
25
+ end
26
+ end
20
27
  end
21
28
  end
22
29
 
23
30
  manifests
24
31
  end
32
+
33
+ private
34
+ def exclude?( file, excludes )
35
+ excludes.each do |pattern|
36
+ ## todo: FNM_DOTMATCH helps or not?? (make up some tests??)
37
+ if File.fnmatch?( pattern, file, File::FNM_CASEFOLD | File::FNM_DOTMATCH )
38
+ logger.debug " Skipping match; it's excluded by pattern >#{pattern}<"
39
+ return true
40
+ end
41
+ end
42
+ false
43
+ end
25
44
 
26
45
  end # class Finder
27
46
  end # module Pakman
@@ -1,3 +1,3 @@
1
1
  module Pakman
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pakman
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gerald Bauer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-18 00:00:00 Z
18
+ date: 2012-06-19 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: fetcher