-
Notifications
You must be signed in to change notification settings - Fork 10
/
update
executable file
·80 lines (59 loc) · 2.6 KB
/
update
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#! /usr/bin/env ruby
# Usage:
# update [module]
#
# If the optional argument [module] is provided, then the module tries to update that module
require 'rubygems'
require 'bundler/setup'
require 'mechanize'
require 'highline/import'
agent = Mechanize.new
login_page = agent.get "https://modules.contextgarden.net/cgi-bin/menu.cgi/action=login"
login_form = login_page.form_with :method => "POST"
username = login_form.field_with :name => "username"
password = login_form.field_with :name => "password"
username.value = ask("username: ") { |q| q.default = "adityam" }
password.value = ask("password: ") { |q| q.echo = false }
module_page = login_form.submit()
my_module_page = module_page.link_with(:text => 'Your module list').click
module_list = my_module_page.search('table > tr[class="#STATE#"] > td:first-of-type > a')
current_module = ""
say "User modules"
choose do |menu|
menu.prompt = "Choose module to update: "
module_list.map do |module_name|
name = module_name.children[0].text
name = name.partition(" ").first.downcase
link = module_name.attr(:href)
menu.choice name do
current_module = name
say "loading module #{name}"
module_page = my_module_page.link_with(:href => link).click
end
end
menu.first_answer = ARGV[0]
menu.select_by = :index_or_name
end
version_page = module_page.link_with(:text => "new version").click
version_form = version_page.form_with :method => "POST"
message = version_form.field_with :name => "pv_message"
version = version_form.field_with :name => "pv_version"
filename = version_form.file_upload_with :name => "uploaded_file"
method = version_form.radiobutton_with(:name => "pv_source_method", :value => "9")
version.value = ask("version: ") { |q| q.default = Time.now.strftime("%Y.%m.%d") }
filename.file_name = ask("filename: ", Pathname) do |q|
q.validate = Proc.new {|file| File.exists?(file) && File.extname(file) == ".zip"}
q.responses[:not_valid] = "Please select a zip file"
q.default = current_module + ".zip"
end.to_s
filename = ask("File specifying log message:", Pathname) do |q|
q.validate = Proc.new {|file| File.exists?(file) && File.extname(file) == ".txt"}
q.responses[:not_valid] = "Please select a txt file"
q.default = current_module + ".txt"
end.to_s
message.value = File.read(filename)
method.check
confirmation_page = agent.submit(version_form, version_form.buttons.first)
confirmation_form = confirmation_page.form_with :method => "POST"
result = agent.submit(confirmation_form, confirmation_form.buttons.first)
pp result