| 1216 | return subprocess.call(args) == 0 |
| 1217 | |
| 1218 | def edit_config(self): |
| 1219 | if self.config.config_path is None: |
| 1220 | self.interact.notify(_("No config file specified.")) |
| 1221 | return |
| 1222 | |
| 1223 | if not self.config.config_path.is_file(): |
| 1224 | if self.interact.confirm( |
| 1225 | _("Config file does not exist - create new from default? (y/N)") |
| 1226 | ): |
| 1227 | try: |
| 1228 | default_config = pkgutil.get_data( |
| 1229 | "bpython", "sample-config" |
| 1230 | ) |
| 1231 | # Py3 files need unicode |
| 1232 | default_config = default_config.decode("ascii") |
| 1233 | containing_dir = self.config.config_path.parent |
| 1234 | if not containing_dir.exists(): |
| 1235 | containing_dir.mkdir(parents=True) |
| 1236 | with open(self.config.config_path, "w") as f: |
| 1237 | f.write(default_config) |
| 1238 | except OSError as e: |
| 1239 | self.interact.notify( |
| 1240 | _("Error writing file '%s': %s") |
| 1241 | % (self.config.config_path, e) |
| 1242 | ) |
| 1243 | return False |
| 1244 | else: |
| 1245 | return False |
| 1246 | |
| 1247 | try: |
| 1248 | if self.open_in_external_editor(self.config.config_path): |
| 1249 | self.interact.notify( |
| 1250 | _( |
| 1251 | "bpython config file edited. Restart bpython for changes to take effect." |
| 1252 | ) |
| 1253 | ) |
| 1254 | except OSError as e: |
| 1255 | self.interact.notify(_("Error editing config file: %s") % e) |
| 1256 | |
| 1257 | |
| 1258 | def next_indentation(line, tab_length) -> int: |