You've already forked macports-contrib
mirror of
https://github.com/macports/macports-contrib.git
synced 2026-07-12 18:18:45 -07:00
Move MPWA to contrib/
git-svn-id: https://svn.macports.org/repository/macports/contrib@38927 d073be05-634f-4543-b044-5fe20cf6d1d6
This commit is contained in:
+183
@@ -0,0 +1,183 @@
|
||||
== Welcome to Rails
|
||||
|
||||
Rails is a web-application and persistence framework that includes everything
|
||||
needed to create database-backed web-applications according to the
|
||||
Model-View-Control pattern of separation. This pattern splits the view (also
|
||||
called the presentation) into "dumb" templates that are primarily responsible
|
||||
for inserting pre-built data in between HTML tags. The model contains the
|
||||
"smart" domain objects (such as Account, Product, Person, Post) that holds all
|
||||
the business logic and knows how to persist themselves to a database. The
|
||||
controller handles the incoming requests (such as Save New Account, Update
|
||||
Product, Show Post) by manipulating the model and directing data to the view.
|
||||
|
||||
In Rails, the model is handled by what's called an object-relational mapping
|
||||
layer entitled Active Record. This layer allows you to present the data from
|
||||
database rows as objects and embellish these data objects with business logic
|
||||
methods. You can read more about Active Record in
|
||||
link:files/vendor/rails/activerecord/README.html.
|
||||
|
||||
The controller and view are handled by the Action Pack, which handles both
|
||||
layers by its two parts: Action View and Action Controller. These two layers
|
||||
are bundled in a single package due to their heavy interdependence. This is
|
||||
unlike the relationship between the Active Record and Action Pack that is much
|
||||
more separate. Each of these packages can be used independently outside of
|
||||
Rails. You can read more about Action Pack in
|
||||
link:files/vendor/rails/actionpack/README.html.
|
||||
|
||||
|
||||
== Getting started
|
||||
|
||||
1. Start the web server: <tt>ruby script/server</tt> (run with --help for options)
|
||||
2. Go to http://localhost:3000/ and get "Welcome aboard: You’re riding the Rails!"
|
||||
3. Follow the guidelines to start developing your application
|
||||
|
||||
|
||||
== Web servers
|
||||
|
||||
Rails uses the built-in web server in Ruby called WEBrick by default, so you don't
|
||||
have to install or configure anything to play around.
|
||||
|
||||
If you have lighttpd installed, though, it'll be used instead when running script/server.
|
||||
It's considerably faster than WEBrick and suited for production use, but requires additional
|
||||
installation and currently only works well on OS X/Unix (Windows users are encouraged
|
||||
to start with WEBrick). We recommend version 1.4.11 and higher. You can download it from
|
||||
http://www.lighttpd.net.
|
||||
|
||||
If you want something that's halfway between WEBrick and lighttpd, we heartily recommend
|
||||
Mongrel. It's a Ruby-based web server with a C-component (so it requires compilation) that
|
||||
also works very well with Windows. See more at http://mongrel.rubyforge.org/.
|
||||
|
||||
But of course its also possible to run Rails with the premiere open source web server Apache.
|
||||
To get decent performance, though, you'll need to install FastCGI. For Apache 1.3, you want
|
||||
to use mod_fastcgi. For Apache 2.0+, you want to use mod_fcgid.
|
||||
|
||||
See http://wiki.rubyonrails.com/rails/pages/FastCGI for more information on FastCGI.
|
||||
|
||||
== Example for Apache conf
|
||||
|
||||
<VirtualHost *:80>
|
||||
ServerName rails
|
||||
DocumentRoot /path/application/public/
|
||||
ErrorLog /path/application/log/server.log
|
||||
|
||||
<Directory /path/application/public/>
|
||||
Options ExecCGI FollowSymLinks
|
||||
AllowOverride all
|
||||
Allow from all
|
||||
Order allow,deny
|
||||
</Directory>
|
||||
</VirtualHost>
|
||||
|
||||
NOTE: Be sure that CGIs can be executed in that directory as well. So ExecCGI
|
||||
should be on and ".cgi" should respond. All requests from 127.0.0.1 go
|
||||
through CGI, so no Apache restart is necessary for changes. All other requests
|
||||
go through FCGI (or mod_ruby), which requires a restart to show changes.
|
||||
|
||||
|
||||
== Debugging Rails
|
||||
|
||||
Have "tail -f" commands running on both the server.log, production.log, and
|
||||
test.log files. Rails will automatically display debugging and runtime
|
||||
information to these files. Debugging info will also be shown in the browser
|
||||
on requests from 127.0.0.1.
|
||||
|
||||
|
||||
== Breakpoints
|
||||
|
||||
Breakpoint support is available through the script/breakpointer client. This
|
||||
means that you can break out of execution at any point in the code, investigate
|
||||
and change the model, AND then resume execution! Example:
|
||||
|
||||
class WeblogController < ActionController::Base
|
||||
def index
|
||||
@posts = Post.find_all
|
||||
breakpoint "Breaking out from the list"
|
||||
end
|
||||
end
|
||||
|
||||
So the controller will accept the action, run the first line, then present you
|
||||
with a IRB prompt in the breakpointer window. Here you can do things like:
|
||||
|
||||
Executing breakpoint "Breaking out from the list" at .../webrick_server.rb:16 in 'breakpoint'
|
||||
|
||||
>> @posts.inspect
|
||||
=> "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
|
||||
#<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
|
||||
>> @posts.first.title = "hello from a breakpoint"
|
||||
=> "hello from a breakpoint"
|
||||
|
||||
...and even better is that you can examine how your runtime objects actually work:
|
||||
|
||||
>> f = @posts.first
|
||||
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
||||
>> f.
|
||||
Display all 152 possibilities? (y or n)
|
||||
|
||||
Finally, when you're ready to resume execution, you press CTRL-D
|
||||
|
||||
|
||||
== Console
|
||||
|
||||
You can interact with the domain model by starting the console through script/console.
|
||||
Here you'll have all parts of the application configured, just like it is when the
|
||||
application is running. You can inspect domain models, change values, and save to the
|
||||
database. Starting the script without arguments will launch it in the development environment.
|
||||
Passing an argument will specify a different environment, like <tt>script/console production</tt>.
|
||||
|
||||
To reload your controllers and models after launching the console run <tt>reload!</tt>
|
||||
|
||||
|
||||
|
||||
== Description of contents
|
||||
|
||||
app
|
||||
Holds all the code that's specific to this particular application.
|
||||
|
||||
app/controllers
|
||||
Holds controllers that should be named like weblog_controller.rb for
|
||||
automated URL mapping. All controllers should descend from
|
||||
ActionController::Base.
|
||||
|
||||
app/models
|
||||
Holds models that should be named like post.rb.
|
||||
Most models will descend from ActiveRecord::Base.
|
||||
|
||||
app/views
|
||||
Holds the template files for the view that should be named like
|
||||
weblog/index.rhtml for the WeblogController#index action. All views use eRuby
|
||||
syntax. This directory can also be used to keep stylesheets, images, and so on
|
||||
that can be symlinked to public.
|
||||
|
||||
app/helpers
|
||||
Holds view helpers that should be named like weblog_helper.rb.
|
||||
|
||||
app/apis
|
||||
Holds API classes for web services.
|
||||
|
||||
config
|
||||
Configuration files for the Rails environment, the routing map, the database, and other dependencies.
|
||||
|
||||
components
|
||||
Self-contained mini-applications that can bundle together controllers, models, and views.
|
||||
|
||||
db
|
||||
Contains the database schema in schema.rb. db/migrate contains all
|
||||
the sequence of Migrations for your schema.
|
||||
|
||||
lib
|
||||
Application specific libraries. Basically, any kind of custom code that doesn't
|
||||
belong under controllers, models, or helpers. This directory is in the load path.
|
||||
|
||||
public
|
||||
The directory available for the web server. Contains subdirectories for images, stylesheets,
|
||||
and javascripts. Also contains the dispatchers and the default HTML files.
|
||||
|
||||
script
|
||||
Helper scripts for automation and generation.
|
||||
|
||||
test
|
||||
Unit and functional tests along with fixtures.
|
||||
|
||||
vendor
|
||||
External libraries that the application depends on. Also includes the plugins subdirectory.
|
||||
This directory is in the load path.
|
||||
@@ -0,0 +1,10 @@
|
||||
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
||||
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
||||
|
||||
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
|
||||
|
||||
require 'rake'
|
||||
require 'rake/testtask'
|
||||
require 'rake/rdoctask'
|
||||
|
||||
require 'tasks/rails'
|
||||
@@ -0,0 +1,32 @@
|
||||
# Filters added to this controller will be run for all controllers in the application.
|
||||
# Likewise, all the methods added will be available for all controllers.
|
||||
class ApplicationController < ActionController::Base
|
||||
|
||||
attr_reader :svn, :tar, :xar, :mtree
|
||||
attr_reader :repo_url, :repo_root, :repo_portpkgs, :repo_portpkgs_url
|
||||
attr_reader :main_tags
|
||||
|
||||
helper :table
|
||||
|
||||
def initialize
|
||||
@svn = "/opt/local/bin/svn"
|
||||
@xar = "/opt/local/bin/xar"
|
||||
@tar = "/usr/bin/tar"
|
||||
@mtree = "/usr/sbin/mtree"
|
||||
|
||||
@repo_url = "file:///Users/jberry/Projects/macports/users/jberry/mpwa/testrepo/repo"
|
||||
@repo_root = "/Users/jberry/Projects/macports/users/jberry/mpwa/testrepo/root"
|
||||
@repo_portpkgs = "#{@repo_root}/portpkgs"
|
||||
@repo_portpkgs_url = "#{@repo_url}/portpkgs"
|
||||
|
||||
@main_tags = [
|
||||
'aqua', 'archivers', 'audio', 'benchmarks', 'cad', 'comms', 'cross',
|
||||
'databases', 'devel', 'editors', 'emulators', 'fuse', 'games',
|
||||
'genealogy', 'gnome', 'gnustep', 'graphics', 'irc', 'java', 'kde',
|
||||
'lang', 'mail', 'math', 'multimedia', 'net', 'news', 'palm', 'perl',
|
||||
'print', 'python', 'ruby', 'science', 'security', 'shells', 'sysutils',
|
||||
'tex', 'textproc', 'www', 'x11', 'zope'
|
||||
]
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,54 @@
|
||||
class FileBlobController < ApplicationController
|
||||
def index
|
||||
list
|
||||
render :action => 'list'
|
||||
end
|
||||
|
||||
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
|
||||
verify :method => :post, :only => [ :destroy, :create, :update ],
|
||||
:redirect_to => { :action => :list }
|
||||
|
||||
def list
|
||||
@file_blob_pages, @file_blobs = paginate :file_blobs, :per_page => 10
|
||||
end
|
||||
|
||||
def show
|
||||
@file_blob = FileBlob.find(params[:id])
|
||||
end
|
||||
|
||||
def new
|
||||
@file_blob = FileBlob.new
|
||||
end
|
||||
|
||||
def create
|
||||
@file_blob = FileBlob.new(params[:file_blob])
|
||||
if @file_blob.save
|
||||
flash[:notice] = 'FileBlob was successfully created.'
|
||||
redirect_to :action => 'list'
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@file_blob = FileBlob.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@file_blob = FileBlob.find(params[:id])
|
||||
if @file_blob.update_attributes(params[:file_blob])
|
||||
flash[:notice] = 'FileBlob was successfully updated.'
|
||||
redirect_to :action => 'show', :id => @file_blob
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
FileBlob.find(params[:id]).destroy
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
|
||||
private :create, :edit, :update, :destroy
|
||||
|
||||
end
|
||||
@@ -0,0 +1,54 @@
|
||||
class FileInfoController < ApplicationController
|
||||
def index
|
||||
list
|
||||
render :action => 'list'
|
||||
end
|
||||
|
||||
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
|
||||
verify :method => :post, :only => [ :destroy, :create, :update ],
|
||||
:redirect_to => { :action => :list }
|
||||
|
||||
def list
|
||||
@file_info_pages, @file_infos = paginate :file_infos, :per_page => 10
|
||||
end
|
||||
|
||||
def show
|
||||
@file_info = FileInfo.find(params[:id])
|
||||
end
|
||||
|
||||
def new
|
||||
@file_info = FileInfo.new
|
||||
end
|
||||
|
||||
def create
|
||||
@file_info = FileInfo.new(params[:file_info])
|
||||
if @file_info.save
|
||||
flash[:notice] = 'FileInfo was successfully created.'
|
||||
redirect_to :action => 'list'
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@file_info = FileInfo.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@file_info = FileInfo.find(params[:id])
|
||||
if @file_info.update_attributes(params[:file_info])
|
||||
flash[:notice] = 'FileInfo was successfully updated.'
|
||||
redirect_to :action => 'show', :id => @file_info
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
FileInfo.find(params[:id]).destroy
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
|
||||
private :create, :edit, :update, :destroy
|
||||
|
||||
end
|
||||
@@ -0,0 +1,66 @@
|
||||
class FileRefController < ApplicationController
|
||||
def index
|
||||
list
|
||||
render :action => 'list'
|
||||
end
|
||||
|
||||
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
|
||||
verify :method => :post, :only => [ :destroy, :create, :update ],
|
||||
:redirect_to => { :action => :list }
|
||||
|
||||
def list
|
||||
@file_ref_pages, @file_refs = paginate :file_refs, :per_page => 10
|
||||
end
|
||||
|
||||
def show
|
||||
@file_ref = FileRef.find(params[:id])
|
||||
end
|
||||
|
||||
def new
|
||||
@file_ref = FileRef.new
|
||||
end
|
||||
|
||||
def create
|
||||
@file_ref = FileRef.new(params[:file_ref])
|
||||
if @file_ref.save
|
||||
flash[:notice] = 'FileRef was successfully created.'
|
||||
redirect_to :action => 'list'
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@file_ref = FileRef.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@file_ref = FileRef.find(params[:id])
|
||||
if @file_ref.update_attributes(params[:file_ref])
|
||||
flash[:notice] = 'FileRef was successfully updated.'
|
||||
redirect_to :action => 'show', :id => @file_ref
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
FileRef.find(params[:id]).destroy
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
|
||||
def emit
|
||||
ref = FileRef.find(params[:id])
|
||||
send_data ref.file_info.data,
|
||||
:filename => ref.file_info.file_path,
|
||||
:type => ref.file_info.mime_type,
|
||||
:disposition => 'inline'
|
||||
|
||||
# Bump download counts for the ref, and for the portpkg too if the file is a portpkg.
|
||||
FileRef.increment_counter('download_count', ref)
|
||||
PortPkg.increment_counter('download_count', ref.port_pkg) if ref.is_port_pkg
|
||||
end
|
||||
|
||||
private :create, :edit, :update, :destroy
|
||||
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class MacPortsController < ApplicationController
|
||||
def index
|
||||
@recent_pkgs = PortPkg.find(:all, :order => 'submitted_at desc', :limit => 25)
|
||||
render :action => 'show'
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,68 @@
|
||||
class PersonController < ApplicationController
|
||||
def index
|
||||
list
|
||||
render :action => 'list'
|
||||
end
|
||||
|
||||
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
|
||||
verify :method => :post, :only => [ :destroy, :create, :update ],
|
||||
:redirect_to => { :action => :list }
|
||||
|
||||
def list
|
||||
@person_pages, @people = paginate :people, :per_page => 30, :order => 'last_name, first_name, user_name'
|
||||
end
|
||||
|
||||
def show
|
||||
@person = Person.find(params[:id])
|
||||
end
|
||||
|
||||
def new
|
||||
@person = Person.new
|
||||
end
|
||||
|
||||
def create
|
||||
@person = Person.new(params[:person])
|
||||
if @person.save
|
||||
flash[:notice] = 'Person was successfully created.'
|
||||
redirect_to :action => 'list'
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@person = Person.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@person = Person.find(params[:id])
|
||||
if @person.update_attributes(params[:person])
|
||||
flash[:notice] = 'Person was successfully updated.'
|
||||
redirect_to :action => 'show', :id => @person
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
Person.find(params[:id]).destroy
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
|
||||
def validation_request
|
||||
@person = Person.find(params[:id])
|
||||
|
||||
# Check captcha result
|
||||
if (params[:a].to_i + params[:b].to_i == params[:sum].to_i)
|
||||
# Create token
|
||||
token = Token.create(:type => 'validation', :random => rand(999999999), :expires => DateTime.now() + 1)
|
||||
Notifier.deliver_user_validation(@person, token)
|
||||
flash[:notice] = 'Validation email sent'
|
||||
elsif
|
||||
flash[:notice] = 'Incorrect sum'
|
||||
end
|
||||
redirect_to :action => 'show', :id => @person
|
||||
end
|
||||
|
||||
private :create, :edit, :update, :destroy
|
||||
end
|
||||
@@ -0,0 +1,91 @@
|
||||
class PortController < ApplicationController
|
||||
|
||||
def index
|
||||
list
|
||||
render :action => 'list'
|
||||
end
|
||||
|
||||
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
|
||||
verify :method => :post, :only => [ :destroy, :create, :update ],
|
||||
:redirect_to => { :action => :list }
|
||||
|
||||
def list
|
||||
@port_pages, @ports = paginate :ports, :per_page => 80, :order => 'name'
|
||||
end
|
||||
|
||||
def show
|
||||
@port = Port.find(params[:id])
|
||||
end
|
||||
|
||||
def random
|
||||
@port = Port.find(:first, :order => "rand()")
|
||||
redirect_to :action => 'show', :id => @port
|
||||
end
|
||||
|
||||
def new
|
||||
@port = Port.new
|
||||
end
|
||||
|
||||
def create
|
||||
@port = Port.new(params[:port])
|
||||
if @port.save
|
||||
flash[:notice] = 'Port was successfully created.'
|
||||
redirect_to :action => 'list'
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@port = Port.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@port = Port.find(params[:id])
|
||||
if @port.update_attributes(params[:port])
|
||||
flash[:notice] = 'Port was successfully updated.'
|
||||
redirect_to :action => 'show', :id => @port
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
Port.find(params[:id]).destroy
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
|
||||
def query
|
||||
@q = params[:q]
|
||||
@port_pages, @ports = paginate :ports, :per_page => 80, :order => 'name',
|
||||
:conditions => Port.build_query_conditions(@q)
|
||||
end
|
||||
|
||||
def tag
|
||||
port = Port.find(params[:id])
|
||||
params[:tags].split(/,?[ ]+/).each do |t|
|
||||
if t =~ /\-(.*)/
|
||||
port.remove_tag($1) if $1
|
||||
elsif t =~ /\+?(.+)/
|
||||
port.add_tag($1)
|
||||
end
|
||||
end
|
||||
redirect_to :action => 'show', :id => port
|
||||
end
|
||||
|
||||
def add_comment
|
||||
port = Port.find(params[:id])
|
||||
text = params[:text]
|
||||
|
||||
if text
|
||||
# TODO: Figure out the real maintainer
|
||||
port.comments << Comment.create(:commenter => port.maintainers.first, :comment => text)
|
||||
end
|
||||
|
||||
redirect_to :action => 'show', :id => port
|
||||
end
|
||||
|
||||
private :add_comment
|
||||
private :create, :edit, :update, :destroy
|
||||
|
||||
end
|
||||
@@ -0,0 +1,115 @@
|
||||
require 'port_pkg'
|
||||
|
||||
class PortPkgController < ApplicationController
|
||||
def index
|
||||
list
|
||||
render :action => 'list'
|
||||
end
|
||||
|
||||
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
|
||||
verify :method => :post, :only => [ :destroy, :create, :update ],
|
||||
:redirect_to => { :action => :list }
|
||||
|
||||
def list
|
||||
@port_pkg_pages, @port_pkgs = paginate :port_pkgs, :per_page => 10
|
||||
end
|
||||
|
||||
def show
|
||||
@port_pkg = PortPkg.find(params[:id])
|
||||
end
|
||||
|
||||
def new
|
||||
@port_pkg = PortPkg.new
|
||||
end
|
||||
|
||||
def create
|
||||
@port_pkg = PortPkg.new(params[:port_pkg])
|
||||
if @port_pkg.save
|
||||
flash[:notice] = 'PortPkg was successfully created.'
|
||||
redirect_to :action => 'list'
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@port_pkg = PortPkg.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@port_pkg = PortPkg.find(params[:id])
|
||||
if @port_pkg.update_attributes(params[:port_pkg])
|
||||
flash[:notice] = 'PortPkg was successfully updated.'
|
||||
redirect_to :action => 'show', :id => @port_pkg
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
PortPkg.find(params[:id]).destroy
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
|
||||
def submit
|
||||
portpkg = params[:portpkg]
|
||||
|
||||
begin
|
||||
# Validate parameters (we're probably making this too hard)
|
||||
raise "bad package" if portpkg.nil?
|
||||
|
||||
# Create a package from the file
|
||||
@port_pkg = PortPkg.create_from_file(portpkg)
|
||||
|
||||
download_url = portpkg_url(:id => @port_pkg)
|
||||
human_url = url_for(:controller => "port_pkg", :action => "show", :id => @port_pkg)
|
||||
render :text => "STATUS: 0\n" +
|
||||
"MESSAGE: PortPkg submitted successfully\n" +
|
||||
"DOWNLOAD_URL: #{download_url}\n" +
|
||||
"HUMAN_URL: #{human_url}\n"
|
||||
rescue FileInfoException => ex
|
||||
render :text => "STATUS: 1\n" +
|
||||
"MESSAGE: Error during submit: #{ex}\n", :status => 400
|
||||
end
|
||||
end
|
||||
|
||||
def emit_portpkg
|
||||
port_pkg = PortPkg.find(params[:id])
|
||||
redirect_to :controller => 'file_ref', :action => 'emit',
|
||||
:id => port_pkg.portpkg_file_ref()
|
||||
end
|
||||
|
||||
def emit_portpkg_path
|
||||
port_pkg = PortPkg.find(params[:id])
|
||||
redirect_to :controller => 'file_ref', :action => 'emit',
|
||||
:id => port_pkg.file_ref_by_path(params[:path].join, '/')
|
||||
end
|
||||
|
||||
def tag
|
||||
port_pkg = PortPkg.find(params[:id])
|
||||
params[:tags].split(/,?[ ]+/).each do |t|
|
||||
if t =~ /\-(.*)/
|
||||
port_pkg.remove_tag($1) if $1
|
||||
elsif t =~ /\+?(.+)/
|
||||
port_pkg.add_tag($1)
|
||||
end
|
||||
end
|
||||
redirect_to :action => 'show', :id => port_pkg
|
||||
end
|
||||
|
||||
def add_comment
|
||||
port_pkg = PortPkg.find(params[:id])
|
||||
text = params[:text]
|
||||
|
||||
if text
|
||||
# TODO: Figure out the real maintainer
|
||||
port_pkg.comments << Comment.create(:commenter => port_pkg.submitter, :comment => text)
|
||||
end
|
||||
|
||||
redirect_to :action => 'show', :id => port_pkg
|
||||
end
|
||||
|
||||
private :add_comment
|
||||
private :create, :edit, :update, :destroy
|
||||
|
||||
end
|
||||
@@ -0,0 +1,184 @@
|
||||
require "fileutils"
|
||||
|
||||
# NOTE: THIS CODE IS OBSOLETE AND NOT BEING USED AT PRESENT
|
||||
#
|
||||
# But it is an example to use in case we decide to auto-commit
|
||||
# some things into svn
|
||||
|
||||
class PortsController < ApplicationController
|
||||
|
||||
def makeTempDir()
|
||||
tmpdir = Dir::tmpdir
|
||||
basename = "mpwa"
|
||||
n = 1
|
||||
begin
|
||||
tmpname = File.join(tmpdir, sprintf('%s.%d.%d', basename, $$, n))
|
||||
n += 1
|
||||
next if File.exist?(tmpname)
|
||||
begin
|
||||
Dir.mkdir(tmpname)
|
||||
rescue SystemCallError
|
||||
next
|
||||
end
|
||||
end while !File.exist?(tmpname)
|
||||
return tmpname
|
||||
end
|
||||
|
||||
def subversionCommand(args)
|
||||
puts "subversion: #{svn} #{args}"
|
||||
`#{svn} #{args}`
|
||||
end
|
||||
|
||||
def ensureRepositoryPath(root, path)
|
||||
# Make sure the root director exists
|
||||
assert { File.directory?(root) }
|
||||
|
||||
# Step through path, building each component that doesn't exist
|
||||
Pathname.new(path).descend do |p|
|
||||
full = Pathname.new(root) + p
|
||||
if !full.directory?
|
||||
full.mkdir
|
||||
subversionCommand("add #{full}")
|
||||
subversionCommand("commit -m 'Make repository path segment' #{full}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def buildPortPkgDirPrefixPath(pkgId)
|
||||
# Two Level Cache
|
||||
# First level is low 6 bits of pkgId
|
||||
# Second level is next 6 bits of pkgId
|
||||
|
||||
lev1 = pkgId & 0x3f
|
||||
lev2 = pkgId >> 6 & 0x3f
|
||||
path = format('%02x/%02x', lev1, lev2)
|
||||
end
|
||||
|
||||
def buildPortPkgDirPath(pkgId)
|
||||
prefix = buildPortPkgDirPrefixPath(pkgId)
|
||||
path = format('%s/%016x', prefix, pkgId)
|
||||
end
|
||||
|
||||
def submit
|
||||
# TODO:
|
||||
# => Move some of this into the model
|
||||
# => And/or break up into more methods
|
||||
|
||||
# Get and validate parameters
|
||||
@portName = params[:portname]
|
||||
@portpkg = params[:portpkg]
|
||||
|
||||
# Validate parameters (we're probably making this too hard)
|
||||
raise "bad portName" if @portName.nil?
|
||||
raise "bad package" if @portpkg.nil?
|
||||
|
||||
tempDir = makeTempDir
|
||||
portpkg = "#{tempDir}/portpkg.xar"
|
||||
pkgdir = "#{tempDir}/portpkg"
|
||||
common = "#{tempDir}/common"
|
||||
target = "#{tempDir}/target"
|
||||
|
||||
# Form partial path to the common directory for the portname
|
||||
firstChar = @portName[0,1].downcase
|
||||
commonPartial = "common/#{firstChar}/#{@portName}"
|
||||
|
||||
# Look for, and create if not found, the common directory for the port
|
||||
ensureRepositoryPath(repo_portpkgs, commonPartial)
|
||||
|
||||
# Unpack the submitted portdir into a temporary directory
|
||||
File.open(portpkg, "w") { |f| f.write(@portpkg.read) }
|
||||
|
||||
# Note: a bug in xar presently prevents us from limiting the extraction to the portpkg directory,
|
||||
# => which we'd like to do for the sake of cleanliness. Hopefully this will become fixed soon.
|
||||
system("cd #{tempDir}; #{xar} -xf #{portpkg}")
|
||||
|
||||
# Check out a private temporary copy of the common directory
|
||||
# so that we don't get into concurrency issues by multi-modifying the directory
|
||||
subversionCommand("co #{repo_portpkgs_url}/#{commonPartial} #{common}")
|
||||
|
||||
# Sync the submission into the common directory by parsing the results of mtree
|
||||
changeCnt = 0
|
||||
treeOut = `#{mtree} -c -k type,cksum -p #{pkgdir} | #{mtree} -p #{common}`
|
||||
treeOut.each_line do |line|
|
||||
puts "Line #{line}"
|
||||
|
||||
case line
|
||||
when /^\w+/
|
||||
puts "Whitespace line #$1"
|
||||
|
||||
when /^(.*) changed$/
|
||||
srcFile = File.join(pkgdir, $1)
|
||||
dstFile = File.join(common, $1)
|
||||
puts "Changed file #{srcFile} != #{dstFile}"
|
||||
FileUtils.cp(srcFile, dstFile)
|
||||
changeCnt += 1
|
||||
|
||||
when /^(.*) extra$/
|
||||
dstFile = File.join(common, $1)
|
||||
if /^\./ =~ File.basename(dstFile)
|
||||
puts "Skipping invisible extra entry #{dstFile}"
|
||||
else
|
||||
puts "Extra entry #{dstFile}"
|
||||
subversionCommand("rm #{dstFile}")
|
||||
changeCnt += 1
|
||||
end
|
||||
|
||||
when /^(.*) missing$/
|
||||
srcFile = File.join(pkgdir, $1)
|
||||
dstFile = File.join(common, $1)
|
||||
|
||||
if /^\./ =~ File.basename(dstFile)
|
||||
puts "Skipping invisible new entry #{dstFile}"
|
||||
else
|
||||
puts "New entry #{srcFile} ==> #{dstFile}"
|
||||
|
||||
if File.directory?(srcFile)
|
||||
subversionCommand("mkdir #{dstFile}")
|
||||
else
|
||||
FileUtils.cp(srcFile, dstFile)
|
||||
subversionCommand("add #{dstFile}")
|
||||
end
|
||||
|
||||
changeCnt += 1
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
if changeCnt == 0
|
||||
puts "No changes detected, so don't create a new submission"
|
||||
else
|
||||
puts "Creating new submission from #{common}"
|
||||
|
||||
# Commit changes to the common directory
|
||||
commitOutput = subversionCommand("commit -m 'New portpkg of #{@portName}' #{common}")
|
||||
commitRevision = /^Committed revision (\d+)./.match(commitOutput)[1]
|
||||
|
||||
# Form the portid from the committed revision number
|
||||
pkgId = commitRevision.to_i
|
||||
portPkgDirPrefix = buildPortPkgDirPrefixPath(pkgId)
|
||||
portPkgDir = buildPortPkgDirPath(pkgId);
|
||||
|
||||
puts "Creating new portpkg #{pkgId} at #{repo_portpkgs}/#{portPkgDir}"
|
||||
|
||||
# Make sure there's a path to the repository location for the portPkg
|
||||
ensureRepositoryPath(repo_portpkgs, portPkgDirPrefix)
|
||||
|
||||
# Make the portPkg directory
|
||||
FileUtils.mkdir("#{repo_portpkgs}/#{portPkgDir}")
|
||||
subversionCommand("add #{repo_portpkgs}/#{portPkgDir}")
|
||||
|
||||
# Add original package and meta directory
|
||||
FileUtils.cp(portpkg, "#{repo_portpkgs}/#{portPkgDir}/portpkg.xar")
|
||||
FileUtils.mkdir("#{repo_portpkgs}/#{portPkgDir}/meta")
|
||||
subversionCommand("add #{repo_portpkgs}/#{portPkgDir}/portpkg.xar #{repo_portpkgs}/#{portPkgDir}/meta")
|
||||
|
||||
# Copy the common directory into unpacked
|
||||
subversionCommand("cp #{common} #{repo_portpkgs}/#{portPkgDir}/unpacked")
|
||||
|
||||
# Commit the portpkg directory
|
||||
subversionCommand("commit -m 'Complete portpkg #{pkgId} of port #{@portName}' #{repo_portpkgs}/#{portPkgDir}")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,63 @@
|
||||
class TagController < ApplicationController
|
||||
|
||||
def index
|
||||
list
|
||||
render :action => 'list'
|
||||
end
|
||||
|
||||
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
|
||||
verify :method => :post, :only => [ :destroy, :create, :update ],
|
||||
:redirect_to => { :action => :list }
|
||||
|
||||
def list
|
||||
@tag_pages, @tags = paginate :tags, :per_page => 128, :order => 'name'
|
||||
end
|
||||
|
||||
def show
|
||||
if !params[:name].nil?
|
||||
@key = params[:name]
|
||||
@tag = Tag.find_by_name(params[:name])
|
||||
render :action => 'notag' if @tag.nil?
|
||||
else
|
||||
@key = params[:id]
|
||||
@tag = Tag.find(params[:id])
|
||||
render :action => 'notag' if @tag.nil?
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@tag = Tag.new
|
||||
end
|
||||
|
||||
def create
|
||||
@tag = Tag.new(params[:tag])
|
||||
if @tag.save
|
||||
flash[:notice] = 'Tag was successfully created.'
|
||||
redirect_to :action => 'list'
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@tag = Tag.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@tag = Tag.find(params[:id])
|
||||
if @tag.update_attributes(params[:tag])
|
||||
flash[:notice] = 'Tag was successfully updated.'
|
||||
redirect_to :action => 'show', :id => @tag
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
Tag.find(params[:id]).destroy
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
|
||||
private :create, :edit, :update, :destroy
|
||||
|
||||
end
|
||||
@@ -0,0 +1,54 @@
|
||||
class VariantController < ApplicationController
|
||||
def index
|
||||
list
|
||||
render :action => 'list'
|
||||
end
|
||||
|
||||
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
|
||||
verify :method => :post, :only => [ :destroy, :create, :update ],
|
||||
:redirect_to => { :action => :list }
|
||||
|
||||
def list
|
||||
@variant_pages, @variants = paginate :variants, :per_page => 10
|
||||
end
|
||||
|
||||
def show
|
||||
@variant = Variant.find(params[:id])
|
||||
end
|
||||
|
||||
def new
|
||||
@variant = Variant.new
|
||||
end
|
||||
|
||||
def create
|
||||
@variant = Variant.new(params[:variant])
|
||||
if @variant.save
|
||||
flash[:notice] = 'Variant was successfully created.'
|
||||
redirect_to :action => 'list'
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@variant = Variant.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@variant = Variant.find(params[:id])
|
||||
if @variant.update_attributes(params[:variant])
|
||||
flash[:notice] = 'Variant was successfully updated.'
|
||||
redirect_to :action => 'show', :id => @variant
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
Variant.find(params[:id]).destroy
|
||||
redirect_to :action => 'list'
|
||||
end
|
||||
|
||||
private :create, :edit, :update, :destroy
|
||||
|
||||
end
|
||||
@@ -0,0 +1,17 @@
|
||||
# Methods added to this helper will be available to all templates in the application.
|
||||
module ApplicationHelper
|
||||
|
||||
def email_obfuscate(str)
|
||||
if str =~ /(.+)@(.+)/
|
||||
localname = $1
|
||||
domain = $2
|
||||
if domain =~ /macports.org/i
|
||||
str = localname
|
||||
else
|
||||
str = "#{domain}:#{localname}"
|
||||
end
|
||||
end
|
||||
return str
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,2 @@
|
||||
module FileBlobHelper
|
||||
end
|
||||
@@ -0,0 +1,2 @@
|
||||
module FileInfosHelper
|
||||
end
|
||||
@@ -0,0 +1,2 @@
|
||||
module FileRefsHelper
|
||||
end
|
||||
@@ -0,0 +1,2 @@
|
||||
module MacPortsHelper
|
||||
end
|
||||
@@ -0,0 +1,2 @@
|
||||
module PersonHelper
|
||||
end
|
||||
@@ -0,0 +1,2 @@
|
||||
module PortHelper
|
||||
end
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user