summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-05-15 20:22:32 +0200
committerhut <hut@lavabit.com>2010-05-15 20:22:32 +0200
commit35b72f662d50dab160dbb32705f32d34762765a1 (patch)
tree292756a3121d7f2d8ad228ebeef6a700d451e63c /ranger
parentbf9c33fca7f33818670aa3b55b5873c6da99ec31 (diff)
downloadranger-35b72f662d50dab160dbb32705f32d34762765a1.tar.gz
core.loader: finished CommandLoader
Diffstat (limited to 'ranger')
-rw-r--r--ranger/core/loader.py34
-rw-r--r--ranger/fsobject/directory.py3
2 files changed, 30 insertions, 7 deletions
diff --git a/ranger/core/loader.py b/ranger/core/loader.py
index 56395ae8..ad6864e2 100644
--- a/ranger/core/loader.py
+++ b/ranger/core/loader.py
@@ -31,11 +31,11 @@ def status_generator():
 		yield '|'
 
 
-class LoadableObject(object):
+class Loadable(object):
+	paused = False
 	def __init__(self, gen, descr):
 		self.load_generator = gen
 		self.description = descr
-		self.paused = False
 
 	def get_description(self):
 		return self.description
@@ -44,15 +44,19 @@ class LoadableObject(object):
 		self.paused = True
 
 	def unpause(self):
-		self.paused = False
+		try:
+			del self.paused
+		except:
+			pass
 
 	def destroy(self):
 		pass
 
 
-class CommandLoader(LoadableObject):
+class CommandLoader(Loadable, FileManagerAware):
+	finished = False
 	def __init__(self, args, descr, begin_hook=None, end_hook=None):
-		LoadableObject.__init__(self, self.generate(), descr)
+		Loadable.__init__(self, self.generate(), descr)
 		self.args = args
 		self.begin_hook = begin_hook
 		self.end_hook = end_hook
@@ -67,12 +71,24 @@ class CommandLoader(LoadableObject):
 			rd, _, __ = select.select(
 					[process.stderr], [], [], 0.05)
 			if rd:
-				self.notify(process.stderr.readline(), bad=True)
+				error = process.stderr.readline().decode('utf-8')
+				self.fm.notify(error, bad=True)
 			sleep(0.02)
 			yield
+		self.finished = True
 		if self.end_hook:
 			self.end_hook(process)
 
+	def pause(self):
+		if not self.finished and not self.paused:
+			self.process.send_signal(20)
+		Loadable.pause(self)
+
+	def unpause(self):
+		if not self.finished and self.paused:
+			self.process.send_signal(18)
+		Loadable.unpause(self)
+
 	def destroy(self):
 		if self.process:
 			self.process.kill()
@@ -113,6 +129,8 @@ class Loader(FileManagerAware):
 
 		if to == 0:
 			self.queue.appendleft(item)
+			if _from != 0:
+				self.queue[1].pause()
 		elif to == -1:
 			self.queue.append(item)
 		else:
@@ -132,6 +150,7 @@ class Loader(FileManagerAware):
 				item = self.queue[index]
 			if hasattr(item, 'unload'):
 				item.unload()
+			item.destroy()
 			del self.queue[index]
 
 	def work(self):
@@ -152,7 +171,10 @@ class Loader(FileManagerAware):
 
 		self.rotate()
 		if item != self.old_item:
+			if self.old_item:
+				self.old_item.pause()
 			self.old_item = item
+		item.unpause()
 
 		end_time = time() + self.seconds_of_work_time
 
diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py
index 930ecb70..bab650c6 100644
--- a/ranger/fsobject/directory.py
+++ b/ranger/fsobject/directory.py
@@ -20,6 +20,7 @@ from os.path import join, isdir, basename
 from collections import deque
 from time import time
 
+from ranger.core.loader import Loadable
 from ranger.ext.mount_path import mount_path
 from ranger.fsobject import BAD_INFO, File, FileSystemObject
 from ranger.shared import SettingsAware
@@ -50,7 +51,7 @@ def accept_file(fname, hidden_filter, name_filter):
 		return False
 	return True
 
-class Directory(FileSystemObject, Accumulator, SettingsAware):
+class Directory(FileSystemObject, Accumulator, Loadable, SettingsAware):
 	is_directory = True
 	enterable = False
 	load_generator = None
> 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 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 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674