packagit 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Brice Texier
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Packagit
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'packagit'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install packagit
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ git_path = File.expand_path('../../.git', __FILE__)
4
+ if File.exist?(git_path)
5
+ packagit_path = File.expand_path('../../lib', __FILE__)
6
+ $:.unshift(packagit_path)
7
+ end
8
+
9
+ require 'packagit'
10
+ task = Packagit::Executable.new(ARGV)
11
+ task.invoke!
@@ -0,0 +1,6 @@
1
+ require "packagit/version"
2
+
3
+ module Packagit
4
+ autoload :Executable, 'packagit/executable'
5
+ autoload :Specification, 'packagit/specification'
6
+ end
@@ -0,0 +1,132 @@
1
+ require 'pathname'
2
+ require 'optparse'
3
+ require 'yaml'
4
+ require 'fileutils'
5
+ require 'active_support/core_ext'
6
+
7
+ module Packagit
8
+
9
+ class Executable
10
+
11
+ RELEASES_DIR = 'pkg'
12
+
13
+ def initialize(argv)
14
+ pwd = Pathname.new(Dir.pwd)
15
+ @config = pwd.join(".packagit")
16
+ version = "undefined"
17
+ if @config.exist?
18
+ if @specification = Packagit::Specification.load(@config)
19
+ version = @specification.version
20
+ end
21
+ end
22
+ @options = {
23
+ checksums: true,
24
+ releases: pwd.join(RELEASES_DIR, version),
25
+ packagers: pwd.join("packagers"),
26
+ tmp: pwd.join("tmp", "packagit")
27
+ }
28
+ optparse = OptionParser.new do |opts|
29
+ opts.banner = "Usage: packagit [options]"
30
+ opts.on('-s', '--[no-]checksums', "Compute check sums (default: #{@options[:checksums]})") do |cs|
31
+ @options[:checksums] = cs
32
+ end
33
+ opts.on('-b', '--builds BUILD[,...]', 'Select builds') do |builds|
34
+ @options[:builds] ||= []
35
+ @options[:builds] += builds.split(/[\,[[:space:]]]+/)
36
+ end
37
+ opts.on('-p', '--packagers PATH', "Define packagers directory (default: #{@options[:packagers]})") do |path|
38
+ @options[:packagers] = Pathname.new(File.expand_path(path))
39
+ end
40
+ opts.on('-r', '--releases PATH', "Define releases directory (default: #{@options[:releases]})") do |path|
41
+ @options[:releases] = Pathname.new(File.expand_path(path))
42
+ end
43
+ opts.on('-t', '--tmp PATH', "Define temporary directory (default: #{@options[:tmp]})") do |path|
44
+ @options[:tmp] = Pathname.new(path).expand_path
45
+ end
46
+ opts.on('-h', '--help', 'Display this screen') do
47
+ puts opts
48
+ exit
49
+ end
50
+ end
51
+ optparse.parse!
52
+
53
+ unless @specification
54
+ puts "Need a config file (.packagit)"
55
+ exit(1)
56
+ end
57
+
58
+ unless @builds = @options.delete(:builds)
59
+ @builds ||= []
60
+ if @options[:packagers].exist?
61
+ Dir.chdir(@options[:packagers]) do
62
+ @builds += Dir.glob("*")
63
+ end
64
+ end
65
+ end
66
+ @builds.sort!
67
+ end
68
+
69
+ def invoke!
70
+ exit(0) if @builds.empty?
71
+
72
+ FileUtils.rm_rf(@options[:tmp])
73
+
74
+ # Prepare a clean export of the files
75
+ reference = @options[:tmp].join("reference")
76
+ FileUtils.mkdir_p(reference)
77
+
78
+ for file in @specification.files
79
+ source = Pathname.new(file).expand_path
80
+ dest = reference.join(file)
81
+ FileUtils.mkdir_p(dest.dirname)
82
+ FileUtils.cp(source, dest) unless source.directory?
83
+ end
84
+
85
+ FileUtils.rm_rf(@options[:releases])
86
+
87
+ # Launch builds
88
+ STDOUT.sync = true
89
+ now = Time.now
90
+ builds_dir = @options[:tmp].join("builds")
91
+ for build in @builds
92
+ print "Build #{build}... "
93
+ build_dir = builds_dir.join(build)
94
+ FileUtils.mkdir_p(build_dir.dirname)
95
+ FileUtils.cp_r(reference, build_dir)
96
+ script = @options[:packagers].join(build).join("build")
97
+ release = @options[:releases].join(build)
98
+ FileUtils.mkdir_p(release)
99
+ command = "BUILD_APP=#{@specification.name}"
100
+ command << " BUILD_VERSION=#{@specification.version}"
101
+ command << " BUILD_DIR=#{build_dir}"
102
+ command << " BUILD_TYPE=#{build}"
103
+ command << " BUILD_LOG=#{builds_dir.join(build + '.log')}"
104
+ command << " BUILD_RELEASE=#{release}"
105
+ command << " #{script} > source.log"
106
+ if script.exist?
107
+ puts command
108
+ `#{command}`
109
+ else
110
+ puts "No script! (#{command})"
111
+ end
112
+ unless release.exist?
113
+ File.write(@options[:releases].join(build, ".placeholder"), "#{@specification.name} #{@specification.version} #{build}")
114
+ end
115
+ end
116
+
117
+ if @options[:checksums]
118
+ Dir.chdir(@options[:releases]) do
119
+ files = `find . -type f`.split(/\s+/)
120
+ for algo in %w(sha256 sha1 md5)
121
+ command = "#{algo}sum #{files.join(' ')} > " + @options[:releases].join("#{algo.upcase}SUMS").to_s
122
+ puts command
123
+ system(command)
124
+ end
125
+ end
126
+ end
127
+
128
+ end
129
+
130
+ end
131
+
132
+ end
@@ -0,0 +1,53 @@
1
+ require 'active_support/core_ext'
2
+
3
+ module Packagit
4
+
5
+ class Specification
6
+ attr_accessor :name, :version, :files, :loaded_from
7
+
8
+ REQUIREDS = [:name, :version]
9
+
10
+ def initialize(&block)
11
+ unless block_given?
12
+ raise ArgumentError, "Block must be given"
13
+ end
14
+ yield(self)
15
+ for required in REQUIREDS
16
+ if self.send(required).blank?
17
+ raise ArgumentError, "#{required} must be given (#{self.class.name})"
18
+ end
19
+ end
20
+ end
21
+
22
+
23
+ # Widely inspired from rubygems
24
+ def self.load(file)
25
+ code = if defined? Encoding
26
+ File.read(file, :mode => 'r:UTF-8:-')
27
+ else
28
+ File.read(file)
29
+ end
30
+
31
+ code.untaint
32
+
33
+ begin
34
+ spec = eval(code, binding, file.to_s)
35
+
36
+ if Packagit::Specification === spec
37
+ spec.loaded_from = File.expand_path file.to_s
38
+ return spec
39
+ end
40
+
41
+ warn "[#{file}] isn't a Packagit::Specification (#{spec.class} instead)."
42
+ rescue SignalException, SystemExit
43
+ raise
44
+ rescue SyntaxError, Exception => e
45
+ warn "Invalid packagit in [#{file}]: #{e}"
46
+ end
47
+
48
+ return nil
49
+ end
50
+
51
+ end
52
+
53
+ end
@@ -0,0 +1,3 @@
1
+ module Packagit
2
+ VERSION = "0.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: packagit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brice Texier
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-01-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>'
20
+ - !ruby/object:Gem::Version
21
+ version: '2.3'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>'
28
+ - !ruby/object:Gem::Version
29
+ version: '2.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Build packages
63
+ email:
64
+ - burisu@oneiros.fr
65
+ executables:
66
+ - packagit
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - LICENSE.txt
71
+ - README.md
72
+ - bin/packagit
73
+ - lib/packagit.rb
74
+ - lib/packagit/executable.rb
75
+ - lib/packagit/specification.rb
76
+ - lib/packagit/version.rb
77
+ homepage: ''
78
+ licenses:
79
+ - MIT
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 1.8.23
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Build packages
102
+ test_files: []