Module: PgxnUtils::NoTasks
Constant Summary
Constants included from Constants
Instance Method Summary collapse
- #ask_for_pgxn_credential ⇒ Object
- #can_zip?(archive) ⇒ Boolean
- #check_response(response) ⇒ Object
- #config_options ⇒ Object
- #has_scm?(path) ⇒ Boolean
- #init_repository(extension_dir) ⇒ Object
- #is_dir?(dir) ⇒ Boolean
- #is_dirty?(extension_dir) ⇒ Boolean
- #is_extension?(dir = ".") ⇒ Boolean
- #make_dist_clean(path) ⇒ Object
- #prepare_multipart_post_for(filename) ⇒ Object
- #resolve_extension_path_and_name(extension_name) ⇒ Object
- #scm_archive(path, archive, prefix, treeish = 'master') ⇒ Object
- #selected_template ⇒ Object
- #send_file_to_pgxn(filename) ⇒ Object
- #set_accessors(extension_name = "your_extension_name") ⇒ Object
- #try_send_file(request, filename) ⇒ Object
- #zip_archive(path, archive, prefix) ⇒ Object
Instance Method Details
#ask_for_pgxn_credential ⇒ Object
53 54 55 56 |
# File 'lib/pgxn_utils/no_tasks.rb', line 53 def ask_for_pgxn_credential self.pgxn_username = ENV["PGXN_USER"] || HighLine.ask("Enter your PGXN username: ") { |q| q.validate = /^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$/ } self.pgxn_password = ENV["PGXN_PASS"] || HighLine.ask("Enter your PGXN password: ") { |q| q.echo = '*' } end |
#can_zip?(archive) ⇒ Boolean
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/pgxn_utils/no_tasks.rb', line 142 def can_zip?(archive) can_zip = false if File.exists?(archive) say_status :conflict, archive, :red if yes? "Overwrite #{archive}? [yN]" FileUtils.rm_f archive can_zip = true else can_zip = false end else can_zip = true end end |
#check_response(response) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/pgxn_utils/no_tasks.rb', line 58 def check_response(response) case response when Net::HTTPUnauthorized then say "oops!", :red say "It seems that you entered a wrong username or password.", :red when Net::HTTPConflict then say "conflict!", :yellow say "Distribution already exists! Please, check your META.json.", :yellow when Net::HTTPSeeOther then say "released successfully!", :green say "Visit: #{URI.parse(response['Location'])}", :green else say "Unknown error. (#{response})" end end |
#config_options ⇒ Object
166 167 168 169 170 171 172 173 174 |
# File 'lib/pgxn_utils/no_tasks.rb', line 166 def file = File.join(target, "META.json") if File.exist?(file) @@config_options ||= JSON.load(File.read(file)) else {} end end |
#has_scm?(path) ⇒ Boolean
121 122 123 124 125 126 127 |
# File 'lib/pgxn_utils/no_tasks.rb', line 121 def has_scm?(path) begin Repo.new(path) rescue Grit::InvalidGitRepositoryError false end end |
#init_repository(extension_dir) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pgxn_utils/no_tasks.rb', line 21 def init_repository(extension_dir) repo = Repo.init(extension_dir) original_dir = File. "." if repo say_status :init, "#{extension_dir}", :green FileUtils.chdir extension_dir repo.add "." if repo.commit_index("initial commit") say_status :commit, "initial commit", :green else say_status :failed, "initial commit", :red end else say_status :error, " initializing #{extension_dir}", :red end FileUtils.chdir original_dir end |
#is_dir?(dir) ⇒ Boolean
162 163 164 |
# File 'lib/pgxn_utils/no_tasks.rb', line 162 def is_dir?(dir) File.directory?(dir) end |
#is_dirty?(extension_dir) ⇒ Boolean
42 43 44 45 |
# File 'lib/pgxn_utils/no_tasks.rb', line 42 def is_dirty?(extension_dir) repo = Repo.init(extension_dir) repo.status.map(&:type).uniq != [nil] end |
#is_extension?(dir = ".") ⇒ Boolean
158 159 160 |
# File 'lib/pgxn_utils/no_tasks.rb', line 158 def is_extension?(dir=".") is_dir?(dir) && File.exists?("#{dir}/META.json") end |
#make_dist_clean(path) ⇒ Object
47 48 49 50 51 |
# File 'lib/pgxn_utils/no_tasks.rb', line 47 def make_dist_clean(path) inside path do run 'make distclean', :capture => true end end |
#prepare_multipart_post_for(filename) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/pgxn_utils/no_tasks.rb', line 74 def prepare_multipart_post_for(filename) file_basename = File.basename(filename) zip_file = File.open(filename) Net::HTTP::Post::Multipart.new( UPLOAD_URL.path, "archive" => UploadIO.new(zip_file, "application/zip", file_basename), "Expect" => "" ) end |
#resolve_extension_path_and_name(extension_name) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/pgxn_utils/no_tasks.rb', line 106 def resolve_extension_path_and_name(extension_name) target = [:target] extension_path = "." if target != "." && extension_name == "." raise ArgumentError, "Please, supply a extension name" elsif target == "." extension_path = File.(extension_name) extension_name = File.basename(extension_path) else extension_path = "#{target}/#{extension_name}" end [ extension_path, extension_name ] end |
#scm_archive(path, archive, prefix, treeish = 'master') ⇒ Object
129 130 131 132 |
# File 'lib/pgxn_utils/no_tasks.rb', line 129 def scm_archive(path, archive, prefix, treeish='master') git = Git.new(Repo.new(path).path) git.archive({:format => "zip", :prefix => prefix, :output => archive}, treeish) end |
#selected_template ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/pgxn_utils/no_tasks.rb', line 7 def selected_template template = [:template] unless [ 'sql', 'c', 'fdw' ].include?(template) if Dir["#{template}/*"].include?("#{template}/META.json") or Dir["#{template}/*"].include?("#{template}/META.json.tt") template = File.([:template]) else raise "invalid template: #{template}" end end template end |
#send_file_to_pgxn(filename) ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/pgxn_utils/no_tasks.rb', line 97 def send_file_to_pgxn(filename) request = prepare_multipart_post_for(filename) ask_for_pgxn_credential request.basic_auth pgxn_username, pgxn_password response = try_send_file(request, filename) check_response(response) end |
#set_accessors(extension_name = "your_extension_name") ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/pgxn_utils/no_tasks.rb', line 176 def set_accessors(extension_name="your_extension_name") self.extension_name = extension_name self.maintainer = [:maintainer] || ["maintainer"] || "The maintainer's name" self.abstract = [:abstract] || ["abstract"] || "A short description" self.license = [:license] || ["license"] || "postgresql" self.version = [:version] || ["version"] || "0.0.1" self.description = [:description] || ["description"] || "A long description" self.generated_by = [:generated_by] || ["generated_by"] || maintainer self. = [:tags] || ["tags"] self.release_status = [:release_status] || ["release_status"] || "unstable" self.destination_root = target end |
#try_send_file(request, filename) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/pgxn_utils/no_tasks.rb', line 84 def try_send_file(request, filename) begin http = Net::HTTP.new(UPLOAD_URL.host, UPLOAD_URL.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE say "Trying to release #{File.basename(filename)} ... " http.request(request) rescue SocketError say "Please, check your connection.", :red exit(1) end end |
#zip_archive(path, archive, prefix) ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/pgxn_utils/no_tasks.rb', line 134 def zip_archive(path, archive, prefix) Zip::ZipFile.open(archive, Zip::ZipFile::CREATE) do |zip| Dir["#{path}/**/**"].each do |file| zip.add("#{prefix}#{file.sub(path+'/','')}", file) unless File.directory?(file) end end end |