lib/fig/repository.rb in fig-0.1.8 vs lib/fig/repository.rb in fig-0.1.9

- old
+ new

@@ -8,33 +8,46 @@ @remote_repository_url = remote_repository_url @remote_repository_user = remote_repository_user @update = update @update_if_missing = update_if_missing @parser = Parser.new + + @overrides = {} + if File.exist?('fig.properties') + File.readlines('fig.properties').each do |line| + descriptor, path = line.strip.split('=') + @overrides[descriptor] = path + end + end end def clean(package_name, version_name) dir = File.join(@local_repository_dir, package_name) dir = File.join(dir, version_name) if version_name FileUtils.rm_rf(dir) end def list_packages results = [] - @os.list(@local_repository_dir).each do |package_name| - @os.list(File.join(@local_repository_dir, package_name)).each do |version_name| - results << "#{package_name}/#{version_name}" + if File.exist?(@local_repository_dir) + @os.list(@local_repository_dir).each do |package_name| + @os.list(File.join(@local_repository_dir, package_name)).each do |version_name| + results << "#{package_name}/#{version_name}" + end end end results end + def list_remote_packages + @os.download_list(@remote_repository_url) + end + def publish_package(package_statements, package_name, version_name) temp_dir = temp_dir_for_package(package_name, version_name) @os.clear_directory(temp_dir) fig_file = File.join(temp_dir, ".fig") - config_mapping = get_config_mapping(package_statements) content = bundle_resources(package_statements).map do |statement| if statement.is_a?(Publish) nil elsif statement.is_a?(Archive) || statement.is_a?(Resource) if statement.is_a?(Resource) && !is_url?(statement.url) @@ -50,33 +63,19 @@ else archive_local = statement.url end @os.upload(archive_local, archive_remote, @remote_repository_user) statement.class.new(archive_name).unparse('') - elsif statement.is_a?(Configuration) - remote_name = config_mapping[statement.name] - if remote_name - statement.with_name(remote_name).unparse('') - else - nil - end else statement.unparse('') end end.select {|s|not s.nil?} @os.write(fig_file, content.join("\n").strip) @os.upload(fig_file, remote_fig_file_for_package(package_name, version_name), @remote_repository_user) # update_package(package_name, version_name) end - def get_config_mapping(package_statements) - publish_mappings = {} - package_statements.each{|s| publish_mappings[s.local_name] = s.remote_name if s.is_a?(Publish) } - publish_mappings - end - - def bundle_resources(package_statements) resources = [] new_package_statements = package_statements.reject do |statement| if statement.is_a?(Resource) && !is_url?(statement.url) resources << statement.url @@ -118,11 +117,18 @@ content = @os.read_url(url) @parser.parse_package(package_name, version_name, nil, content) end def read_package_from_directory(dir, package_name, version_name) - read_package_from_file(File.join(dir, ".fig"), package_name, version_name) + file = File.join(dir, ".fig") + if not File.exist?(file) + file = File.join(dir, "package.fig") + end + if not File.exist?(file) + raise "File not found: #{file}" + end + read_package_from_file(file, package_name, version_name) end def read_package_from_file(file_name, package_name, version_name) if not @os.exist?(file_name) $stderr.puts "Package not found: #{package_name}/#{version_name}" @@ -132,10 +138,17 @@ content = @os.read(file_name) @parser.parse_package(package_name, version_name, File.dirname(file_name), content) end def local_dir_for_package(package_name, version_name) - File.join(@local_repository_dir, package_name, version_name) + descriptor = "#{package_name}/#{version_name}" + dir = @overrides[descriptor] + if dir + $stderr.puts "override: #{descriptor}=#{dir}" + else + dir = File.join(@local_repository_dir, package_name, version_name) + end + dir end private def install_package(package_name, version_name)