reapack-index 1.0beta2 → 1.0beta3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,157 @@
1
+ class ReaPack::Index::CLI
2
+ PROGRAM_NAME = 'reapack-index'.freeze
3
+
4
+ CONFIG_SEARCH = [
5
+ '~',
6
+ '.',
7
+ ].freeze
8
+
9
+ DEFAULTS = {
10
+ verbose: false,
11
+ warnings: true,
12
+ progress: true,
13
+ quiet: false,
14
+ commit: nil,
15
+ output: './index.xml',
16
+ ignore: [],
17
+ url_template: 'auto',
18
+ }.freeze
19
+
20
+ def read_config
21
+ CONFIG_SEARCH.map {|dir|
22
+ dir = expand_path dir
23
+ path = File.expand_path '.reapack-index.conf', dir
24
+
25
+ log 'reading configuration from %s' % path
26
+
27
+ unless File.readable? path
28
+ log 'configuration file is unreadable, skipping'
29
+ next
30
+ end
31
+
32
+ opts = Array.new
33
+ File.foreach(path) {|line| opts << Shellwords.split(line) }
34
+ opts
35
+ }.flatten.compact
36
+ end
37
+
38
+ def parse_options(args)
39
+ opts = Hash.new
40
+
41
+ OptionParser.new do |op|
42
+ op.program_name = PROGRAM_NAME
43
+ op.version = ReaPack::Index::VERSION
44
+ op.banner = "Package indexer for ReaPack-based repositories\n" +
45
+ "Usage: #{PROGRAM_NAME} [options] [directory]"
46
+
47
+ op.separator 'Options:'
48
+
49
+ op.on '-a', '--[no-]amend', 'Reindex existing versions' do |bool|
50
+ opts[:amend] = bool
51
+ end
52
+
53
+ op.on '-c', '--check', 'Test every package including uncommited changes and exit' do
54
+ opts[:check] = true
55
+ end
56
+
57
+ op.on '-i', '--ignore PATH', "Don't check or index any file starting with PATH" do |path|
58
+ opts[:ignore] ||= []
59
+ opts[:ignore] << expand_path(path)
60
+ end
61
+
62
+ op.on '-n', '--name NAME', 'Set the name shown in ReaPack for this repository' do |name|
63
+ opts[:name] = name.strip
64
+ end
65
+
66
+ op.on '-U', "--url-template TEMPLATE=#{DEFAULTS[:url_template]}",
67
+ 'Set the template for implicit download links' do |tpl|
68
+ opts[:url_template] = tpl.strip
69
+ end
70
+
71
+ op.on '-o', "--output FILE=#{DEFAULTS[:output]}",
72
+ 'Set the output filename and path for the index' do |file|
73
+ opts[:output] = file.strip
74
+ end
75
+
76
+ op.on '-l', '--link LINK', 'Add or remove a website link' do |link|
77
+ opts[:links] ||= Array.new
78
+ opts[:links] << [:website, link.strip]
79
+ end
80
+
81
+ op.on '--donation-link LINK', 'Add or remove a donation link' do |link|
82
+ opts[:links] ||= Array.new
83
+ opts[:links] << [:donation, link.strip]
84
+ end
85
+
86
+ op.on '--ls-links', 'Display the link list then exit' do
87
+ opts[:lslinks] = true
88
+ end
89
+
90
+ op.on '-A', '--about=FILE', 'Set the about content from a file' do |file|
91
+ opts[:about] = file.strip
92
+ end
93
+
94
+ op.on '--remove-about', 'Remove the about content from the index' do
95
+ opts[:rmabout] = true
96
+ end
97
+
98
+ op.on '--dump-about', 'Dump the raw about content in RTF and exit' do
99
+ opts[:dump_about] = true
100
+ end
101
+
102
+ op.on '--[no-]progress', 'Enable or disable progress information' do |bool|
103
+ opts[:progress] = bool
104
+ end
105
+
106
+ op.on '-V', '--[no-]verbose', 'Activate diagnosis messages' do |bool|
107
+ opts[:verbose] = bool
108
+ end
109
+
110
+ op.on '-C', '--[no-]commit', 'Select whether to commit the modified index' do |bool|
111
+ opts[:commit] = bool
112
+ end
113
+
114
+ op.on '--prompt-commit', 'Ask at runtime whether to commit the index' do
115
+ opts[:commit] = nil
116
+ end
117
+
118
+ op.on '-W', '--warnings', 'Enable warnings' do
119
+ opts[:warnings] = true
120
+ end
121
+
122
+ op.on '-w', '--no-warnings', 'Turn off warnings' do
123
+ opts[:warnings] = false
124
+ end
125
+
126
+ op.on '-q', '--[no-]quiet', 'Disable almost all output' do
127
+ opts[:warnings] = false
128
+ opts[:progress] = false
129
+ opts[:verbose] = false
130
+ opts[:quiet] = true
131
+ end
132
+
133
+ op.on '--no-config', 'Bypass the configuration files' do
134
+ opts[:noconfig] = true
135
+ end
136
+
137
+ op.on_tail '-v', '--version', 'Display version information' do
138
+ puts op.ver
139
+ @exit = true
140
+ return opts
141
+ end
142
+
143
+ op.on_tail '-h', '--help', 'Prints this help' do
144
+ puts op
145
+ @exit = true
146
+ return opts
147
+ end
148
+ end.parse! args
149
+
150
+ opts
151
+ rescue OptionParser::ParseError => e
152
+ $stderr.puts "#{PROGRAM_NAME}: #{e.message}"
153
+ $stderr.puts "Try '#{PROGRAM_NAME} --help' for more information."
154
+ @exit = false
155
+ opts
156
+ end
157
+ end
@@ -1,5 +1,5 @@
1
1
  module ReaPack
