Megatest

Check-in [564660d855]
Login
Overview
Comment:More datashare hacking done.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | v1.60
Files: files | file ages | folders
SHA1: 564660d8550181fb76511ed77788bf9b6ef0f1ff
User & Date: matt on 2014-08-24 17:08:47
Other Links: branch diff | manifest | tags
Context
2014-08-24
18:19
Enough of datashare implemented to demo check-in: c35d3e8493 user: matt tags: v1.60
17:08
More datashare hacking done. check-in: 564660d855 user: matt tags: v1.60
2014-08-23
13:58
Basics of get data in place check-in: 5cdc4cd6d0 user: matt tags: v1.60
Changes

Modified Makefile from [52d90a724c] to [53817c1730].

166
167
168
169
170
171
172
173
174
175
176

177
178
deploytarg/dboard :  $(OFILES) $(GOFILES) dashboard.scm deploytarg/apropos.so
	csc -deploy $(OFILES) $(GOFILES) dashboard.scm -o deploytarg
	mv deploytarg/deploytarg deploytarg/dboard

# DATASHAREO=configf.o common.o process.o tree.o dcommon.o margs.o launch.o gutils.o db.o synchash.o server.o \
#            megatest-version.o tdb.o ods.o mt.o keys.o
datashare-testing/datashare : datashare.scm $(OFILES)
	mkdir -p /tmp/$(USER)/datashare /tmp/$(USER)/datashare/disk1
	csc datashare.scm $(OFILES) -o datashare-testing/datashare

datashare : datashare-testing/datashare

	BASEPATH=/tmp/$(USER)/basepath ./datashare-testing/datashare








<



>


166
167
168
169
170
171
172

173
174
175
176
177
178
deploytarg/dboard :  $(OFILES) $(GOFILES) dashboard.scm deploytarg/apropos.so
	csc -deploy $(OFILES) $(GOFILES) dashboard.scm -o deploytarg
	mv deploytarg/deploytarg deploytarg/dboard

# DATASHAREO=configf.o common.o process.o tree.o dcommon.o margs.o launch.o gutils.o db.o synchash.o server.o \
#            megatest-version.o tdb.o ods.o mt.o keys.o
datashare-testing/datashare : datashare.scm $(OFILES)

	csc datashare.scm $(OFILES) -o datashare-testing/datashare

datashare : datashare-testing/datashare
	mkdir -p /tmp/$(USER)/datashare/disk1 /tmp/$(USER)/basepath
	BASEPATH=/tmp/$(USER)/basepath ./datashare-testing/datashare

Modified datashare.scm from [ee9522478a] to [38fe06106c].

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

88
89
90
91
92
93
94
95
96
97
98
99
100
101

102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

119
120
121
122
123
124
125

;;======================================================================
;; RECORDS
;;======================================================================

;; make-vector-record "testing" datastore pkg id area version_name store_type copied source_path iteration submitter datetime storegrp datavol quality disk_id comment
;; testing
(define (make-datastore:pkg)(make-vector 14))
(define-inline (datastore:pkg-get-id             vec)    (vector-ref  vec 0))
(define-inline (datastore:pkg-get-area           vec)    (vector-ref  vec 1))
(define-inline (datastore:pkg-get-version_name   vec)    (vector-ref  vec 2))
(define-inline (datastore:pkg-get-store_type     vec)    (vector-ref  vec 3))
(define-inline (datastore:pkg-get-copied         vec)    (vector-ref  vec 4))
(define-inline (datastore:pkg-get-source_path    vec)    (vector-ref  vec 5))
(define-inline (datastore:pkg-get-iteration      vec)    (vector-ref  vec 6))
(define-inline (datastore:pkg-get-submitter      vec)    (vector-ref  vec 7))
(define-inline (datastore:pkg-get-datetime       vec)    (vector-ref  vec 8))
(define-inline (datastore:pkg-get-storegrp       vec)    (vector-ref  vec 9))
(define-inline (datastore:pkg-get-datavol        vec)    (vector-ref  vec 10))
(define-inline (datastore:pkg-get-quality        vec)    (vector-ref  vec 11))
(define-inline (datastore:pkg-get-disk_id        vec)    (vector-ref  vec 12))
(define-inline (datastore:pkg-get-comment        vec)    (vector-ref  vec 13))

