Megatest

Check-in [f1295e0ec5]
Login
Overview
Comment:First pass at txtdb reader
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: f1295e0ec52fbd4c4b86d2e89dc2de5fa06a8461
User & Date: matt on 2013-07-14 10:58:00
Other Links: branch diff | manifest | tags
Context
2013-07-14
13:31
read-dat for txtdb completed check-in: eb02e8c328 user: matt tags: dev
10:58
First pass at txtdb reader check-in: f1295e0ec5 user: matt tags: dev
03:56
Added full import from gnumeric format and a stub for reading from txtdb check-in: 93afeeb4bd user: matt tags: dev
Changes

Modified txtdb/txtdb.scm from [5e94ada62d] to [2933c5fd59].

114
115
116
117
118
119
120




121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136



137
138
139
140
141
142
143
144
145
146
								 (string? b))
							    (string< a b))))))))))
    (with-output-to-file (conc targdir "/xml/" sheet-name ".xml")
      (lambda ()
	(print (sxml-serializer#serialize-sxml remaining))))
    sheet-name))






(define (extract-txtdb dat targdir)
  (let* ((wrkbk   (find-section   dat   'http://www.gnumeric.org/v10.dtd:Workbook))
	 (wrk-rem (remove-section dat   'http://www.gnumeric.org/v10.dtd:Workbook))
	 (sheets  (find-section   wrkbk 'http://www.gnumeric.org/v10.dtd:Sheets))
	 (sht-rem (remove-section wrkbk 'http://www.gnumeric.org/v10.dtd:Sheets)))
    (create-directory (conc targdir "/xml") #t)
    (with-output-to-file (conc targdir "/xml/workbook.xml")
      (lambda ()
	(print (sxml-serializer#serialize-sxml wrk-rem))))
    (with-output-to-file (conc targdir "/xml/sheets.xml")
      (lambda ()
	(print (sxml-serializer#serialize-sxml sht-rem))))
    (let ((sheet-names (map (lambda (sheet)
			      (sheet->txtdb sheet targdir))
			    sheets)))



      (with-output-to-file (conc targdir "/sheet-names.cfg")
	(lambda ()
	  (map print sheet-names))))))

(define (read-gnumeric-file fname)
  (if (not (string-match (regexp ".*.gnumeric$") fname))
      (begin
	(print "ERROR: Attempt to import gnumeric file with extention other than .gnumeric")
	(exit))
      (let ((tmpf (create-temporary-file (pathname-strip-directory fname))))







>
>
>
>


|
|
|
|
<
<
<
<
<
<
<
|
|
|
>
>
>
|
|
|







114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130







131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
								 (string? b))
							    (string< a b))))))))))
    (with-output-to-file (conc targdir "/xml/" sheet-name ".xml")
      (lambda ()
	(print (sxml-serializer#serialize-sxml remaining))))
    sheet-name))

(define (sxml->file dat fname)
  (with-output-to-file fname
    (lambda ()
      (print (sxml-serializer#serialize-sxml dat)))))

(define (extract-txtdb dat targdir)
  (let* ((wrkbk       (find-section   dat   'http://www.gnumeric.org/v10.dtd:Workbook))
	 (wrk-rem     (remove-section dat   'http://www.gnumeric.org/v10.dtd:Workbook))
	 (sheets      (find-section   wrkbk 'http://www.gnumeric.org/v10.dtd:Sheets))
	 (sht-rem     (remove-section wrkbk 'http://www.gnumeric.org/v10.dtd:Sheets))







	 (sheet-names (map (lambda (sheet)
			     (sheet->txtdb sheet targdir))
			   sheets)))
    (create-directory (conc targdir "/xml") #t)
    (sxml->file wrk-rem (conc targdir "/xml/workbook.xml"))
    (sxml->file sht-rem (conc targdir "/xml/sheets.xml"))
    (with-output-to-file (conc targdir "/sheet-names.cfg")
      (lambda ()
	(map print sheet-names)))))

(define (read-gnumeric-file fname)
  (if (not (string-match (regexp ".*.gnumeric$") fname))
      (begin
	(print "ERROR: Attempt to import gnumeric file with extention other than .gnumeric")
	(exit))
      (let ((tmpf (create-temporary-file (pathname-strip-directory fname))))
157
158
159
160
161
162
163
164



165



166
167

168
169
170
171



172
173
174
175
176
177
178
	(tmpf     (create-temporary-file (pathname-strip-directory fname))))
    (with-output-to-file tmpf
      (lambda ()
	(print (sxml-serializer#serialize-sxml sxml-dat))))
    (system (conc "gzip " tmpf))
    (file-copy tmpf fname)
    (delete-file tmpf)))
    



(define (txtdb->sxml dbdir)



  ;; Read sheets list
  ;; Read sheets

  ;; Read xml for each sheet
  ;; Read meta data xml
  ;; Construct the final sxml and return it
  #f)




#|  
 (define x (txtdb:read-gnumeric-xml "testdata-stripped.xml"))



;; Write out sxml







|
>
>
>

>
>
>
|
|
>
|
<
<
|
>
>
>







157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175


176
177
178
179
180
181
182
183
184
185
186
	(tmpf     (create-temporary-file (pathname-strip-directory fname))))
    (with-output-to-file tmpf
      (lambda ()
	(print (sxml-serializer#serialize-sxml sxml-dat))))
    (system (conc "gzip " tmpf))
    (file-copy tmpf fname)
    (delete-file tmpf)))

(define (read-dat fname)
  (read-file fname read-line)) ;; Placeholder!
    
(define (txtdb->sxml dbdir)
  (let* ((sht-names (read-file (conc dbdir "/sheet-names.cfg")  read-line))
	 (wrk-rem   (read-file (conc dbdir "/xml/workbook.xml") read-line))
	 (sht-rem   (read-file (conc dbdir "/xml/sheets.xml")   read-line))
	 (sheets    (fold (lambda (sheetname res)
			    (let ((sheetdat (read-dat (conc dbdir "/" sheetname ".dat")))
				  (sht-meta (txtdb:read-gnumeric-xml (conc dbdir "/xml/" sheetname ".xml"))))
			      (cons (cons sht-meta sheetdat)


				    res)))
			  '()
			  sht-names)))
    (append wrk-rem (list sheets))))

#|  
 (define x (txtdb:read-gnumeric-xml "testdata-stripped.xml"))



;; Write out sxml