Class: AtkPackage

Inherits:
Object
  • Object
show all
Defined in:
lib/atk/atk_info.rb

Instance Method Summary collapse

Constructor Details

#initialize(package_name) ⇒ AtkPackage

Returns a new instance of AtkPackage.



144
145
146
# File 'lib/atk/atk_info.rb', line 144

def initialize(package_name)
    @init_name = package_name
end

Instance Method Details

#cache_locationObject



199
200
201
202
203
204
# File 'lib/atk/atk_info.rb', line 199

def cache_location()
    if @cache_location == nil
        @cache_location = Atk.paths['repos']/self.cache_name
    end
    return @cache_location
end

#cache_nameObject



188
189
190
191
192
193
194
195
196
197
# File 'lib/atk/atk_info.rb', line 188

def cache_name()
    if @cache_name == nil
        repo_url = self.url()
        require 'digest'
        repo_hash = Digest::MD5.hexdigest(repo_url)
        repo_name = Git.repo_name(repo_url)
        @cache_name = repo_name+"_"+repo_hash
    end
    return @cache_name
end

#ensure_cachedObject



206
207
208
209
210
211
# File 'lib/atk/atk_info.rb', line 206

def ensure_cached()
    if @is_cached == nil
        Git.ensure_cloned_and_up_to_date(self.cache_location, self.url)
        @is_cached = true
    end
end

#run(arguments) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/atk/atk_info.rb', line 213

def run(arguments)
    # make sure the repo is downloaded
    self.ensure_cached()
    FS.in_dir(self.cache_location) do
        run_command = nil
        begin
            run_command = Info["(installer)"]["(commands)"]["(run)"]
        rescue
        end
        if run_command.is_a?(String)
            system(run_command + Console.make_arguments_appendable(arguments))
        else
            # 
            # refine the error message
            # 
            custom_message = ""
            if run_command != nil && ( !run_command.is_a?(String) )
                custom_message = "✖ the (run) command wasn't a string".red
            else
                yaml_exists = File.exist?(self.cache_location()/"info.yaml")
                
                if not yaml_exists
                    custom_message = "✖ there was no info.yaml for this package".red
                else
                    error_loading_yaml = false
                    begin
                        YAML.load_file("./info.yaml")
                    rescue
                        error_loading_yaml = true
                    end
                    if error_loading_yaml
                        custom_message = "✖ there was an issue loading the info.yaml for this package".red
                    else
                        if run_command == nil
                            custom_message = "✖ there wasn't an (installer) key with a run command".red
                        end
                    end
                end
            end
            
            # throw error for command not being runable
            raise "                \n                \n                \#{custom_message}\n                \n                For the repository to be runnable\n                1. There needs to be an \#{\"info.yaml\".blue}\n                2. The info.yaml needs to be in the root directory/folder\n                3. It needs to contain:\n                \#{\"\n                (installer):\n                    (commands):\n                        (run): \\\"a commandline command\\\"\n                \".blue}\n            HEREDOC\n        end\n    end\nend\n".remove_indent

#simple_nameObject



148
149
150
151
152
153
154
155
156
157
# File 'lib/atk/atk_info.rb', line 148

def simple_name
    if @simple_name == nil
        source = @init_name.strip
        # if its starts with "atk/", just remove that part
        source = source.sub( /^atk\//, "" )
        # if it starts with "https://github.com/", just remove that part
        @simple_name = source.sub( /^https:\/\/github.com\//, "" )
    end
    return @simple_name
end

#urlObject



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/atk/atk_info.rb', line 159

def url
    if @url == nil
        simple_name = self.simple_name()
        # if the package name does not have a slash in it, then assume it is a core / approved installer
        if not (simple_name =~ /.*\/.*/) 
            # TODO: turn this into a check for is_core_repo?(package_name)
            # path_to_core_listing = Atk.paths[:core_yaml]
            # core = YAML.load_file(path_to_core_listing)
            # if core[package_name] == nil
            #     puts "I don't see that package in the core, let me make sure I have the latest info"
            #     download("https://raw.githubusercontent.com/aggie-tool-kit/atk/master/interface/core.yaml", as: path_to_core_listing)
            #     core = YAML.load_file(path_to_core_listing)
            # end
            # if core[package_name] != nil
            #     repo_url = core[package_name]["source"]
            # else
                raise "That package #{@init_name} doesn't seem to be a core package"
            # end
        # if it does have a slash, and isn't a full url, then assume its a github repo
        elsif not simple_name.start_with?(/https?:\/\//)
            repo_url = "https://github.com/"+simple_name
        else
            repo_url = simple_name
        end
        @url = repo_url
    end
    return @url
end