(define-inline (datastore:pkg-set-id!            vec val)(vector-set! vec 0 val))
(define-inline (datastore:pkg-set-area!          vec val)(vector-set! vec 1 val))
(define-inline (datastore:pkg-set-version_name!  vec val)(vector-set! vec 2 val))
(define-inline (datastore:pkg-set-store_type!    vec val)(vector-set! vec 3 val))
(define-inline (datastore:pkg-set-copied!        vec val)(vector-set! vec 4 val))
(define-inline (datastore:pkg-set-source_path!   vec val)(vector-set! vec 5 val))
(define-inline (datastore:pkg-set-iteration!     vec val)(vector-set! vec 6 val))
(define-inline (datastore:pkg-set-submitter!     vec val)(vector-set! vec 7 val))
(define-inline (datastore:pkg-set-datetime!      vec val)(vector-set! vec 8 val))
(define-inline (datastore:pkg-set-storegrp!      vec val)(vector-set! vec 9 val))
(define-inline (datastore:pkg-set-datavol!       vec val)(vector-set! vec 10 val))
(define-inline (datastore:pkg-set-quality!       vec val)(vector-set! vec 11 val))
(define-inline (datastore:pkg-set-disk_id!       vec val)(vector-set! vec 12 val))
(define-inline (datastore:pkg-set-comment!       vec val)(vector-set! vec 13 val))


;;======================================================================
;; DB
;;======================================================================