2
2
  class Index
3
- VERSION = '1.0beta2'
3
+ VERSION = '1.0beta3'
4
4
  end
5
5
  end
@@ -17,8 +17,14 @@ class ReaPack::Index
17
17
  def push_link(type, name = nil, url)
18
18
  Link.check_type type
19
19
 
20
- unless url =~ /\A#{URI::regexp(['http', 'https'])}\z/
21
- raise Error, "invalid URL: #{url}"
20
+ begin
21
+ uri = Addressable::URI.parse url
22
+
23
+ unless ['http', 'https'].include? uri.scheme
24
+ raise Addressable::URI::InvalidURIError
25
+ end
26
+ rescue Addressable::URI::InvalidURIError
27
+ raise Error, "invalid link: #{url}"
22
28
  end
23
29
 
24
30
  make_root
@@ -5,7 +5,7 @@ class WordpressChangelog < MetaHeader::Parser
5
5
  ((?:--)?\]\]|\*\/)
6
6
  /xm.freeze
7
7
 
8
- VERSION = /\A[\s\*]+v([\d\.]+)(?:\s+(.+))?\Z/.freeze
8
+ VERSION = /\A[\s\*]*v([\d\.]+)(?:\s+(.+))?\Z/.freeze
9
9
 
10
10
  def parse(input)
11
11
  input.encode! Encoding::UTF_8, invalid: :replace
@@ -13,23 +13,20 @@ class WordpressChangelog < MetaHeader::Parser
13
13
  ver, changes = header[:version], header[:changelog]
14
14
  return if ver.nil? || changes || CHANGELOG.match(input).nil?
15
15
 
16
- $1.lines {|line| read line.lstrip }
16
+ $1.lines.each {|line| read line.lstrip }
17
17
  end
18
18
 
19
19
  def read(line)
20
20
  if line =~ VERSION
21
21
  @current = $1 == header[:version]
22
- line = $2.to_s
22
+ elsif @current
23
+ if header[:changelog]
24
+ header[:changelog] += "\n"
25
+ else
26
+ header[:changelog] = String.new
27
+ end
28
+
29
+ header[:changelog] += line.chomp
23
30
  end
24
-
25
- return unless @current
26
-
27
- if header[:changelog]
28
- header[:changelog] += "\n"
29
- else
30
- header[:changelog] = String.new
31
- end
32
-
33
- header[:changelog] += line.chomp
34
31
  end
35
32
  end
@@ -125,7 +125,7 @@ class ReaPack::Index
125
125
  @node.parent = parent
126
126
  @node[PLATFORM] = @platform
127
127
  @node[FILE] = @file if @file
128
- @node.content = URI.escape @url
128
+ @node.content = Addressable::URI.encode @url
129
129
  end
130
130
  end
131
131
 
@@ -5,13 +5,13 @@ $LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
5
5
  require 'reapack/index/gem_version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.name = "reapack-index"
