Class: Purple::PurpleCabinet

Inherits:
Object
  • Object
show all
Defined in:
lib/purple.rb,
lib/purple/osx.rb,
lib/purple/debian.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePurpleCabinet

Returns a new instance of PurpleCabinet.



16
17
18
19
20
# File 'lib/purple.rb', line 16

def initialize
    @packages = Array.new
    @urls = Hash.new
    @files = Array.new
end

Instance Attribute Details

#cabinet_dirObject (readonly)

Returns the value of attribute cabinet_dir.



22
23
24
# File 'lib/purple.rb', line 22

def cabinet_dir
  @cabinet_dir
end

#filesObject (readonly)

Returns the value of attribute files.



22
23
24
# File 'lib/purple.rb', line 22

def files
  @files
end

#long_nameObject

Returns the value of attribute long_name.



21
22
23
# File 'lib/purple.rb', line 21

def long_name
  @long_name
end

#nameObject

Returns the value of attribute name.



21
22
23
# File 'lib/purple.rb', line 21

def name
  @name
end

#packagesObject (readonly)

Returns the value of attribute packages.



22
23
24
# File 'lib/purple.rb', line 22

def packages
  @packages
end

#urlsObject (readonly)

Returns the value of attribute urls.



22
23
24
# File 'lib/purple.rb', line 22

def urls
  @urls
end

Instance Method Details

#add_url(url) ⇒ Object



51
52
53
54
55
# File 'lib/purple.rb', line 51

def add_url url
    filename = File.basename URI.parse(url).path
    @urls[filename] = url
    @files << filename
end

#assert_dir(path) ⇒ Object

##



136
137
138
139
140
141
142
# File 'lib/purple.rb', line 136

def assert_dir path
    unless FileTest.exist? path
        puts ">- Creating folder #{path}"
        Dir.mkdir path 
    end
    (FileTest.directory? path) ? path : nil
end

#build_stepObject



100
101
102
103
104
# File 'lib/purple.rb', line 100

def build_step
    @packages.each { |p|
        return false if not p.build
    }
end

#config_stepObject



94
95
96
97
98
# File 'lib/purple.rb', line 94

def config_step
    @packages.each { |p|
        return false if not p.config
    }
end

#create_packageObject

##



124
125
126
127
128
129
130
131
132
# File 'lib/purple.rb', line 124

def create_package
    p = PackageInfo.new
    class <<p
        include PackageActions
    end
    p.cabinet = self
    @packages << p
    @packages.last
end

#deployObject



119
120
121
122
123
# File 'lib/purple/osx.rb', line 119

def deploy
    packages.each do |pkg|
        system "open '#{File.join packagedir, pkg.name}.pkg'"
    end
end

#deps_stepObject



112
113
114
# File 'lib/purple.rb', line 112

def deps_step
    true
end

#fetch(filename) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/purple.rb', line 63

def fetch filename
    if not FileTest.exist? "#{filesdir}/#{filename}"
        g = Getter.new urls[filename], filesdir 
        g.get
        status = 'Getting'
        loop do
            status, done = *(g.get_status)
            printf "\015\033[MFetching %-40s %3d%%  %s", filename,  done, status
            $defout.flush
            sleep 1
            break if 'Getting' != status
        end
        puts
        throw :stop, "There was an error while fetching file #{filename}" unless 'Done' == status 
    end
end

#fetch_allObject



45
46
47
48
49
# File 'lib/purple.rb', line 45

def fetch_all
    urls.each do |url|
        Getter.get url, filesdir
    end
end

#filesdirObject

-> aString # Get source dir



25
26
27
# File 'lib/purple.rb', line 25

def filesdir
    assert_dir File.join(@cabinet_dir, 'Files')
end

#logdirObject



41
42
43
# File 'lib/purple.rb', line 41

def logdir
    assert_dir File.join(@cabinet_dir, 'Log')
end

#makeObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/purple/osx.rb', line 81

def make
    packages.each do |pkg|
        system "rm -r '#{osx_stage}'"
        File.open "#{osx_stage}/Description.plist", "w" do |f|
            f.puts pkg.description
        end

        Dir.mkdir "#{osx_stage}/Resources"

        info = ['README', 'NOTICE'].find { |f|
            FileTest.exists? File.join(pkg.srcdir, f)
        }
        if info
            FileUtils.cp File.join(pkg.srcdir, info), File.join(osx_stage, 'Resources/', 'ReadMe.txt')
        end

        license = ['COPYING', 'LICENSE'].find { |f|
            FileTest.exists? "#{pkg.srcdir}/#{f}"
        }
        if license
            FileUtils.cp "#{pkg.srcdir}/#{license}", "#{osx_stage}/Resources/License.txt"
        end

        File.open "#{osx_stage}/Info.plist", "w" do |f|
            f.print PACKAGE_INFO_TEMPLATE.call(pkg)
        end

        File.open "#{osx_stage}/Description.plist", "w" do |f|
            f.print PACKAGE_DESCRIPTION_TEMPLATE.call(pkg)
        end

        system "/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker " + 
            "-build -p '#{packagedir}/#{pkg.name}.pkg' -f '#{pkg.stage_root}' -r '#{osx_stage}/Resources' " +
            "-d '#{osx_stage}/Description.plist' -i '#{osx_stage}/Info.plist'"
    end
end

#osx_stageObject



75
76
77
78
79
# File 'lib/purple/osx.rb', line 75

def osx_stage
    assert_dir "#{@cabinet_dir}"
    assert_dir "#{@cabinet_dir}/OsxStage"
    assert_dir File.join(@cabinet_dir, 'OsxStage')
end

#packagedirObject



37
38
39
# File 'lib/purple.rb', line 37

def packagedir
    assert_dir File.join(@cabinet_dir, 'Package')
end

#prepare_stepObject



80
81
82
83
84
85
# File 'lib/purple.rb', line 80

def prepare_step
    @packages.each do |p|
        p.files.each { |f| fetch f }
        p.prepare
    end
end

#run_steps(steps = [:prepare, :setup, :build, :deps, :make]) ⇒ Object



116
117
118
119
120
# File 'lib/purple.rb', line 116

def run_steps steps=[:prepare, :setup, :build, :deps, :make]
    steps.each do |step|
        self.method("#{step}_step").call
    end
end

#setupObject



57
58
59
60
61
# File 'lib/purple.rb', line 57

def setup
    raise 'cabinet long_name not properly set' if not long_name
    @cabinet_dir = File.join(PURPLE_FOLDER, long_name)
    assert_dir @cabinet_dir
end

#setup_stepObject



87
88
89
90
91
92
# File 'lib/purple.rb', line 87

def setup_step
    @packages.each do |p|
        p.files.each { |f| fetch f }
        p.setup
    end
end

#srcdirObject



29
30
31
# File 'lib/purple.rb', line 29

def srcdir
    assert_dir File.join(@cabinet_dir, 'Source')
end

#stage_rootObject



33
34
35
# File 'lib/purple.rb', line 33

def stage_root
    assert_dir File.join(@cabinet_dir, 'StageRoot')
end

#stage_stepObject



106
107
108
109
110
# File 'lib/purple.rb', line 106

def stage_step
    @packages.each { |p|
        return false if not p.stage
    }
end

#sys(name, cmd, *args) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/purple.rb', line 144

def sys name, cmd, *args
    bars = ['  -', '  \\', '  |', '  /']
    child = Run::Child.new name, logdir, cmd, *args
    $>.print "     > #{name}\015"
    $>.flush
    child.start
    while not child.status
        $>.print bars[0] + "\015"
        $>.flush
        bars << bars.shift
        sleep 1
    end
    puts "Done"
    return(child.exit_code == 0)
end