(define (datashare:initialize-db db)
  (for-each
   (lambda (qry)
     (sqlite3:execute db qry))
   (list 
    "CREATE TABLE pkgs 
         (id           INTEGER PRIMARY KEY,
          area         TEXT,
          version_name TEXT,
          store_type   TEXT DEFAULT 'copy',
          copied       INTEGER DEFAULT 0,
          source_path  TEXT,

          iteration    INTEGER DEFAULT 0,
          submitter    TEXT,
          datetime     TIMESTAMP DEFAULT (strftime('%s','now')),
          storegrp     TEXT,
          datavol      INTEGER,
          quality      TEXT,
          disk_id      INTEGER,







|














>














>

















>







66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128

;;======================================================================
;; RECORDS
;;======================================================================

;; make-vector-record "testing" datastore pkg id area version_name store_type copied source_path iteration submitter datetime storegrp datavol quality disk_id comment
;; testing
(define (make-datastore:pkg)(make-vector 15))
(define-inline (datastore:pkg-get-id             vec)    (vector-ref  vec 0))
(define-inline (datastore:pkg-get-area           vec)    (vector-ref  vec 1))
(define-inline (datastore:pkg-get-version_name   vec)    (vector-ref  vec 2))
(define-inline (datastore:pkg-get-store_type     vec)    (vector-ref  vec 3))
(define-inline (datastore:pkg-get-copied         vec)    (vector-ref  vec 4))
(define-inline (datastore:pkg-get-source_path    vec)    (vector-ref  vec 5))
(define-inline (datastore:pkg-get-iteration      vec)    (vector-ref  vec 6))
(define-inline (datastore:pkg-get-submitter      vec)    (vector-ref  vec 7))
(define-inline (datastore:pkg-get-datetime       vec)    (vector-ref  vec 8))
(define-inline (datastore:pkg-get-storegrp       vec)    (vector-ref  vec 9))
(define-inline (datastore:pkg-get-datavol        vec)    (vector-ref  vec 10))
(define-inline (datastore:pkg-get-quality        vec)    (vector-ref  vec 11))
(define-inline (datastore:pkg-get-disk_id        vec)    (vector-ref  vec 12))
(define-inline (datastore:pkg-get-comment        vec)    (vector-ref  vec 13))
(define-inline (datastore:pkg-get-stored_path    vec)    (vector-ref  vec 14))
(define-inline (datastore:pkg-set-id!            vec val)(vector-set! vec 0 val))
(define-inline (datastore:pkg-set-area!          vec val)(vector-set! vec 1 val))
(define-inline (datastore:pkg-set-version_name!  vec val)(vector-set! vec 2 val))
(define-inline (datastore:pkg-set-store_type!    vec val)(vector-set! vec 3 val))
(define-inline (datastore:pkg-set-copied!        vec val)(vector-set! vec 4 val))
(define-inline (datastore:pkg-set-source_path!   vec val)(vector-set! vec 5 val))
(define-inline (datastore:pkg-set-iteration!     vec val)(vector-set! vec 6 val))
(define-inline (datastore:pkg-set-submitter!     vec val)(vector-set! vec 7 val))
(define-inline (datastore:pkg-set-datetime!      vec val)(vector-set! vec 8 val))
(define-inline (datastore:pkg-set-storegrp!      vec val)(vector-set! vec 9 val))
(define-inline (datastore:pkg-set-datavol!       vec val)(vector-set! vec 10 val))
(define-inline (datastore:pkg-set-quality!       vec val)(vector-set! vec 11 val))
(define-inline (datastore:pkg-set-disk_id!       vec val)(vector-set! vec 12 val))
(define-inline (datastore:pkg-set-comment!       vec val)(vector-set! vec 13 val))
(define-inline (datastore:pkg-set-stored_path!   vec val)(vector-set! vec 14 val))

;;======================================================================
;; DB
;;======================================================================

(define (datashare:initialize-db db)
  (for-each
   (lambda (qry)
     (sqlite3:execute db qry))
   (list 
    "CREATE TABLE pkgs 
         (id           INTEGER PRIMARY KEY,
          area         TEXT,
          version_name TEXT,
          store_type   TEXT DEFAULT 'copy',
          copied       INTEGER DEFAULT 0,
          source_path  TEXT,
          stored_path  TEXT,
          iteration    INTEGER DEFAULT 0,
          submitter    TEXT,
          datetime     TIMESTAMP DEFAULT (strftime('%s','now')),
          storegrp     TEXT,
          datavol      INTEGER,
          quality      TEXT,
          disk_id      INTEGER,
147
148
149
150
151
152
153
















154
155
156
157
158
159
160
	iter-qry area version-name)
       ;; now store the data
       (sqlite3:execute db "INSERT INTO pkgs (area,version_name,iteration,store_type,submitter,source_path,quality,comment) 
                                 VALUES (?,?,?,?,?,?,?,?);"
			area version-name next-iteration (conc store-type) submitter source-path quality comment)))
    (sqlite3:finalize! iter-qry)
    next-iteration))
















  
(define (datashare:get-pkg-record db area version-name iteration)
  #f)

;; Create the sqlite db
(define (datashare:open-db configdat) 
  (let ((path (configf:lookup configdat "database" "location")))







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
	iter-qry area version-name)
       ;; now store the data
       (sqlite3:execute db "INSERT INTO pkgs (area,version_name,iteration,store_type,submitter,source_path,quality,comment) 
                                 VALUES (?,?,?,?,?,?,?,?);"
			area version-name next-iteration (conc store-type) submitter source-path quality comment)))
    (sqlite3:finalize! iter-qry)
    next-iteration))

(define (datastore:get-id db area version-name iteration)
  (let ((res #f))
    (sqlite3:for-each-row
     (lambda (id)
       (set! res id))
     db
     "SELECT id FROM pkgs WHERE area=? AND version_name=? AND iteration=?;"
     area version-name iteration)
    res))

(define (datastore:set-stored-path db id path)
  (sqlite3:execute db "UPDATE pkgs SET stored_path=? WHERE id=?;" path id))

(define (datastore:set-copied db id value)
  (sqlite3:execute db "UPDATE pkgs SET copied=? WHERE id=?;" value id))
  
(define (datashare:get-pkg-record db area version-name iteration)
  #f)

;; Create the sqlite db
(define (datashare:open-db configdat) 
  (let ((path (configf:lookup configdat "database" "location")))
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231


232




233



234





235





236
237
238
239

240
241
242
243
244
245
246

(define (datashare:get-pkgs db area-filter version-filter iter-filter)
  (let ((res '()))
    (sqlite3:for-each-row ;; replace with fold ...
     (lambda (a . b)
       (set! res (cons (list->vector (cons a b)) res)))
     db 
     (conc "SELECT id,area,version_name,store_type,copied,source_path,iteration,submitter,datetime,storegrp,datavol,quality,disk_id,comment "
	   " FROM pkgs WHERE area like ? AND version_name LIKE ? AND iteration " iter-filter ";")
     area-filter version-filter)
    (reverse res)))

;;======================================================================
;; DATA IMPORT/EXPORT
;;======================================================================

(define (datashare:import-data source-path dest-path area version iteration)


  (let ((targ-path (conc dest-path "/" area "/" version "/" iteration)))




    (create-directory targ-path #t)



    (process-run "rsync" (list "-av" source-path targ-path))





    #t)) ;; #t on success






(define (datastore:get-best-storage configdat)
  (let* ((storage     (configf:lookup configdat "setup" "storage"))
	 (store-areas (if storage (string-split storage) '())))

    (datastore:find-most-space store-areas)))

(define (datastore:find-most-space paths)
  (fold (lambda (area res)
	  ;; (print "area=" area " res=" res)
	  (let ((maxspace (car res))
		(currpath (cdr res)))







|








|
>
>
|
>
>
>
>
|
>
>
>
|
>
>
>
>
>
|
>
>
>
>
>


|

>







234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285

(define (datashare:get-pkgs db area-filter version-filter iter-filter)
  (let ((res '()))
    (sqlite3:for-each-row ;; replace with fold ...
     (lambda (a . b)
       (set! res (cons (list->vector (cons a b)) res)))
     db 
     (conc "SELECT id,area,version_name,store_type,copied,source_path,iteration,submitter,datetime,storegrp,datavol,quality,disk_id,comment,stored_path "
	   " FROM pkgs WHERE area like ? AND version_name LIKE ? AND iteration " iter-filter ";")
     area-filter version-filter)
    (reverse res)))

;;======================================================================
;; DATA IMPORT/EXPORT
;;======================================================================

(define (datashare:import-data configdat source-path dest-path area version iteration)
  (let* ((space-avail (car dest-path))
	 (disk-path   (cdr dest-path))
	 (targ-path   (conc disk-path "/" area "/" version "/" iteration))
	 (id          (datastore:get-id db area version iteration))
	 (db          (datashare:open-db configdat)))
    (if (> space-avail 10000) ;; dumb heuristic
	(begin
	  (create-directory targ-path #t)
	  (datastore:set-stored-path db id targ-path)
	  (print "Running command: rsync -av " source-path " " targ-path)
	  (let ((th1 (make-thread (lambda ()
				    (let ((pid (process-run "rsync" (list "-av" source-path targ-path))))
				      (process-wait pid)
				      (datastore:set-copied db id "yes")
				      (sqlite3:finalize! db)))
				   "Data copy")))
	    (thread-start! th1))
	  #t)
	(begin
	  (print "ERROR: Not enough space in storage area " dest-path)
	  (datastore:set-copied db id "no")
	  (sqlite3:finalize! db)
	  #f))))

(define (datastore:get-best-storage configdat)
  (let* ((storage     (configf:lookup configdat "settings" "storage"))
	 (store-areas (if storage (string-split storage) '())))
    (print "Looking for available space in " store-areas)
    (datastore:find-most-space store-areas)))

(define (datastore:find-most-space paths)
  (fold (lambda (area res)
	  ;; (print "area=" area " res=" res)
	  (let ((maxspace (car res))
		(currpath (cdr res)))
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
			       ;;  		'copy
			       ;;  		'link))
			       (db          (datashare:open-db configdat))
			       (iteration   (datashare:register-data db area-name version publish-type submitter quality spath comment))
			       (dest-store  (datastore:get-best-storage configdat)))
			  (if iteration
			      (if (eq? 'copy publish-type)
				  (datashare:import-data spath dest-store area-name version iteration))
			      (print "ERROR: Failed to get an iteration number"))
			  (sqlite3:finalize! db))))
	 (copy        (iup:button "Copy and Publish"
				  #:expand "HORIZONTAL"
				  #:action (lambda (obj)
					     (publish 'copy))))
	 (link        (iup:button "Link and Publish"







|







349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
			       ;;  		'copy
			       ;;  		'link))
			       (db          (datashare:open-db configdat))
			       (iteration   (datashare:register-data db area-name version publish-type submitter quality spath comment))
			       (dest-store  (datastore:get-best-storage configdat)))
			  (if iteration
			      (if (eq? 'copy publish-type)
				  (datashare:import-data configdat spath dest-store area-name version iteration))
			      (print "ERROR: Failed to get an iteration number"))
			  (sqlite3:finalize! db))))
	 (copy        (iup:button "Copy and Publish"
				  #:expand "HORIZONTAL"
				  #:action (lambda (obj)
					     (publish 'copy))))
	 (link        (iup:button "Link and Publish"
347
348
349
350
351
352
353








354
355
356
357
358

359
360
361

362


363

364
365
366
367
368



369
370
371
372
373
374
375
376
377
378
379
380
381

382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411




412
413
414
415
416
417
418
419
420
421
422
423
424











425











426
427



428
429
430
431
432
433
434
435
436
437
438




439
440
441
442
443
444
445
     ;; 	       (iup:label "Iteration:")   iteration)
     (iup:hbox (iup:label "Comment:"     #:size label-size)   comment-tb)
     (iup:hbox (iup:label "Source base path:" #:size label-size)   source-tb browse-btn)
     (iup:hbox copy link))))

(define (datastore:lst->path pathlst)
  (conc "/" (string-intersperse (map conc pathlst) "/")))









(define (datashare:get-view configdat)
  (iup:vbox
   (iup:hbox
    (let* ((label-size     "60x")

	   (area-filter    "%")
	   (version-filter "%")
	   (iter-filter    ">= 0")

	   (dat            (make-hash-table)) ;; reverse lookup


	   (apply          (iup:button "Apply"))

	   (submitter      (iup:label "" #:expand "HORIZONTAL"))
	   (date-submitted (iup:label "" #:expand "HORIZONTAL"))
	   (comment        (iup:label "" #:expand "HORIZONTAL"))
	   (copy-link      (iup:label "" #:expand "HORIZONTAL"))
	   (quality        (iup:label "" #:expand "HORIZONTAL"))



	   ;; (source-data    (iup:label "" #:expand "HORIZONTAL"))
	   (tb             (iup:treebox
			    #:value 0
			    #:name "Packages"
			    #:expand "YES"
			    #:addexpanded "NO"
			    #:selection-cb
			    (lambda (obj id state)
			      ;; (print "obj: " obj ", id: " id ", state: " state)
			      (let* ((path   (datastore:lst->path (cdr (tree:node->path obj id))))
				     (record (hash-table-ref/default dat path #f)))
				(if record
				    (begin

				      (iup:attribute-set! submitter      "TITLE" (datastore:pkg-get-submitter record))
				      (iup:attribute-set! date-submitted "TITLE" (time->string (seconds->local-time (datastore:pkg-get-datetime record))))
				      (iup:attribute-set! comment        "TITLE" (datastore:pkg-get-comment record))
				      (iup:attribute-set! quality        "TITLE" (datastore:pkg-get-quality record))
				      (iup:attribute-set! copy-link      "TITLE" (datastore:pkg-get-store_type record))
				      ))
				(print  "id=" id " path=" path " record=" record);; (tree:node->path obj id) " run-id: " run-id)
				))))
	   (tb2             (iup:treebox
			    #:value 0
			    #:name "Packages"
			    #:expand "YES"
			    #:addexpanded "NO"
			    #:selection-cb
			    (lambda (obj id state)
			      ;; (print "obj: " obj ", id: " id ", state: " state)
			      (let* ((path   (datastore:lst->path (cdr (tree:node->path obj id))))
				     (record (hash-table-ref/default dat path #f)))
				(if record
				    (begin
				      (iup:attribute-set! submitter      "TITLE" (datastore:pkg-get-submitter record))
				      (iup:attribute-set! date-submitted "TITLE" (time->string (seconds->local-time (datastore:pkg-get-datetime record))))
				      (iup:attribute-set! comment        "TITLE" (datastore:pkg-get-comment record))
				      (iup:attribute-set! quality        "TITLE" (datastore:pkg-get-quality record))
				      (iup:attribute-set! copy-link      "TITLE" (datastore:pkg-get-store_type record))
				      ))
				(print  "id=" id " path=" path " record=" record);; (tree:node->path obj id) " run-id: " run-id)
				))))
	   (refresh        (lambda (obj)
			     (let ((db (datashare:open-db configdat)))




			       (for-each
				(lambda (pkgitem)
				  (let* ((pkg-path   (list (datastore:pkg-get-area  pkgitem)
							   (datastore:pkg-get-version_name pkgitem)
							   (datastore:pkg-get-iteration pkgitem)))
					 (pkg-id     (datastore:pkg-get-id          pkgitem))
					 (path       (datastore:lst->path pkg-path)))
				    ;; (print "tree:add-node tb=" tb ", pkg-path=" pkg-path ", pkg-id=" pkg-id)
				    (if (not (hash-table-ref/default dat path #f))
					(tree:add-node tb "Packages" pkg-path userdata: (conc "pkg-id: " pkg-id)))
				    ;; (print "path=" path " pkgitem=" pkgitem)
				    (hash-table-set! dat path pkgitem)))
				(datashare:get-pkgs db area-filter version-filter iter-filter))











			       (sqlite3:finalize! db)))))











      (iup:vbox 
       (iup:hbox tb tb2)



       (iup:hbox (iup:button "Refresh" #:action refresh) apply)
       (iup:hbox (iup:label "Submitter: ") ;;  #:size label-size)
		 submitter 
		 (iup:label "Submitted on: ") ;;  #:size label-size)
		 date-submitted)
       (iup:hbox (iup:label "Data stored: ")
		 copy-link
		 (iup:label "Quality: ")
		 quality)
       (iup:hbox (iup:label "Comment: ")
		 comment)




       )))))

(define (datashare:manage-view configdat)
  (iup:vbox
   (iup:hbox 
    (iup:button "Pushme"
		#:expand "YES"







>
>
>
>
>
>
>
>





>



>
|
>
>
|
>





>
>
>










|


>










|






|
<
<
|
<
<
<
<
<
<


|
>
>
>
>








|


|

>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>


>
>
>
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>







386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455


456






457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
     ;; 	       (iup:label "Iteration:")   iteration)
     (iup:hbox (iup:label "Comment:"     #:size label-size)   comment-tb)
     (iup:hbox (iup:label "Source base path:" #:size label-size)   source-tb browse-btn)
     (iup:hbox copy link))))

(define (datastore:lst->path pathlst)
  (conc "/" (string-intersperse (map conc pathlst) "/")))

(define (datastore:path->lst path)
  (string-split path "/"))

(define (datastore:pathdat-apply-heuristics configdat path)
  (cond
   ((file-exists? path) "found")
   (else "not installed")))

(define (datashare:get-view configdat)
  (iup:vbox
   (iup:hbox
    (let* ((label-size     "60x")
	   ;; filter elements
	   (area-filter    "%")
	   (version-filter "%")
	   (iter-filter    ">= 0")
	   ;; reverse lookup from path to data for src and installed
	   (srcdat         (make-hash-table)) ;; reverse lookup
	   (installed-dat  (make-hash-table))
	   ;; config values
	   (basepath       (configf:lookup configdat "settings" "basepath"))
	   ;; gui elements
	   (submitter      (iup:label "" #:expand "HORIZONTAL"))
	   (date-submitted (iup:label "" #:expand "HORIZONTAL"))
	   (comment        (iup:label "" #:expand "HORIZONTAL"))
	   (copy-link      (iup:label "" #:expand "HORIZONTAL"))
	   (quality        (iup:label "" #:expand "HORIZONTAL"))
	   (installed-status (iup:label "" #:expand "HORIZONTAL"))
	   ;; misc 
	   (curr-record    #f)
	   ;; (source-data    (iup:label "" #:expand "HORIZONTAL"))
	   (tb             (iup:treebox
			    #:value 0
			    #:name "Packages"
			    #:expand "YES"
			    #:addexpanded "NO"
			    #:selection-cb
			    (lambda (obj id state)
			      ;; (print "obj: " obj ", id: " id ", state: " state)
			      (let* ((path   (datastore:lst->path (cdr (tree:node->path obj id))))
				     (record (hash-table-ref/default srcdat path #f)))
				(if record
				    (begin
				      (set! curr-record record)
				      (iup:attribute-set! submitter      "TITLE" (datastore:pkg-get-submitter record))
				      (iup:attribute-set! date-submitted "TITLE" (time->string (seconds->local-time (datastore:pkg-get-datetime record))))
				      (iup:attribute-set! comment        "TITLE" (datastore:pkg-get-comment record))
				      (iup:attribute-set! quality        "TITLE" (datastore:pkg-get-quality record))
				      (iup:attribute-set! copy-link      "TITLE" (datastore:pkg-get-store_type record))
				      ))
				(print  "id=" id " path=" path " record=" record);; (tree:node->path obj id) " run-id: " run-id)
				))))
	   (tb2             (iup:treebox
			    #:value 0
			    #:name "Installed"
			    #:expand "YES"
			    #:addexpanded "NO"
			    #:selection-cb
			    (lambda (obj id state)
			      ;; (print "obj: " obj ", id: " id ", state: " state)
			      (let* ((path   (datastore:lst->path (cdr (tree:node->path obj id))))
				     (status (hash-table-ref/default installed-dat path #f)))


				(iup:attribute-set! installed-status "TITLE" (if status status ""))






				))))
	   (refresh        (lambda (obj)
			     (let* ((db    (datashare:open-db configdat))
				    (areas (or (configf:get-section configdat "areas") '())))
			       ;;
			       ;; first update the Sources
			       ;;
			       (for-each
				(lambda (pkgitem)
				  (let* ((pkg-path   (list (datastore:pkg-get-area  pkgitem)
							   (datastore:pkg-get-version_name pkgitem)
							   (datastore:pkg-get-iteration pkgitem)))
					 (pkg-id     (datastore:pkg-get-id          pkgitem))
					 (path       (datastore:lst->path pkg-path)))
				    ;; (print "tree:add-node tb=" tb ", pkg-path=" pkg-path ", pkg-id=" pkg-id)
				    (if (not (hash-table-ref/default srcdat path #f))
					(tree:add-node tb "Packages" pkg-path userdata: (conc "pkg-id: " pkg-id)))
				    ;; (print "path=" path " pkgitem=" pkgitem)
				    (hash-table-set! srcdat path pkgitem)))
				(datashare:get-pkgs db area-filter version-filter iter-filter))
			       ;;
			       ;; then update the installed
			       ;;
			       (for-each
				(lambda (area)
				  (let* ((path     (conc "/" (cadr area)))
					 (fullpath (conc basepath path)))
				    (if (not (hash-table-ref/default installed-dat path #f))
					(tree:add-node tb2 "Installed" (datastore:path->lst path)))
				    (hash-table-set! installed-dat path (datastore:pathdat-apply-heuristics configdat path))))
				areas)
			       (sqlite3:finalize! db))))
	   (apply          (iup:button "Apply"
				       #:action
				       (lambda (obj)
					 (if curr-record
					     (let* ((stored-path (datastore:pkg-get-stored_path curr-record))
						    (source-type (datastore:pkg-get-store_type curr-record))
						    (source-path (case source-type ;;  (equal? source-type "link"))
								   ((link)(datastore:pkg-get-source-path curr-record))
								   ((copy)stored-path)
								   (else #f))))
					       (print "Creating link from " stored-path " to " basepath)))))))
      (iup:vbox 
       (iup:hbox tb tb2)
       (iup:frame 
	#:title "Source Info"
	(iup:vbox
	 (iup:hbox (iup:button "Refresh" #:action refresh) apply)
	 (iup:hbox (iup:label "Submitter: ") ;;  #:size label-size)
		   submitter 
		   (iup:label "Submitted on: ") ;;  #:size label-size)
		   date-submitted)
	 (iup:hbox (iup:label "Data stored: ")
		   copy-link
		   (iup:label "Quality: ")
		   quality)
	 (iup:hbox (iup:label "Comment: ")
		   comment)))
       (iup:frame
	#:title "Installed Info"
	(iup:vbox
	 (iup:hbox (iup:label "Installed status/path: ") installed-status)))
       )))))

(define (datashare:manage-view configdat)
  (iup:vbox
   (iup:hbox 
    (iup:button "Pushme"
		#:expand "YES"