8
+ spec.name = 'reapack-index'
9
9
  spec.version = ReaPack::Index::VERSION
10
- spec.authors = ["cfillion"]
11
- spec.email = ["reapack-index@cfillion.tk"]
12
- spec.summary = %q{Package indexer for ReaPack-based repositories}
13
- spec.homepage = "https://github.com/cfillion/reapack-indexer"
14
- spec.license = "LGPL-3.0+"
10
+ spec.authors = ['cfillion']
11
+ spec.email = ['reapack-index@cfillion.tk']
12
+ spec.summary = 'Package indexer for ReaPack-based repositories'
13
+ spec.homepage = 'https://github.com/cfillion/reapack-index'
14
+ spec.license = "GPL-3.0+"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -20,14 +20,16 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency 'bundler', '~> 1.10'
22
22
  spec.add_development_dependency 'coveralls', '~> 0.8'
23
- spec.add_development_dependency 'git', '~> 1.2'
23
+ spec.add_development_dependency 'git', '~> 1.3'
24
24
  spec.add_development_dependency 'minitest', '~> 5.8'
25
- spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rake', '~> 11.0'
26
26
  spec.add_development_dependency 'simplecov', '~> 0.11'
27
27
 
28
+ spec.add_runtime_dependency 'addressable', '~> 2.4'
28
29
  spec.add_runtime_dependency 'colorize', '~> 0.7'
30
+ spec.add_runtime_dependency 'gitable', '~> 0.3'
29
31
  spec.add_runtime_dependency 'metaheader', '~> 1.0'
30
32
  spec.add_runtime_dependency 'nokogiri', '~> 1.6'
31
- spec.add_runtime_dependency 'pandoc-ruby', '~> 1.0'
32
- spec.add_runtime_dependency 'rugged', '~> 0.24.0b12'
33
+ spec.add_runtime_dependency 'pandoc-ruby', '~> 2.0'
34
+ spec.add_runtime_dependency 'rugged', '~> 0.24'
33
35
  end
@@ -0,0 +1,59 @@
1
+ ; Source: http://nsis.sourceforge.net/StrRep
2
+
3
+ !macro StrRep output string old new
4
+ Push `${string}`
5
+ Push `${old}`
6
+ Push `${new}`
7
+ Call StrRep
8
+ Pop ${output}
9
+ !macroend
10
+
11
+ Function StrRep
12
+ Exch $R2 ;new
13
+ Exch 1
14
+ Exch $R1 ;old
15
+ Exch 2
16
+ Exch $R0 ;string
17
+ Push $R3
18
+ Push $R4
19
+ Push $R5
20
+ Push $R6
21
+ Push $R7
22
+ Push $R8
23
+ Push $R9
24
+
25
+ StrCpy $R3 0
26
+ StrLen $R4 $R1
27
+ StrLen $R6 $R0
28
+ StrLen $R9 $R2
29
+ loop:
30
+ StrCpy $R5 $R0 $R4 $R3
31
+ StrCmp $R5 $R1 found
32
+ StrCmp $R3 $R6 done
33
+ IntOp $R3 $R3 + 1 ;move offset by 1 to check the next character
34
+ Goto loop
35
+ found:
36
+ StrCpy $R5 $R0 $R3
37
+ IntOp $R8 $R3 + $R4
38
+ StrCpy $R7 $R0 "" $R8
39
+ StrCpy $R0 $R5$R2$R7
40
+ StrLen $R6 $R0
41
+ IntOp $R3 $R3 + $R9 ;move offset by length of the replacement string
42
+ Goto loop
43
+ done:
44
+
45
+ Pop $R9
46
+ Pop $R8
47
+ Pop $R7
48
+ Pop $R6
49
+ Pop $R5
50
+ Pop $R4
51
+ Pop $R3
52
+ Push $R0
53
+ Push $R1
54
+ Pop $R0
55
+ Pop $R1
56
+ Pop $R0
57
+ Pop $R2
58
+ Exch $R1
59
+ FunctionEnd
@@ -1,7 +1,8 @@
1
1
  !include MUI2.nsh
2
2
  !include Sections.nsh
3
+ !include StrRep.nsh
3
4
 
4
- !define VERSION "1.0beta2"
5
+ !define VERSION "1.0beta3"
5
6
  !define NAME "ReaPack Index ${VERSION}"
