aboutsummaryrefslogtreecommitdiff
path: root/sources/potlatch
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2013-01-24 15:54:19 +0100
committerJochen Topf <jochen@topf.org>2013-01-24 15:54:19 +0100
commit38095b40997a08a0b7e5155da442fa77165ce556 (patch)
treeb46b031fad2b6a7cbff9ef11e44997455cf5f63d /sources/potlatch
parent55550a88ff517d48ca6e56f720c4080fdb569ac9 (diff)
downloadtaginfo-38095b40997a08a0b7e5155da442fa77165ce556.tar
taginfo-38095b40997a08a0b7e5155da442fa77165ce556.tar.gz
Updated ruby import scripts
* Removed rubygems require which isn't needed any more in Ruby 1.9 * Updated transaction syntax to use blocks * Updated copyright year
Diffstat (limited to 'sources/potlatch')
-rwxr-xr-xsources/potlatch/import_potlatch.rb67
1 files changed, 32 insertions, 35 deletions
diff --git a/sources/potlatch/import_potlatch.rb b/sources/potlatch/import_potlatch.rb
index f99926a..c63670d 100755
--- a/sources/potlatch/import_potlatch.rb
+++ b/sources/potlatch/import_potlatch.rb
@@ -7,7 +7,7 @@
#
#------------------------------------------------------------------------------
#
-# Copyright (C) 2012 Jochen Topf <jochen@remote.org>
+# Copyright (C) 2013 Jochen Topf <jochen@remote.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -25,56 +25,53 @@
#
#------------------------------------------------------------------------------
-require 'rubygems'
-
-require 'pp'
require 'sqlite3'
require 'rexml/document'
dir = ARGV[0] || '.'
-
db = SQLite3::Database.new(dir + '/taginfo-potlatch.db')
-db.execute('BEGIN TRANSACTION');
+#------------------------------------------------------------------------------
-file = File.new(dir + '/git-source/resources/map_features.xml')
-doc = REXML::Document.new(file)
+db.transaction do |db|
+ file = File.new(dir + '/git-source/resources/map_features.xml')
+ doc = REXML::Document.new(file)
-doc.elements.each('/mapFeatures/category') do |category_element|
- db.execute('INSERT INTO categories (id, name) VALUES (?, ?)', category_element.attributes['id'], category_element.attributes['name'])
-end
+ doc.elements.each('/mapFeatures/category') do |category_element|
+ db.execute('INSERT INTO categories (id, name) VALUES (?, ?)', category_element.attributes['id'], category_element.attributes['name'])
+ end
-doc.elements.each('/mapFeatures/feature') do |feature_element|
- feature_name = feature_element.attributes['name']
+ doc.elements.each('/mapFeatures/feature') do |feature_element|
+ feature_name = feature_element.attributes['name']
- on = { :point => 0, :line => 0, :area => 0, :relation => 0 }
+ on = { :point => 0, :line => 0, :area => 0, :relation => 0 }
- fields = Hash.new
- feature_element.elements.each do |element|
- case element.name
- when 'tag'
- value = element.attributes['v'] == '*' ? nil : element.attributes['v']
- db.execute('INSERT INTO tags (key, value, feature_name) VALUES (?, ?, ?)', element.attributes['k'], value, feature_name)
- when /^(point|line|area|relation)$/
- on[$1.to_sym] = 1
- when /^(category|help)$/
- fields[element.name] = element.text.strip
- when 'icon'
- fields['icon_image'] = element.attributes['image']
- fields['icon_background'] = element.attributes['background']
- fields['icon_foreground'] = element.attributes['foreground']
+ fields = Hash.new
+ feature_element.elements.each do |element|
+ case element.name
+ when 'tag'
+ value = element.attributes['v'] == '*' ? nil : element.attributes['v']
+ db.execute('INSERT INTO tags (key, value, feature_name) VALUES (?, ?, ?)', element.attributes['k'], value, feature_name)
+ when /^(point|line|area|relation)$/
+ on[$1.to_sym] = 1
+ when /^(category|help)$/
+ fields[element.name] = element.text.strip
+ when 'icon'
+ fields['icon_image'] = element.attributes['image']
+ fields['icon_background'] = element.attributes['background']
+ fields['icon_foreground'] = element.attributes['foreground']
+ end
+ end
+
+ if on[:point] + on[:line] + on[:area] + on[:relation] == 0
+ on = { :point => 1, :line => 1, :area => 1, :relation => 1 }
end
- end
- if on[:point] + on[:line] + on[:area] + on[:relation] == 0
- on = { :point => 1, :line => 1, :area => 1, :relation => 1 }
+ db.execute('INSERT INTO features (name, category_id, help, on_point, on_line, on_area, on_relation, icon_image, icon_background, icon_foreground) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
+ feature_name, fields['category'], fields['help'], on[:point], on[:line], on[:area], on[:relation], fields['icon_image'], fields['icon_background'], fields['icon_foreground'])
end
- db.execute('INSERT INTO features (name, category_id, help, on_point, on_line, on_area, on_relation, icon_image, icon_background, icon_foreground) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
- feature_name, fields['category'], fields['help'], on[:point], on[:line], on[:area], on[:relation], fields['icon_image'], fields['icon_background'], fields['icon_foreground'])
end
-db.execute('COMMIT');
-
#-- THE END -------------------------------------------------------------------