--- a/RefactoringRope/RefactoringClient.py Sat Sep 23 17:21:24 2017 +0200 +++ b/RefactoringRope/RefactoringClient.py Sat Sep 23 17:40:07 2017 +0200 @@ -80,6 +80,8 @@ "CalculateSignatureChanges": self.__calculateSignatureChanges, "CalculateInlineArgumentDefaultChanges": self.__calculateInlineArgumentDefaultChanges, + "CalculateModuleToPackageChanges": + self.__calculateModuleToPackageChanges, } from FileSystemCommands import RefactoringClientFileSystemCommands @@ -1205,7 +1207,6 @@ errorDict = {} result = { - "Subcommand": "Signature", "ChangeGroup": changeGroup, "Title": title, } @@ -1263,7 +1264,6 @@ errorDict = {} result = { - "Subcommand": "Signature", "ChangeGroup": changeGroup, "Title": title, } @@ -1289,6 +1289,53 @@ result.update(errorDict) self.sendJson("Changes", result) + + def __calculateModuleToPackageChanges(self, params): + """ + Private method to calculate the 'Module to Package' changes + based on the parameters sent by the server. + + @param params dictionary containing the method parameters sent by + the server + @type dict + """ + changeGroup = params["ChangeGroup"] + title = params["Title"] + filename = params["FileName"] + + errorDict = {} + result = { + "ChangeGroup": changeGroup, + "Title": title, + } + + import rope.refactor.topackage + resource = rope.base.libutils.path_to_resource( + self.__project, filename) + try: + changes = rope.refactor.topackage.ModuleToPackage( + self.__project, resource).get_changes() + except Exception as err: + errorDict = self.__handleRopeError(err) + + self.__changes[changeGroup] = changes + + # send the change description first + if changes: + description = changes.description + else: + description = "" + self.sendJson("Changes", { + "ChangeGroup": changeGroup, + "Title": title, + "Subcommand": "ChangeDescription", + "Description": description, + }) + + result["Subcommand"] = "ChangesCalculated" + result.update(errorDict) + + self.sendJson("Changes", result) if __name__ == '__main__':