[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/geas/tools parse_load_sql.py
From: |
Neil Tiffin |
Subject: |
gnue/geas/tools parse_load_sql.py |
Date: |
Fri, 06 Jul 2001 19:29:57 -0700 |
CVSROOT: /home/cvs
Module name: gnue
Changes by: Neil Tiffin <address@hidden> 01/07/06 19:29:57
Modified files:
geas/tools : parse_load_sql.py
Log message:
Mostly working now.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/tools/parse_load_sql.py.diff?cvsroot=OldCVS&tr1=1.2&tr2=1.3&r1=text&r2=text
Patches:
Index: gnue/geas/tools/parse_load_sql.py
diff -u gnue/geas/tools/parse_load_sql.py:1.2
gnue/geas/tools/parse_load_sql.py:1.3
--- gnue/geas/tools/parse_load_sql.py:1.2 Fri Jul 6 16:27:19 2001
+++ gnue/geas/tools/parse_load_sql.py Fri Jul 6 19:29:57 2001
@@ -1,8 +1,9 @@
#!/usr/bin/env python
#
-# parse_load_sql.py - parse *.sql files and substitute
-# /*GEAS_OBJECT_ID*/ with real
-# object id, then load files into
+# parse_load_sql.py - parse *.geas files and substitute
+# GEAS_OBJECT_ID with real
+# object id, create .sql file then
+# load files into
# SQL database.
#
# Copyright 2001 Free Software Foundation
@@ -24,8 +25,14 @@
# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.
#
-# $Id: parse_load_sql.py,v 1.2 2001/07/06 23:27:19 ntiffin Exp $
+# $Id: parse_load_sql.py,v 1.3 2001/07/07 02:29:57 ntiffin Exp $
#
+# the format of the .geas file is as follows:
+# INSERT INTO must start in col 1 and must preceed any data
+#
+# all data lines must end with ; and start with left parenthesis
+# ("data");
+#
import os
import sys
@@ -46,11 +53,11 @@
f.close()
return my_uuids.pop()
-temp = get_uuid()
-print my_uuids
-print "A uuid = ", get_uuid()
-print "whats left"
-print my_uuids
+# temp = get_uuid()
+# print my_uuids
+# print "A uuid = ", get_uuid()
+# print "whats left"
+# print my_uuids
options, args = getopt.getopt(sys.argv, "")
@@ -60,9 +67,11 @@
else:
current_dir = os.getcwd()
print "Starting at directory: ", current_dir
+current_dir_keep = current_dir
# scan all files for *.sql format
sql_file_list = []
+sql_load_file_list = []
dir_list = []
dir_list.append( current_dir)
@@ -79,38 +88,51 @@
dir_list.append(os.path.abspath(full_item))
# print "Found Path: ", full_item
if os.path.isfile(full_item):
- m = re.match(".*\.sql$", full_item)
+ m = re.match(r'^insert.*\.geas$',
os.path.basename(full_item))
if m != None:
sql_file_list.append(full_item)
print "Found SQL file: ", full_item
+ # TODO should handle links
# ask to use stored file list or go thru each file found
# ask if process all or ask each one
do_all = "y"
do_this_one = "y"
-do_all = raw_input("Do you want to process all files (y/n)? ")
+do_all = raw_input("Do you want to process all files found (y/n)? ")
# if not all then
# for each file ask if wanted for processing
for file_name in sql_file_list:
if (do_all == "n" or do_all == "N"):
- print "File: ", file_name
+ print "\nFile: ", file_name
do_this_one = raw_input("Do you want to process this file
(y/n)? ")
# for each file selected replace OBJECTID with uuid
if do_this_one == "y" or do_this_one == "Y":
file_in = open( file_name, "r")
- file_out = open( file_name + ".geas", "w")
- print "Open out file: ", file_name + ".geas"
+ out_file_name = re.sub(r"\.geas$", ".sql", file_name, 1)
+ print "Open out file: ", out_file_name
+ sql_load_file_list.append(out_file_name)
+ file_out = open( out_file_name, "w")
all_lines = file_in.readlines()
+ prefix_line = ""
for line in all_lines:
- new_line = string.replace(line, "GEAS-OBJECT-ID",
get_uuid() )
+ if (line.startswith("INSERT INTO")):
+ prefix_line = line[:-1] + " ("
+ continue
+ new_line = re.sub( r'^\s*\(', prefix_line, line)
+ new_line = string.replace(new_line, "GEAS-OBJECT-ID",
get_uuid() )
file_out.write(new_line)
-
+ file_in.close()
+ file_out.close()
+
# pass each file to psql
-
-
-
-
+for each_file in sql_load_file_list:
+ print each_file
+ f = os.popen("psql -f "+each_file, "r")
+ output = f.readlines()
+ for line in output:
+ print line
+ f.close