RefactoringRope/RefactoringClient.py

branch
server_client_variant
changeset 172
c8890f852917
parent 170
05ef7c12a6d4
child 173
2cdb7c48b719
equal deleted inserted replaced
171:9872d31f8755 172:c8890f852917
54 "GetConfig": self.__getConfig, 54 "GetConfig": self.__getConfig,
55 "ConfigChanged": self.__configChanged, 55 "ConfigChanged": self.__configChanged,
56 "PerformSoa": self.__performSOA, 56 "PerformSoa": self.__performSOA,
57 "ReportChanged": self.__reportChanged, 57 "ReportChanged": self.__reportChanged,
58 "History": self.__processHistory, 58 "History": self.__processHistory,
59 "PreviewChanges": self.__previewChanges,
60 "ApplyChanges": self.__applyChanges,
61 "ClearChanges": self.__clearChanges,
62 "CalculateRenameChanges": self.__calculateRenameChanges,
59 } 63 }
60 64
61 from FileSystemCommands import RefactoringClientFileSystemCommands 65 from FileSystemCommands import RefactoringClientFileSystemCommands
62 self.__fsCommands = RefactoringClientFileSystemCommands(self) 66 self.__fsCommands = RefactoringClientFileSystemCommands(self)
63 67
418 elif subcommand == "ClearChanges": 422 elif subcommand == "ClearChanges":
419 try: 423 try:
420 del self.__changes["History"] 424 del self.__changes["History"]
421 except KeyError: 425 except KeyError:
422 pass 426 pass
427
428 def __clearChanges(self, params):
429 """
430 Private method to clear the changes cache of a given change group.
431
432 @param params dictionary containing the method parameters sent by
433 the server
434 @type dict
435 """
436 try:
437 del self.__changes[params["ChangeGroup"]]
438 except KeyError:
439 pass
440
441 def __applyChanges(self, params):
442 """
443 Private method to apply the changes of a given change group.
444
445 @param params dictionary containing the method parameters sent by
446 the server
447 @type dict
448 """
449 errorDict = {}
450
451 from ProgressHandle import ProgressHandle
452 self.__progressHandle = ProgressHandle(self, params["Title"], False)
453 try:
454 changes = self.__changes[params["ChangeGroup"]]
455 self.___project.do(changes, self.__progressHandle)
456 except Exception as err:
457 errorDict = self.__handleRopeError(err)
458 self.__progressHandle.reset()
459 self.__progressHandle = None
460
461 result = {
462 "Subcommand": "ChangesApplied",
463 "ChangeGroup": params["ChangeGroup"],
464 "ChangedFiles": [
465 res.real_path for res in changes.get_changed_resources()
466 ],
467 }
468 result.update(errorDict)
469
470 self.sendJson("Changes", result)
471
472 def __previewChanges(self, params):
473 """
474 Private method to determine the changes data for a preview.
475
476 @param params dictionary containing the method parameters sent by
477 the server
478 @type dict
479 """
480 changes = self.__changes[params["ChangeGroup"]]
481
482 changesData = []
483 for change in changes:
484 changeTitle = str(change)
485 try:
486 changeText = change.get_description()
487 except AttributeError:
488 changeText = None
489 changesData.append([changeTitle, changeText])
490
491 result = {
492 "Subcommand": "PreviewChanges",
493 "ChangeGroup": params["ChangeGroup"],
494 "Description": changes.description,
495 "Changes": changesData,
496 }
497
498 self.sendJson("Changes", result)
499
500 def __calculateRenameChanges(self, params):
501 """
502 Private method to calculate the rename changes based on the parameters
503 sent by the server.
504
505 @param params dictionary containing the method parameters sent by
506 the server
507 @type dict
508 """
509 title = params["Title"]
510 filename = params["FileName"]
511 offset = params["Offset"]
512 isLocal = params["LocalRename"]
513 newName = params["NewName"]
514 renameHierarchy = params["RenameHierarchy"]
515 renameInStrings = params["RenameInStrings"]
516
517 errorDict = {}
518 changes = []
519 result = {
520 "ChangeGroup": params["ChangeGroup"],
521 }
522
523 import rope.refactor.rename
524 resource = rope.base.libutils.path_to_resource(
525 self.__project, filename)
526
527 try:
528 renamer = rope.refactor.rename.Rename(
529 self.__project, resource, offset)
530 except Exception as err:
531 errorDict = self.__handleRopeError(err)
532 result.update(errorDict)
533 self.sendJson("Changes", result)
534 return
535
536 if isLocal:
537 resources = [resource]
538 else:
539 resources = None
540
541 from ProgressHandle import ProgressHandle
542 self.__progressHandle = ProgressHandle(self, title, True)
543 try:
544 changes = renamer.get_changes(
545 newName,
546 resources=resources,
547 in_hierarchy=renameHierarchy,
548 unsure=self.__confirmUnsure,
549 docs=renameInStrings,
550 task_handle=self.__progressHandle)
551 except Exception as err:
552 errorDict = self.__handleRopeError(err)
553 self.__progressHandle.reset()
554 self.__progressHandle = None
555
556 if changes:
557 self.__changes[params["ChangeGroup"]] = changes
558
559 result["Subcommand"] = "ChangesCalculated"
560 result.update(errorDict)
561
562 self.sendJson("Changes", result)
563
564 def __confirmUnsure(self, occurrence):
565 """
566 Private method to confirm unsure occurrences.
567
568 @parameter occurrence reference to the occurrence object
569 @type rope.refactor.occurrences.Occurrence
570 @return flag indicating an occurrence
571 @rtype bool
572 """
573 # TODO: implement this method; synchronous poll
423 574
424 if __name__ == '__main__': 575 if __name__ == '__main__':
425 if len(sys.argv) != 4: 576 if len(sys.argv) != 4:
426 print('Host, port and project path parameters are missing. Abort.') 577 print('Host, port and project path parameters are missing. Abort.')
427 sys.exit(1) 578 sys.exit(1)

eric ide

mercurial