6
7
  !define LONG_VERSION "0.1.0.0"
7
8
 
@@ -10,11 +11,13 @@
10
11
  !define RUBYINSTALLER_URL \
11
12
  "http://dl.bintray.com/oneclick/rubyinstaller/${RUBYINSTALLER_FILE}"
12
13
 
13
- !define PANDOC_FILE "pandoc-1.16.0.2-windows.msi"
14
+ !define PANDOC_VERSION "1.17.0.2"
15
+ !define PANDOC_FILE "pandoc-${PANDOC_VERSION}-windows.msi"
14
16
  !define PANDOC_URL \
15
- "https://github.com/jgm/pandoc/releases/download/1.16.0.2/${PANDOC_FILE}"
17
+ "https://github.com/jgm/pandoc/releases/download/${PANDOC_VERSION}/${PANDOC_FILE}"
16
18
 
17
- !define RUGGED_FILE "rugged-0.24.0b12-x86-mingw32.gem"
19
+ !define RUGGED_VERSION "0.24.0"
20
+ !define RUGGED_FILE "rugged-${RUGGED_VERSION}-%PLATFORM%.gem"
18
21
  !define RUGGED_URL \
19
22
  "https://github.com/cfillion/reapack-index/releases/download/v${VERSION}/${RUGGED_FILE}"
20
23
 
@@ -42,11 +45,11 @@ VIAddVersionKey "LegalCopyright" "Copyright (C) 2015-2016 Christian Fillion"
42
45
  !insertmacro MUI_LANGUAGE "English"
43
46
 
44
47
  !macro DOWNLOAD url file
45
- NSISdl::download /TIMEOUT=30000 "${url}" "${file}"
46
- Pop $R0
47
- StrCmp $R0 "success" +4
48
- DetailPrint "Error while downloading ${url}:"
49
- DetailPrint " $R0"
48
+ inetc::get /CONNECTTIMEOUT=30000 "${url}" "${file}" /END
49
+ Pop $0
50
+ StrCmp $0 "OK" +4
51
+ DetailPrint "Error while downloading ${url} to ${file}:"
52
+ DetailPrint " $0"
50
53
  Abort "${ABORT_MSG}"
51
54
  !macroend
52
55
 
@@ -68,69 +71,89 @@ VIAddVersionKey "LegalCopyright" "Copyright (C) 2015-2016 Christian Fillion"
68
71
  Abort "${ABORT_MSG}"
69
72
  !macroend
70
73
 
74
+ !macro RELOAD_PATH
75
+ ; reload the path to use the one freshly set by the ruby installer
76
+ ReadRegStr $R1 HKCU "Environment" "Path"
77
+ System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("Path", R1).r2'
78
+ !macroend
79
+
71
80
  Section /o "Ruby for Windows" InstallRuby
72
81
  InitPluginsDir
73
- StrCpy $0 "$PLUGINSDIR\${RUBYINSTALLER_FILE}"
74
- !insertmacro DOWNLOAD "${RUBYINSTALLER_URL}" $0
82
+ StrCpy $R0 "$PLUGINSDIR\${RUBYINSTALLER_FILE}"
83
+ !insertmacro DOWNLOAD "${RUBYINSTALLER_URL}" $R0
75
84
 
76
85
  DetailPrint "Installing Ruby ${RUBY_VERSION}..."
77
- !insertmacro EXEC_GUI '"$0" /VERYSILENT /TASKS=MODPATH' ${RUBYINSTALLER_FILE}
86
+ !insertmacro EXEC_GUI '"$R0" /VERYSILENT /TASKS=MODPATH' ${RUBYINSTALLER_FILE}
78
87
 
79
- ; reload the path to use the one freshly set by the ruby installer
80
- ReadRegStr $R0 HKCU "Environment" "Path"
81
- System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("Path", R0).r2'
88
+ !insertmacro RELOAD_PATH
82
89
  SectionEnd
83
90
 
84
91
  Section /o "Rugged (libgit2)" InstallRugged
92
+ nsExec::ExecToStack '"ruby" -e "print Gem::Platform.local"'
93
+ Pop $0
94
+ Pop $1
95
+ !insertmacro StrRep $R2 "${RUGGED_FILE}" "%PLATFORM%" $1
96
+ !insertmacro StrRep $R3 "${RUGGED_URL}" "%PLATFORM%" $1
97
+
85
98
  InitPluginsDir
