Overview
Comment: | Completed sretrieve |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | v1.60 |
Files: | files | file ages | folders |
SHA1: |
07c1d52486339c5565b85d22c0fb0398 |
User & Date: | matt on 2015-12-13 23:06:05 |
Other Links: | branch diff | manifest | tags |
Context
2015-12-17
| ||
14:31 | Needed to follow links by default in sretrieve check-in: 15bf67d66a user: mrwellan tags: v1.60 | |
2015-12-13
| ||
23:06 | Completed sretrieve check-in: 07c1d52486 user: matt tags: v1.60 | |
2015-12-12
| ||
22:40 | Added function for reading packages check-in: ed27042583 user: matt tags: v1.60 | |
Changes
Modified datashare-testing/.sretrieve.config from [91a460477d] to [e657ec9c50].
1 2 3 | [settings] allowed-users matt mrwellan pjhatwal allowed-chars [0-9a-zA-Z\-\.]+ | > > | > > > > > | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | [settings] base-dir /tmp/matt/datashare/disk1 allowed-users matt mrwellan pjhatwal allowed-chars [0-9a-zA-Z\-\.]+ default-area megatest # NOTE: packages-metadir defaults to exe dir if not specified here # packages-metadir /tmp/#{getenv USER}/packages # conversion-script has semantics as cp, takes file1 and outputs file2 # cp file1 file2 conversion-script cp upstream-file packages.config [database] location #{scheme (create-directory "/tmp/#{getenv USER}" #t)} |
Added datashare-testing/NOTES version [1e24a4d112].
> > > | 1 2 3 | To test sretrieve first publish megatest as v1.60 at least twice to get iterations 0 and 1 |
Added datashare-testing/megatest.config version [85f1bdc170].
> > > > | 1 2 3 4 | [v1.60] status released iteration 1 |
Modified datashare-testing/packages.config from [2bebde2921] to [85f1bdc170].
|
| | | | | | 1 2 3 4 | [v1.60] status released iteration 1 |
Modified sretrieve.scm from [7011d614d7] to [bdaa86239f].
︙ | ︙ | |||
15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ;; (use sxml-modifications) ;; (use regex) ;; (use srfi-69) ;; (use regex-case) ;; (use posix) ;; (use json) ;; (use csv) (use srfi-18) (use format) (require-library ini-file) (import (prefix ini-file ini:)) (use sql-de-lite srfi-1 posix regex regex-case srfi-69) | > | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | ;; (use sxml-modifications) ;; (use regex) ;; (use srfi-69) ;; (use regex-case) ;; (use posix) ;; (use json) ;; (use csv) (use directory-utils) (use srfi-18) (use format) (require-library ini-file) (import (prefix ini-file ini:)) (use sql-de-lite srfi-1 posix regex regex-case srfi-69) |
︙ | ︙ | |||
87 88 89 90 91 92 93 | bundle TEXT NOT NULL, release TEXT NOT NULL, status TEXT NOT NULL, event_date TEXT NOT NULL);" ))) (define (sretrieve:register-action db action submitter source-path comment) | > | | | | | | | > > | > | | | < > | | < < | < < < | < < < < < | < | < < < < < | | | | | | | | | 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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | bundle TEXT NOT NULL, release TEXT NOT NULL, status TEXT NOT NULL, event_date TEXT NOT NULL);" ))) (define (sretrieve:register-action db action submitter source-path comment) (print "(sretrieve:register-action db " db " action " action " submitter " submitter " source-path " source-path " comment " comment) (exec (sql db "INSERT INTO actions (action,retriever,srcpath,comment) VALUES(?,?,?,?)") action submitter source-path (or comment ""))) ;; (call-with-database ;; (lambda (db) ;; (set-busy-handler! db (busy-timeout 10000)) ; 10 second timeout ;; ...)) ;; Create the sqlite db (define (sretrieve:db-do configdat proc) (let ((path (configf:lookup configdat "database" "location"))) (if (not path) (begin (debug:print 0 "[database]\nlocation /some/path\n\n Is missing from the config file!") (exit 1))) (if (and path (directory? path) (file-read-access? path)) (let* ((dbpath (conc path "/sretrieve.db")) (writeable (file-write-access? dbpath)) (dbexists (file-exists? dbpath))) (handle-exceptions exn (begin (debug:print 2 "ERROR: problem accessing db " dbpath ((condition-property-accessor 'exn 'message) exn)) (exit 1)) (call-with-database dbpath (lambda (db) ;; (debug:print 0 "calling proc " proc " on db " db) (set-busy-handler! db (busy-timeout 10000)) ;; 10 sec timeout (if (not dbexists)(sretrieve:initialize-db db)) (proc db))))) (debug:print 0 "ERROR: invalid path for storing database: " path)))) ;; copy in file to dest, validation is done BEFORE calling this ;; (define (sretrieve:get configdat reldat retriever area version iter comment) (let* ((iteration (or iter (configf:lookup reldat version "iteration"))) (base-dir (configf:lookup configdat "settings" "base-dir")) (datadir (conc base-dir "/" area "/" version "/" iteration))) (if (or (not base-dir) (not (file-exists? base-dir))) (begin (debug:print 0 "ERROR: Bad configuration! base-dir " base-dir " not found") (exit 1))) (if (not (file-exists? datadir)) (begin (debug:print 0 "ERROR: Bad version (" version ") or iteration (" iteration "), no data found at " datadir "." ) (exit 1))) (sretrieve:db-do configdat (lambda (db) (sretrieve:register-action db "get" retriever datadir comment))) (change-directory datadir) (process-execute "tar" (append (list "cfv" "-")(filter (lambda (x) (not (member x '("." "..")))) (glob "*" ".*")))))) (define (sretrieve:validate target-dir targ-mk) (let* ((normal-path (normalize-pathname targ-mk)) (targ-path (conc target-dir "/" normal-path))) (if (string-contains normal-path "..") (begin (debug:print 0 "ERROR: Path " targ-mk " resolved outside target area " target-dir ) (exit 1))) (if (not (string-contains targ-path target-dir)) (begin (debug:print 0 "ERROR: You cannot update data outside " target-dir ".") (exit 1))) (debug:print 0 "Path " targ-mk " is valid.") )) ;; make directory in dest ;; (define (sretrieve:mkdir configdat submitter target-dir targ-mk comment) (let ((targ-path (conc target-dir "/" targ-mk))) (if (file-exists? targ-path) (begin (debug:print 0 "ERROR: target Directory " targ-path " already exist!!") (exit 1))) (sretrieve:db-do configdat (lambda (db) (sretrieve:register-action db "mkdir" submitter targ-mk comment))) (let* ((th1 (make-thread (lambda () (create-directory targ-path #t) (debug:print 0 " ... dir " targ-path " created")) "mkdir thread")) (th2 (make-thread (lambda () (let loop () (thread-sleep! 15) (display ".") (flush-output) (loop))) "action is happening thread"))) (thread-start! th1) (thread-start! th2) (thread-join! th1)) (cons #t "Successfully saved data"))) ;; create a symlink in dest ;; (define (sretrieve:ln configdat submitter target-dir targ-link link-name comment) (let ((targ-path (conc target-dir "/" link-name))) (if (file-exists? targ-path) (begin (debug:print 0 "ERROR: target file " targ-path " already exist!!") (exit 1))) (if (not (file-exists? targ-link )) (begin (debug:print 0 "ERROR: target file " targ-link " does not exist!!") (exit 1))) (sretrieve:db-do configdat (lambda (db) (sretrieve:register-action db "ln" submitter link-name comment))) (let* ((th1 (make-thread (lambda () (create-symbolic-link targ-link targ-path ) (debug:print 0 " ... link " targ-path " created")) "symlink thread")) (th2 (make-thread (lambda () (let loop () (thread-sleep! 15) (display ".") (flush-output) |
︙ | ︙ | |||
254 255 256 257 258 259 260 | ;; remove copy of file in dest ;; (define (sretrieve:rm configdat submitter target-dir targ-file comment) (let ((targ-path (conc target-dir "/" targ-file))) (if (not (file-exists? targ-path)) (begin | | | | 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | ;; remove copy of file in dest ;; (define (sretrieve:rm configdat submitter target-dir targ-file comment) (let ((targ-path (conc target-dir "/" targ-file))) (if (not (file-exists? targ-path)) (begin (debug:print 0 "ERROR: target file " targ-path " not found, nothing to remove.") (exit 1))) (sretrieve:db-do configdat (lambda (db) (sretrieve:register-action db "rm" submitter targ-file comment))) (let* ((th1 (make-thread (lambda () (delete-file targ-path) (debug:print 0 " ... file " targ-path " removed")) "rm thread")) (th2 (make-thread (lambda () (let loop () (thread-sleep! 15) (display ".") (flush-output) |
︙ | ︙ | |||
307 308 309 310 311 312 313 | ;;====================================================================== (define (sretrieve:do-as-calling-user proc) (let ((eid (current-effective-user-id)) (cid (current-user-id))) (if (not (eq? eid cid)) ;; running suid (set! (current-effective-user-id) cid)) | | > > > > > > > | | > | > > > > | | | | | | | > > | | | > | | | | | | | | < | < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < | < < < < | | | < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < | > > > | 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 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 | ;;====================================================================== (define (sretrieve:do-as-calling-user proc) (let ((eid (current-effective-user-id)) (cid (current-user-id))) (if (not (eq? eid cid)) ;; running suid (set! (current-effective-user-id) cid)) ;; (debug:print 0 "running as " (current-effective-user-id)) (proc) (if (not (eq? eid cid)) (set! (current-effective-user-id) eid)))) (define (sretrieve:find name paths) (if (null? paths) #f (let loop ((hed (car paths)) (tal (cdr paths))) (if (file-exists? (conc hed "/" name)) hed (if (null? tal) #f (loop (car tal)(cdr tal))))))) (define (sretrieve:stderr-print . args) (with-output-to-port (current-error-port) (lambda () (apply print args)))) ;;====================================================================== ;; MAIN ;;====================================================================== (define (sretrieve:load-config exe-dir exe-name) (let* ((fname (conc exe-dir "/." exe-name ".config"))) (ini:property-separator-patt " * *") (ini:property-separator #\space) (if (file-exists? fname) ;; (ini:read-ini fname) (read-config fname #f #t) (make-hash-table)))) ;; package-type is "megatest", "builds", "kits" etc. ;; (define (sretrieve:load-packages configdat exe-dir package-type) (push-directory exe-dir) (let* ((packages-metadir (or (configf:lookup configdat "settings" "packages-metadir") ".")) ;; exe-dir)) (conversion-script (configf:lookup configdat "settings" "conversion-script")) (upstream-file (configf:lookup configdat "settings" "upstream-file")) (package-config (conc packages-metadir "/" package-type ".config"))) ;; this section here does a timestamp based rebuild of the ;; <packages-metadir>/<package-type>.config file using ;; <upstream-file> as an input (if (file-exists? upstream-file) (if (or (not (file-exists? package-config)) ;; if not created call the updater, otherwise call only if upstream newer (> (file-modification-time upstream-file)(file-modification-time package-config))) (handle-exceptions exn (debug:print 0 "ERROR: failed to run script " conversion-script " with params " upstream-file " " package-config) (let ((pid (process-run conversion-script (list upstream-file package-config)))) (process-wait pid))) (debug:print 0 "Skipping update of " package-config " from " upstream-file)) (debug:print 0 "Skipping update of " package-config " as " upstream-file " not found")) (ini:property-separator-patt " * *") (ini:property-separator #\space) (let ((res (if (file-exists? package-config) (begin (debug:print 0 "Reading package config " package-config) (read-config package-config #f #t)) (make-hash-table)))) (pop-directory) res))) (define (sretrieve:process-action configdat action . args) (let* ((base-dir (configf:lookup configdat "settings" "base-dir")) (user (current-user-name)) (allowed-users (string-split (or (configf:lookup configdat "settings" "allowed-users") ""))) (default-area (configf:lookup configdat "settings" "default-area"))) ;; otherwise known as the package (if (not base-dir) (begin (debug:print 0 "[settings]\nbase-dir /some/path\n\n Is MISSING from the config file!") (exit))) (if (null? allowed-users) (begin (debug:print 0 "[setings]\nallowed-users user1 user2 ...\n\n Is MISSING from the config file!") (exit))) (if (not (member user allowed-users)) (begin (debug:print 0 "User \"" (current-user-name) "\" does not have access. Exiting") (exit 1))) (case (string->symbol action) ((get) (if (< (length args) 1) (begin (debug:print 0 "ERROR: Missing arguments; " (string-intersperse args ", ")) (exit 1))) (let* ((remargs (args:get-args args '("-m" "-i" "-package") '() args:arg-hash 0)) (version (car args)) (msg (or (args:get-arg "-m") "")) (iteration (args:get-arg "-i")) (package-type (or (args:get-arg "-package") default-area)) (exe-dir (configf:lookup configdat "exe-info" "exe-dir")) (relconfig (sretrieve:load-packages configdat exe-dir package-type))) (debug:print 0 "retrieving " version " of " package-type " as tar data on stdout") (sretrieve:get configdat relconfig user package-type version iteration msg))) (else (debug:print 0 "Unrecognised command " action))))) ;; ease debugging by loading ~/.dashboardrc - REMOVE FROM PRODUCTION! ;; (let ((debugcontrolf (conc (get-environment-variable "HOME") "/.sretrieverc"))) ;; (if (file-exists? debugcontrolf) ;; (load debugcontrolf))) (define (main) (let* ((args (argv)) (prog (car args)) (rema (cdr args)) (exe-name (pathname-file (car (argv)))) (exe-dir (or (pathname-directory prog) (sretrieve:find exe-name (string-split (get-environment-variable "PATH") ":")))) (configdat (sretrieve:load-config exe-dir exe-name))) ;; preserve the exe data in the config file (hash-table-set! configdat "exe-info" (list (list "exe-name" exe-name) (list "exe-dir" exe-dir))) (cond ;; one-word commands ((eq? (length rema) 1) (case (string->symbol (car rema)) ((help -h -help --h --help) (print sretrieve:help)) ((list-vars) ;; print out the ini file |
︙ | ︙ | |||
524 525 526 527 528 529 530 | (sql db "SELECT * FROM actions"))))) (else (print "ERROR: Unrecognised command. Try \"sretrieve help\"")))) ;; multi-word commands ((null? rema)(print sretrieve:help)) ((>= (length rema) 2) (apply sretrieve:process-action configdat (car rema)(cdr rema))) | | | 441 442 443 444 445 446 447 448 449 450 | (sql db "SELECT * FROM actions"))))) (else (print "ERROR: Unrecognised command. Try \"sretrieve help\"")))) ;; multi-word commands ((null? rema)(print sretrieve:help)) ((>= (length rema) 2) (apply sretrieve:process-action configdat (car rema)(cdr rema))) (else (debug:print 0 "ERROR: Unrecognised command. Try \"sretrieve help\""))))) (main) |