[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 16:27:19 -0700 |
CVSROOT: /home/cvs
Module name: gnue
Changes by: Neil Tiffin <address@hidden> 01/07/06 16:27:19
Modified files:
geas/tools : parse_load_sql.py
Log message:
First working version.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/tools/parse_load_sql.py.diff?cvsroot=OldCVS&tr1=1.1&tr2=1.2&r1=text&r2=text
Patches:
Index: gnue/geas/tools/parse_load_sql.py
diff -u gnue/geas/tools/parse_load_sql.py:1.1
gnue/geas/tools/parse_load_sql.py:1.2
--- gnue/geas/tools/parse_load_sql.py:1.1 Fri Jul 6 10:46:47 2001
+++ gnue/geas/tools/parse_load_sql.py Fri Jul 6 16:27:19 2001
@@ -24,12 +24,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.1 2001/07/06 17:46:47 ntiffin Exp $
+# $Id: parse_load_sql.py,v 1.2 2001/07/06 23:27:19 ntiffin Exp $
#
import os
import sys
import getopt
+import re
+import string
my_uuids = []
@@ -38,26 +40,77 @@
if (len(my_uuids) < 2):
f = os.popen("./gen_uuid -n 25", "r")
uuids = f.readlines()
- my_uuids.append(uuids)
+ for uuid in uuids:
+ if len(uuid) and (uuid[-1] == "\n"):
+ my_uuids.append(uuid[:-1])
f.close()
return my_uuids.pop()
-
-# if -d then use that for dir else use current dir
-getopt.getopt(sys.argv, "d")
+temp = get_uuid()
+print my_uuids
+print "A uuid = ", get_uuid()
+print "whats left"
+print my_uuids
+
+options, args = getopt.getopt(sys.argv, "")
+
# get top level directory name
+if (len(args) > 1):
+ current_dir = os.path.abspath(args[1])
+else:
+ current_dir = os.getcwd()
+print "Starting at directory: ", current_dir
# scan all files for *.sql format
+sql_file_list = []
+dir_list = []
+dir_list.append( current_dir)
+
+while (len(dir_list) > 0):
+ current_dir = dir_list.pop()
+ # print "Len after pop: ", len(dir_list)
+ # print "Processing directory: ", current_dir
+ dir_contents = os.listdir(current_dir)
+ # print "Dir Contents: ", dir_contents
+ for item in dir_contents:
+ # print "Doing item: ", item
+ full_item = os.path.join(current_dir, item)
+ if os.path.isdir(full_item):
+ 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)
+ if m != None:
+ sql_file_list.append(full_item)
+ print "Found SQL file: ", full_item
# 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)? ")
# 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
+ 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"
+ all_lines = file_in.readlines()
+ for line in all_lines:
+ new_line = string.replace(line, "GEAS-OBJECT-ID",
get_uuid() )
+ file_out.write(new_line)
+
+# pass each file to psql
-# for each file selected replace OBJECTID with uuid
-# pass each file to psql
+
+