86
- StrCpy $0 "$PLUGINSDIR\${RUGGED_FILE}"
87
- !insertmacro DOWNLOAD "${RUGGED_URL}" $0
99
+ StrCpy $R0 "$PLUGINSDIR\$R2"
100
+ !insertmacro DOWNLOAD "$R3" $R0
88
101
 
89
102
  DetailPrint "Installing rugged/libgit2 with pre-built C extensions..."
90
- !insertmacro EXEC_CLI '"cmd" /C gem install $0' "gem install ${RUGGED_FILE}"
103
+ !insertmacro EXEC_CLI '"cmd" /C gem install $R0' "gem install $R2"
91
104
  SectionEnd
92
105
 
93
106
  Section /o "Pandoc" InstallPandoc
94
107
  InitPluginsDir
95
- StrCpy $0 "$PLUGINSDIR\${PANDOC_FILE}"
96
- !insertmacro DOWNLOAD "${PANDOC_URL}" $0
108
+ StrCpy $R0 "$PLUGINSDIR\${PANDOC_FILE}"
109
+ !insertmacro DOWNLOAD "${PANDOC_URL}" $R0
97
110
 
98
111
  DetailPrint "Installing Pandoc..."
99
- !insertmacro EXEC_GUI '"msiexec" /i $0 /passive' ${PANDOC_FILE}
112
+ !insertmacro EXEC_GUI '"msiexec" /i $R0 /passive' ${PANDOC_FILE}
100
113
  SectionEnd
101
114
 
102
- Section "ReaPack-Index" InstallMain
115
+ Section "ReaPack Index" InstallMain
103
116
  SectionIn RO
104
117
 
105
118
  DetailPrint "Installing reapack-index... (this can take a while)"
106
119
 
107
- !insertmacro EXEC_CLI \
108
- '"cmd" /C gem install reapack-index --version=${VERSION}' \
109
- "gem install reapack-index"
120
+ StrCpy $R0 "gem install reapack-index --version=${VERSION}"
121
+ !insertmacro EXEC_CLI '"cmd" /C $R0' "$R0"
110
122
  SectionEnd
111
123
 
112
124
  Function .onInit
113
- nsExec::ExecToStack '"ruby" -e "require \"rugged\"'
125
+ !insertmacro RELOAD_PATH
126
+ nsExec::ExecToStack '"ruby" -e " \
127
+ spec = Gem::Specification.find_all_by_name(\"rugged\").first; \
128
+ req = Gem::Requirement.new(\"~> ${RUGGED_VERSION}\"); \
129
+ raise unless spec && req =~ spec.version'
114
130
  Pop $0
115
131
 
116
- StrCmp $0 "error" 0 +5 ; failed to launch ruby
132
+ StrCmp $0 "error" 0 +6 ; failed to launch ruby
117
133
  SectionGetFlags ${InstallRuby} $1
118
134
  IntOp $1 $1 | ${SF_SELECTED}
135
+ IntOp $1 $1 | ${SF_RO}
119
136
  SectionSetFlags ${InstallRuby} $1
120
137
  Goto +2 ; also install rugged
121
138
 
122
- StrCmp $0 "1" 0 +4 ; rugged is not installed
139
+ StrCmp $0 "1" 0 +5 ; rugged is not installed
123
140
  SectionGetFlags ${InstallRugged} $1
124
141
  IntOp $1 $1 | ${SF_SELECTED}
142
+ IntOp $1 $1 | ${SF_RO}
125
143
  SectionSetFlags ${InstallRugged} $1
126
144
 
127
145
  nsExec::ExecToStack '"pandoc" --version'
128
146
  Pop $0
129
147
 
130
- StrCmp $0 "error" 0 +4 ; failed to launch pandoc
148
+ StrCmp $0 "error" 0 +5 ; failed to launch pandoc
131
149
  SectionGetFlags ${InstallPandoc} $1
132
150
  IntOp $1 $1 | ${SF_SELECTED}
151
+ IntOp $1 $1 | ${SF_RO}
133
152
  SectionSetFlags ${InstallPandoc} $1
153
+
154
+ SectionGetFlags ${InstallMain} $1
155
+ IntOp $1 $1 | ${SF_PSELECTED}
156
+ SectionSetFlags ${InstallMain} $1
134
157
  FunctionEnd
135
158
 
136
159
  !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN