[69352] branches/gsoc10-mpwa/mpwa/db
jrozner at macports.org
jrozner at macports.org
Thu Jul 1 22:57:40 PDT 2010
Revision: 69352
http://trac.macports.org/changeset/69352
Author: jrozner at macports.org
Date: 2010-07-01 22:57:37 -0700 (Thu, 01 Jul 2010)
Log Message:
-----------
#!/usr/bin/env ruby
require 'active_record'
TIME_FILE = "/var/tmp/mpwa-sync"
NEW_PORTS = "/Users/joe/Dev/gsoc10-mpwa/bin/new-ports"
PORT_INDEX = "/opt/local/var/macports/sources/rsync.macports.org/release/ports"
RAILS_ROOT = "/Users/joe/Dev/gsoc10-mpwa/mpwa"
require File.expand_path(RAILS_ROOT + '/app/models/category.rb', __FILE__)
require File.expand_path(RAILS_ROOT + '/app/models/port.rb', __FILE__)
require File.expand_path(RAILS_ROOT + '/app/models/port_dependency.rb', __FILE__)
require File.expand_path(RAILS_ROOT + '/app/models/supplemental_category.rb', __FILE__)
if File.exists?(TIME_FILE)
$mtime = File.stat(TIME_FILE).mtime.to_i
else
$mtime = 0
end
$ports = Array.new
$hashed_data = Hash.new
db_info = YAML.load_file(File.expand_path(RAILS_ROOT + '/config/database.yml', __FILE__))
ActiveRecord::Base.establish_connection(db_info['development'])
fp = IO.popen("#{NEW_PORTS} -m #{$mtime} #{PORT_INDEX}")
new_ports = fp.read.split("\n")
new_ports.each do |line|
unless (line == "")
data = line.match(/(\S+):\s+\{?(.+)\}?$/)
unless data.nil? #field missing, should record this if it happens
$hashed_data[data[1].to_sym] = data[2]
end
else
port = Port.new({
:name => $hashed_data[:name],
:path => $hashed_data[:portdir],
:version => $hashed_data[:version],
:description => $hashed_data[:description],
:licenses => $hashed_data[:license],
:category_id => Category.find_by_name($hashed_data[:categories].split(" ")[0]).id,
:variants => $hashed_data[:variants],
:maintainers => $hashed_data[:maintainers],
:platforms => $hashed_data[:platforms]
})
$ports << [$hashed_data, port]
port.save
$hashed_data = {}
end
end
$ports.each do |port|
categories = port[0][:categories].split(" ")
unless (categories.count < 2)
categories[1..-1].each do |category|
port[1].supplemental_categories.build({:name => category}).save!
end
end
dependencies = Array.new
unless port[0][:depends_lib].nil?
dependencies << port[0][:depends_lib].split(" ")
end
unless port[0][:depends_run].nil?
dependencies << port[0][:depends_run].split(" ")
end
unless port[0][:depends_build].nil?
dependencies << port[0][:depends_build].split(" ")
end
dependencies.flatten.uniq.each do |dependency|
name = dependency.match(/.+:(.+)/)[1]
dep = Port.find_by_name(name)
unless dep.nil? #should provide the info that the port doesn't exist eventually
port[1].port_dependencies.build({:dependency_id => dep.id}).save!
end
end
end
Modified Paths:
--------------
branches/gsoc10-mpwa/mpwa/db/schema.rb
Added Paths:
-----------
branches/gsoc10-mpwa/mpwa/db/migrate/20100702053149_add_platforms_to_ports.rb
Added: branches/gsoc10-mpwa/mpwa/db/migrate/20100702053149_add_platforms_to_ports.rb
===================================================================
--- branches/gsoc10-mpwa/mpwa/db/migrate/20100702053149_add_platforms_to_ports.rb (rev 0)
+++ branches/gsoc10-mpwa/mpwa/db/migrate/20100702053149_add_platforms_to_ports.rb 2010-07-02 05:57:37 UTC (rev 69352)
@@ -0,0 +1,9 @@
+class AddPlatformsToPorts < ActiveRecord::Migration
+ def self.up
+ add_column :ports, :platforms, :string
+ end
+
+ def self.down
+ remove_column :ports, :platforms
+ end
+end
\ No newline at end of file
Modified: branches/gsoc10-mpwa/mpwa/db/schema.rb
===================================================================
--- branches/gsoc10-mpwa/mpwa/db/schema.rb 2010-07-01 20:41:09 UTC (rev 69351)
+++ branches/gsoc10-mpwa/mpwa/db/schema.rb 2010-07-02 05:57:37 UTC (rev 69352)
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20100624234814) do
+ActiveRecord::Schema.define(:version => 20100702053149) do
create_table "categories", :force => true do |t|
t.string "name"
@@ -42,6 +42,7 @@
t.datetime "created_at"
t.datetime "updated_at"
t.string "maintainers"
+ t.string "platforms"
end
create_table "supplemental_categories", :force => true do |t|
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20100701/68f5b3df/attachment.html>
More information about the macports-changes
mailing list