| Conditions | 9 |
| Total Lines | 118 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 9 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import os.path |
||
| 46 | def plugin_loaded(): |
||
| 47 | """ |
||
| 48 | Called automatically from ST3 if plugin is loaded. |
||
| 49 | |||
| 50 | Is required now due to async call and ignoring sublime.* from main routine |
||
| 51 | """ |
||
| 52 | |||
| 53 | packages = sublime.packages_path() |
||
| 54 | prompt_dir = os.path.join(packages, "User", "Rainmeter", "path") |
||
| 55 | |||
| 56 | __require_path(prompt_dir) |
||
| 57 | |||
| 58 | open_file_dialog_bat = os.path.join(prompt_dir, "open_file_dialog.ps1") |
||
| 59 | open_folder_dialog_bat = os.path.join(prompt_dir, "open_folder_dialog.ps1") |
||
| 60 | |||
| 61 | __copy_on_absence_or_newer(open_file_dialog_bat, "Packages/Rainmeter/path/open_file_dialog.ps1") |
||
| 62 | __copy_on_absence_or_newer(open_folder_dialog_bat, "Packages/Rainmeter/path/open_folder_dialog.ps1") |
||
| 63 | |||
| 64 | program_path = get_cached_program_path() |
||
| 65 | if not program_path: |
||
| 66 | """ |
||
| 67 | Open dialog and set program path. |
||
| 68 | |||
| 69 | Due to cache this might be annoying |
||
| 70 | since I cant call cached stuff |
||
| 71 | before I can assure that the path is correct |
||
| 72 | or just reset the cache |
||
| 73 | """ |
||
| 74 | |||
| 75 | def on_rainmeter_exe_browsed(message): |
||
| 76 | """ |
||
| 77 | If file is browsed we need to verify that this is the Rainmeter.exe. |
||
| 78 | If it is we need to reset the cache via. |
||
| 79 | """ |
||
| 80 | if os.path.exists(message): |
||
| 81 | # If file is browsed |
||
| 82 | # - verify Rainmeter.exe. |
||
| 83 | # - reset cache |
||
| 84 | # - save new path in settings |
||
| 85 | |||
| 86 | logger.info("Verified existence of Rainmeter.exe in '" + message + "'.") |
||
| 87 | settings = sublime.load_settings("Rainmeter.sublime-settings") |
||
| 88 | rm_dir = os.path.dirname(message) |
||
| 89 | normed_rm_dir = os.path.normpath(rm_dir) |
||
| 90 | |||
| 91 | settings.set("rainmeter_path", normed_rm_dir) |
||
| 92 | sublime.save_settings("Rainmeter.sublime-settings") |
||
| 93 | logger.info("Rewrote settings to include rainmeter path.") |
||
| 94 | sublime.message_dialog("Successfully set the Rainmeter application path to '" + normed_rm_dir + "'.") |
||
| 95 | |||
| 96 | # we have to reset every cache because all are dependent on the program path |
||
| 97 | # at least transitively |
||
| 98 | get_cached_program_path.cache_clear() |
||
| 99 | get_cached_program_drive.cache_clear() |
||
| 100 | get_cached_setting_path.cache_clear() |
||
| 101 | get_cached_skin_path.cache_clear() |
||
| 102 | get_cached_addon_path.cache_clear() |
||
| 103 | get_cached_plugin_path.cache_clear() |
||
| 104 | logger.info("Cleared cache.") |
||
| 105 | |||
| 106 | elif message == "-1": |
||
| 107 | logger.info("User canceled Rainmeter.exe input.") |
||
| 108 | pass |
||
| 109 | |||
| 110 | else: |
||
| 111 | # retry by recalling it again. |
||
| 112 | logger.info("No valid Rainmeter.exe found. Retrying again.") |
||
| 113 | browse_file(on_rainmeter_exe_browsed) |
||
| 114 | |||
| 115 | browse_file(on_rainmeter_exe_browsed) |
||
| 116 | |||
| 117 | skin_path = get_cached_skin_path() |
||
| 118 | if not skin_path: |
||
| 119 | """ |
||
| 120 | Open folder dialog and set skin path. |
||
| 121 | """ |
||
| 122 | |||
| 123 | def on_skins_folder_browsed(skin_dir): |
||
| 124 | """.""" |
||
| 125 | logger.info("skin_dir: " + skin_dir) |
||
| 126 | if os.path.exists(skin_dir): |
||
| 127 | # If folder is browsed: |
||
| 128 | # - verify skin folder |
||
| 129 | # - reset cache |
||
| 130 | # - save new path in settings |
||
| 131 | |||
| 132 | logger.info("Verified existence of Rainmeter Skin folder in '" + skin_dir + "'.") |
||
| 133 | settings = sublime.load_settings("Rainmeter.sublime-settings") |
||
| 134 | normed_skin_dir = os.path.normpath(skin_dir) |
||
| 135 | |||
| 136 | settings.set("rainmeter_skins_path", normed_skin_dir) |
||
| 137 | sublime.save_settings("Rainmeter.sublime-settings") |
||
| 138 | logger.info("Rewrote settings to include skin path.") |
||
| 139 | sublime.message_dialog("Successfully set the Rainmeter Skins path to '" + skin_dir + "'.") |
||
| 140 | |||
| 141 | # we have to reset every cache because all are dependent on the program path |
||
| 142 | # at least transitively |
||
| 143 | get_cached_skin_path.cache_clear() |
||
| 144 | logger.info("Cleared cache.") |
||
| 145 | |||
| 146 | elif skin_dir == "-1": |
||
| 147 | logger.info("User canceled Rainmeter Skin folder input.") |
||
| 148 | pass |
||
| 149 | |||
| 150 | else: |
||
| 151 | # retry by recalling it again. |
||
| 152 | logger.info("No valid Rainmeter Skin folder found. Retrying again.") |
||
| 153 | browse_folder(on_skins_folder_browsed) |
||
| 154 | |||
| 155 | browse_folder(on_skins_folder_browsed) |
||
| 156 | |||
| 157 | padding = 16 |
||
| 158 | logger.info("#PROGRAMPATH#:".ljust(padding) + get_cached_program_path()) # Rainmeter.exe |
||
| 159 | logger.info("#PROGRAMDRIVE#:".ljust(padding) + get_cached_program_drive()) |
||
| 160 | logger.info("#SETTINGSPATH#:".ljust(padding) + get_cached_setting_path()) # Rainmeter.ini |
||
| 161 | logger.info("#SKINSPATH#:".ljust(padding) + get_cached_skin_path()) # Rainmeter/Skins path |
||
| 162 | logger.info("#PLUGINSPATH#:".ljust(padding) + get_cached_plugin_path()) |
||
| 163 | logger.info("#ADDONSPATH#:".ljust(padding) + get_cached_addon_path()) |
||
| 164 |