tgfa-glynn 1.1.11

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f8820a08b0fa2b4b3883d99430f20e81a6411cad
4
+ data.tar.gz: fa61e4bbff8927aa2110caed2937f2860dd08c14
5
+ SHA512:
6
+ metadata.gz: c6316c26b9eee07f1a2820e11761e9dbb155e111adb5175028461d6363060503cec7c096e0e7c03ec4fae9fcbc747714ce2b015efe1e4744dfb8f4d0415d9121
7
+ data.tar.gz: b314028630fb32221c422aa42d538fc684e9258adcc27c334e12aee5442b35c0cb27cdd2cbfef98b40200a6262fd1104d9bdf6fc7068b0838c55dd310b7cf420
data/bin/glynn ADDED
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'jekyll'
4
+ require 'glynn'
5
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
6
+
7
+
8
+ options = {}
9
+ case ARGV.size
10
+ when 0
11
+ when 1
12
+ options['destination'] = ARGV[0]
13
+ when 2
14
+ options['source'] = ARGV[0]
15
+ options['destination'] = ARGV[1]
16
+ when 4
17
+ options['source'] = ARGV[0]
18
+ options['destination'] = ARGV[1]
19
+ options['ftp_username'] = ARGV[2]
20
+ options['ftp_password'] = ARGV[3]
21
+ end
22
+ options = Jekyll.configuration(options)
23
+ ftp_port = (options['ftp_port'] || 21).to_i
24
+ passive = options['ftp_passive'] || true
25
+
26
+ puts "Building site: #{options['source']} -> #{options['destination']}"
27
+ jekyll = Glynn::Jekyll.new
28
+ jekyll.build
29
+ puts "Successfully generated site"
30
+
31
+ puts "Sending site over FTP (host: #{options['ftp_host']}, port: #{ftp_port})"
32
+ begin
33
+ if options['ftp_username'].nil?
34
+ print "FTP Username: "
35
+ username = $stdin.gets.chomp
36
+ else
37
+ username = options['ftp_username']
38
+ end
39
+
40
+ if options['ftp_password'].nil?
41
+ print "FTP Password: "
42
+ # We hide the entered characters before to ask for the password
43
+ system "stty -echo"
44
+ password = $stdin.gets.chomp
45
+ system "stty echo"
46
+ else
47
+ password = options['ftp_password']
48
+ end
49
+ rescue NoMethodError, Interrupt
50
+ # When the process is exited, we display the characters again
51
+ # And we exit
52
+ system "stty echo"
53
+ exit
54
+ end
55
+
56
+ ftp = Glynn::Ftp.new(options['ftp_host'], ftp_port, {:username => username, :password => password, :passive => passive})
57
+ puts "\r\nConnected to server. Sending site"
58
+ ftp.sync(options['destination'], options['ftp_dir'])
59
+ puts "Successfully sent site"
data/lib/glynn/file.rb ADDED
@@ -0,0 +1,13 @@
1
+ module Glynn
2
+ class File
3
+
4
+ def self.is_bin?(f)
5
+ file_test = %x(file #{f})
6
+
7
+ # http://stackoverflow.com/a/8873922
8
+ file_test = file_test.encode('UTF-16', 'UTF-8', :invalid => :replace, :replace => '').encode('UTF-8', 'UTF-16')
9
+
10
+ file_test !~ /text/
11
+ end
12
+ end
13
+ end
data/lib/glynn/ftp.rb ADDED
@@ -0,0 +1,67 @@
1
+ require 'net/ftp'
2
+
3
+ module Glynn
4
+ class Ftp
5
+ attr_reader :host, :port, :username, :password, :passive
6
+
7
+ def initialize(host, port = 21, options = Hash.new)
8
+ options = {:username => nil, :password => nil}.merge(options)
9
+ @host, @port = host, port
10
+ @username, @password = options[:username], options[:password]
11
+ @passive = options[:passive]
12
+ end
13
+
14
+ def sync(local, distant)
15
+ connect do |ftp|
16
+ send_dir(ftp, local, distant)
17
+ end
18
+ end
19
+
20
+ private
21
+ def connect
22
+ Net::FTP.open(host) do |ftp|
23
+ ftp.passive = @passive
24
+ ftp.connect(host, port)
25
+ ftp.login(username, password)
26
+ yield ftp
27
+ end
28
+ end
29
+
30
+ def send_dir(ftp, local, distant)
31
+ begin
32
+ ftp.mkdir(distant)
33
+ rescue Net::FTPPermError
34
+ # We don't do anything. The directory already exists.
35
+ # TODO : this is also risen if we don't have write access. Then, we need to raise.
36
+ end
37
+ Dir.foreach(local) do |file_name|
38
+ # If the file/directory is hidden (first character is a dot), we ignore it
39
+ next if file_name =~ /^(\.|\.\.)$/
40
+
41
+ puts " -> " + file_name
42
+ if ::File.stat(local + "/" + file_name).directory?
43
+ # It is a directory, we recursively send it
44
+ begin
45
+ ftp.mkdir(distant + "/" + file_name)
46
+ rescue Net::FTPPermError
47
+ # We don't do anything. The directory already exists.
48
+ # TODO : this is also risen if we don't have write access. Then, we need to raise.
49
+ end
50
+ send_dir(ftp, local + "/" + file_name, distant + "/" + file_name)
51
+ else
52
+ # It's a file, we just send it
53
+ if Glynn::File.is_bin?(local + "/" + file_name)
54
+ ftp.putbinaryfile(local + "/" + file_name, distant + "/" + file_name)
55
+ else
56
+ ftp.puttextfile(local + "/" + file_name, distant + "/" + file_name)
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ private
63
+ def host_with_port
64
+ "#{host}:#{port}"
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,18 @@
1
+ require 'jekyll'
2
+
3
+ module Glynn
4
+ class Jekyll
5
+ attr_reader :site
6
+
7
+ def initialize(options = {})
8
+ @site = ::Jekyll::Site.new(::Jekyll.configuration(options))
9
+ end
10
+
11
+ #
12
+ # Builds the website in the ./_site directory.
13
+ #
14
+ def build
15
+ site.process
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Glynn
2
+ VERSION = '1.1.11'
3
+ end
data/lib/glynn.rb ADDED
@@ -0,0 +1,6 @@
1
+ $:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
2
+ require 'rubygems'
3
+
4
+ require 'glynn/jekyll'
5
+ require 'glynn/file'
6
+ require 'glynn/ftp'
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tgfa-glynn
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.11
5
+ platform: ruby
6
+ authors:
7
+ - sugeng tigefa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jekyll
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.2.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.1
55
+ description: Deploy a jekyll weblog through ftp
56
+ email: sugeng@tigefa.org
57
+ executables:
58
+ - glynn
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/glynn.rb
63
+ - lib/glynn/file.rb
64
+ - lib/glynn/ftp.rb
65
+ - lib/glynn/jekyll.rb
66
+ - lib/glynn/version.rb
67
+ - bin/glynn
68
+ homepage: https://github.com/tgfa/tgfa-glynn
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.0.2
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Deploy a jekyll weblog through ftp and ftps or sftp
92
+ test_files: []