Changeset 4902
- Timestamp:
- 27 Jan 2010, 12:11:32 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/trunk/src/waeup/utils/batching.txt
r4895 r4902 226 226 227 227 >>> processor = CaveProcessor() 228 >>> processor.doImport('newcomers.csv',228 >>> result = processor.doImport('newcomers.csv', 229 229 ... ['name', 'dinoports', 'owner', 'taxpayer'], 230 230 ... mode='create', user='Bob', logger=logger) 231 >>> result 231 232 (4, 0, '/.../newcomers.finished.csv', None) 232 233 … … 263 264 provided a logger during the call: 264 265 265 >>> #print open('newcomers.csv.create.msg').read()266 266 >>> print open('stoneville.log').read() 267 267 -------------------- … … 274 274 -------------------- 275 275 276 We cleanup the temporay dir created by doImport(): 277 278 >>> import shutil 279 >>> import os 280 >>> shutil.rmtree(os.path.dirname(result[2])) 281 276 282 As we can see, the processing was successful. Otherwise, all problems 277 283 could be read here as we can see, if we do the same operation again: 278 284 279 >>> processor.doImport('newcomers.csv',285 >>> result = processor.doImport('newcomers.csv', 280 286 ... ['name', 'dinoports', 'owner', 'taxpayer'], 281 287 ... mode='create', user='Bob', logger=logger) 288 >>> result 282 289 (4, 4, '/.../newcomers.finished.csv', '/.../newcomers.pending.csv') 283 290 … … 286 293 The log file will tell us this in more detail: 287 294 288 >>> #print open('newcomers.csv.create.msg').read()289 295 >>> print open('stoneville.log').read() 290 296 -------------------- … … 303 309 process and an additional column with error messages: 304 310 305 >>> print open( 'newcomers.pending.csv').read()311 >>> print open(result[3]).read() 306 312 owner,name,taxpayer,dinoports,--ERRORS-- 307 313 Barney,Barneys Home,1,2,This object already exists. Skipping. … … 317 323 ``False`` (which is accepted by the converters). 318 324 325 Clean up: 326 327 >>> shutil.rmtree(os.path.dirname(result[2])) 319 328 320 329 Updating entries … … 324 333 mode: 325 334 326 >>> processor.doImport('newcomers.csv', ['name', 'dinoports', 'owner'], 335 >>> result = processor.doImport('newcomers.csv', ['name', 336 ... 'dinoports', 'owner'], 327 337 ... mode='update', user='Bob') 338 >>> result 328 339 (4, 0, '...', None) 329 340 … … 339 350 1 340 351 352 Clean up: 353 354 >>> shutil.rmtree(os.path.dirname(result[2])) 355 356 341 357 We start the processor: 342 358 343 >>> processor.doImport('newcomers.csv', ['name', 'dinoports', 'owner'], 344 ... mode='update', user='Bob') 359 >>> result = processor.doImport('newcomers.csv', ['name', 360 ... 'dinoports', 'owner'], mode='update', user='Bob') 361 >>> result 345 362 (1, 0, '...', None) 346 363 … … 351 368 Wilma's number of dinoports raised. 352 369 370 Clean up: 371 372 >>> shutil.rmtree(os.path.dirname(result[2])) 373 374 353 375 If we try to update an unexisting entry, an error occurs: 354 376 … … 358 380 ... """) 359 381 360 >>> processor.doImport('newcomers.csv', ['name', 'dinoports', 'owner'], 382 >>> result = processor.doImport('newcomers.csv', ['name', 383 ... 'dinoports', 'owner'], 361 384 ... mode='update', user='Bob') 385 >>> result 362 386 (1, 1, '/.../newcomers.finished.csv', '/.../newcomers.pending.csv') 387 388 Clean up: 389 390 >>> shutil.rmtree(os.path.dirname(result[2])) 391 363 392 364 393 Also invalid values will be spotted: … … 369 398 ... """) 370 399 371 >>> processor.doImport('newcomers.csv', ['name', 'dinoports', 'owner'], 400 >>> result = processor.doImport('newcomers.csv', ['name', 401 ... 'dinoports', 'owner'], 372 402 ... mode='update', user='Bob') 403 >>> result 373 404 (1, 1, '...', '...') 405 406 Clean up: 407 408 >>> shutil.rmtree(os.path.dirname(result[2])) 409 374 410 375 411 We can also update only some cols, leaving some out. We skip the … … 381 417 ... """) 382 418 383 >>> processor.doImport('newcomers.csv', ['name', 'owner'], 384 ... mode='update', user='Bob') 419 >>> result = processor.doImport('newcomers.csv', ['name', 'owner'], 420 ... mode='update', user='Bob') 421 >>> result 385 422 (1, 0, '...', None) 386 423 387 424 >>> wilma.owner 388 425 u'Barney' 426 427 Clean up: 428 429 >>> shutil.rmtree(os.path.dirname(result[2])) 430 389 431 390 432 We can however, not leave out the 'location field' ('name' in our … … 412 454 ... """) 413 455 414 >>> processor.doImport('newcomers.csv', ['name', 'dinoports', 'owner'], 456 >>> result = processor.doImport('newcomers.csv', ['name', 457 ... 'dinoports', 'owner'], 415 458 ... mode='update', user='Bob') 459 >>> result 416 460 (1, 0, '...', None) 417 461 … … 419 463 True 420 464 465 Clean up: 466 467 >>> shutil.rmtree(os.path.dirname(result[2])) 468 421 469 Generally, empty strings are considered as ``None``: 422 470 … … 426 474 ... """) 427 475 428 >>> processor.doImport('newcomers.csv', ['name', 'dinoports', 'owner'], 476 >>> result = processor.doImport('newcomers.csv', ['name', 477 ... 'dinoports', 'owner'], 429 478 ... mode='update', user='Bob') 479 >>> result 430 480 (1, 0, '...', None) 431 481 … … 433 483 True 434 484 485 Clean up: 486 487 >>> shutil.rmtree(os.path.dirname(result[2])) 488 489 435 490 Removing entries 436 491 ---------------- … … 444 499 ... """) 445 500 446 >>> processor.doImport('newcomers.csv', ['name', 'dinoports', 'owner'], 501 >>> result = processor.doImport('newcomers.csv', ['name', 502 ... 'dinoports', 'owner'], 447 503 ... mode='remove', user='Bob') 504 >>> result 448 505 (1, 0, '...', None) 449 506 … … 453 510 Oops! Wilma is gone. 454 511 512 Clean up: 513 514 >>> shutil.rmtree(os.path.dirname(result[2])) 515 455 516 456 517 Clean up: … … 458 519 >>> import os 459 520 >>> os.unlink('newcomers.csv') 460 >>> os.unlink('newcomers.finished.csv')461 521 >>> os.unlink('stoneville.log')
Note: See TracChangeset for help on using the changeset viewer.