Changeset 1170:f59845f5741b
- Timestamp:
- 05/19/08 22:24:40 (7 months ago)
- Author:
- Ronny Pfannschmidt <Ronny.Pfannschmidt@…>
- Message:
-
took the Environment class away, its module level now
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r1157
|
r1170
|
|
| 28 | 28 | |
| 29 | 29 | # PIDA Imports |
| 30 | | from pida.core.environment import Environment, get_uidef_path |
| | 30 | from pida.core.environment import get_uidef_path |
| 31 | 31 | from pida.core.service import Service |
| 32 | 32 | from pida.core.events import EventsConfig |
-
|
r1036
|
r1170
|
|
| 30 | 30 | |
| 31 | 31 | # PIDA Imports |
| 32 | | from pida.core.environment import Environment, get_uidef_path |
| 33 | 32 | from pida.core.service import Service |
| 34 | 33 | from pida.core.actions import ActionsConfig |
-
|
r1140
|
r1170
|
|
| 29 | 29 | |
| 30 | 30 | # PIDA Imports |
| 31 | | from pida.core.environment import Environment, get_uidef_path |
| | 31 | from pida.core.environment import pida_home, get_uidef_path |
| 32 | 32 | from pida.core.service import Service |
| 33 | 33 | from pida.core.actions import ActionsConfig |
| … |
… |
|
| 189 | 189 | |
| 190 | 190 | def start(self): |
| 191 | | self._filename = os.path.join(Environment.pida_home, 'rfc-index.txt') |
| | 191 | self._filename = os.path.join(pida_home, 'rfc-index.txt') |
| 192 | 192 | self._view = RfcView(self) |
| 193 | 193 | self._has_loaded = False |
-
|
r1040
|
r1170
|
|
| 76 | 76 | # This can test if PIDA is installed |
| 77 | 77 | try: |
| 78 | | from pida.core.environment import Environment |
| | 78 | from pida.core import environment as env |
| 79 | 79 | from pida.core.boss import Boss |
| 80 | 80 | from pida import PIDA_VERSION |
| … |
… |
|
| 88 | 88 | |
| 89 | 89 | |
| 90 | | def run_pida(env): |
| 91 | | b = Boss(env) |
| | 90 | def run_pida(): |
| | 91 | b = Boss() |
| 92 | 92 | PosixSignalHandler(b) |
| 93 | 93 | try: |
| … |
… |
|
| 126 | 126 | |
| 127 | 127 | def main(): |
| 128 | | env = Environment(sys.argv) |
| 129 | | sys.argv = sys.argv[:1] |
| 130 | 128 | if env.is_debug(): |
| 131 | 129 | os.environ['PIDA_DEBUG'] = '1' |
| … |
… |
|
| 136 | 134 | set_trace() |
| 137 | 135 | if env.is_version(): |
| 138 | | run_func = run_version |
| | 136 | run_version() |
| 139 | 137 | else: |
| 140 | | run_func = run_pida |
| 141 | | exit_val = run_func(env) |
| 142 | | signal.signal(signal.SIGALRM, force_quit) |
| 143 | | signal.alarm(3) |
| 144 | | sys.exit(exit_val) |
| | 138 | exit_val = run_pida() |
| | 139 | signal.signal(signal.SIGALRM, force_quit) |
| | 140 | signal.alarm(3) |
| | 141 | sys.exit(exit_val) |
| 145 | 142 | |
| 146 | 143 | |
-
|
r1158
|
r1170
|
|
| 6 | 6 | from pida.core.servicemanager import ServiceManager |
| 7 | 7 | from pida.core.log import get_logger |
| 8 | | |
| | 8 | from pida.core import environment as env |
| 9 | 9 | from pida.ui.icons import IconRegister |
| 10 | 10 | from pida.ui.window import PidaWindow |
| … |
… |
|
| 23 | 23 | |
| 24 | 24 | |
| 25 | | def __init__(self, env=None): |
| 26 | | self._env = env |
| 27 | | |
| | 25 | def __init__(self): |
| 28 | 26 | if env.is_debug(): |
| 29 | 27 | get_logger().setLevel(logging.DEBUG) |
| … |
… |
|
| 42 | 40 | |
| 43 | 41 | def _run_first_time(self): |
| 44 | | if not self._env.has_firstrun() or self._env.is_firstrun(): |
| | 42 | if not env.has_firstrun() or env.is_firstrun(): |
| 45 | 43 | ft = FirstTimeWindow(self._sm.get_available_editors()) |
| 46 | | success, editor = ft.run(self._env.get_firstrun_filename()) |
| | 44 | success, editor = ft.run(env.firstrun_filename) |
| 47 | 45 | self.override_editor = editor |
| 48 | 46 | self.quit_before_started = not success |
| … |
… |
|
| 87 | 85 | |
| 88 | 86 | def get_service_dirs(self): |
| 89 | | if self._env is None: |
| 90 | | return [] |
| 91 | | else: |
| 92 | | return [ |
| 93 | | self._env.get_base_service_directory(), |
| 94 | | self._env.get_local_service_directory(), |
| 95 | | ] |
| | 87 | import pida.services |
| | 88 | return pida.services.__path__ |
| 96 | 89 | |
| 97 | 90 | def get_editor_dirs(self): |
| 98 | | if self._env is None: |
| 99 | | return [] |
| 100 | | else: |
| 101 | | return [ |
| 102 | | self._env.get_base_editor_directory(), |
| 103 | | ] |
| | 91 | import pida.editors |
| | 92 | return pida.editors.__path__ |
| 104 | 93 | |
| 105 | | def get_editor(self): |
| | 94 | @property |
| | 95 | def editor(self): |
| 106 | 96 | return self._sm.editor |
| 107 | | |
| 108 | | editor = property(get_editor) |
| 109 | 97 | |
| 110 | 98 | def get_plugins(self): |
| … |
… |
|
| 130 | 118 | |
| 131 | 119 | def get_pida_home(self): |
| 132 | | return self._env.pida_home |
| | 120 | return env.pida_home |
| 133 | 121 | |
| 134 | 122 | def show_splash(self): |
-
|
r1056
|
r1170
|
|
| 1 | 1 | import os |
| | 2 | import sys |
| 2 | 3 | from optparse import OptionParser |
| 3 | 4 | |
| … |
… |
|
| 31 | 32 | return get_resource_path('data', name) |
| 32 | 33 | |
| | 34 | pida_home = os.path.expanduser('~/.pida2') |
| | 35 | firstrun_filename = os.path.join(pida_home, 'first_run_wizard') |
| | 36 | plugins_dir = os.path.join(pida_home, 'plugins') |
| 33 | 37 | |
| 34 | | class Environment(object): |
| | 38 | if not os.path.exists(pida_home): |
| | 39 | os.mkdir(pida_home) |
| 35 | 40 | |
| 36 | | pida_home = os.path.expanduser('~/.pida2') |
| | 41 | op = OptionParser() |
| | 42 | op.add_option('-v', '--version', action='store_true', |
| | 43 | help=_('Print version information and exit.')) |
| | 44 | op.add_option('-D', '--debug', action='store_true', |
| | 45 | help=_('Run PIDA with added debug information.')) |
| | 46 | op.add_option('-T', '--trace', action='store_true', |
| | 47 | help=_('Run PIDA with tracing.')) |
| | 48 | op.add_option('-F', '--firstrun', action='store_true', |
| | 49 | help=_('Run the PIDA first run wizard.')) |
| 37 | 50 | |
| 38 | | def __init__(self, argv): |
| 39 | | if not os.path.exists(self.pida_home): |
| 40 | | os.mkdir(self.pida_home) |
| 41 | | self.get_options(argv) |
| 42 | | self.env = dict(os.environ) |
| | 51 | opts, args = op.parse_args(sys.argv) |
| | 52 | env = dict(os.environ) |
| 43 | 53 | |
| 44 | | def get_options(self, argv): |
| 45 | | op = OptionParser() |
| 46 | | op.add_option('-v', '--version', action='store_true', |
| 47 | | help=_('Print version information and exit.')) |
| 48 | | op.add_option('-D', '--debug', action='store_true', |
| 49 | | help=_('Run PIDA with added debug information.')) |
| 50 | | op.add_option('-T', '--trace', action='store_true', |
| 51 | | help=_('Run PIDA with tracing.')) |
| 52 | | op.add_option('-F', '--firstrun', action='store_true', |
| 53 | | help=_('Run the PIDA first run wizard.')) |
| 54 | | self.opts, self.args = op.parse_args(argv) |
| | 54 | def is_version(): |
| | 55 | return opts.version |
| 55 | 56 | |
| 56 | | def is_version(self): |
| 57 | | return self.opts.version |
| | 57 | def is_debug(): |
| | 58 | return opts.debug |
| 58 | 59 | |
| 59 | | def is_debug(self): |
| 60 | | return self.opts.debug |
| | 60 | def is_trace(): |
| | 61 | return opts.trace |
| 61 | 62 | |
| 62 | | def is_trace(self): |
| 63 | | return self.opts.trace |
| | 63 | def is_firstrun(): |
| | 64 | return opts.firstrun |
| 64 | 65 | |
| 65 | | def is_firstrun(self): |
| 66 | | return self.opts.firstrun |
| 67 | | |
| 68 | | def get_base_service_directory(self): |
| 69 | | return os.path.join( |
| 70 | | os.path.dirname(os.path.dirname(__file__)), 'services') |
| 71 | | |
| 72 | | def get_local_service_directory(self): |
| 73 | | path = os.path.join(self.pida_home, 'services') |
| 74 | | if not os.path.exists(path): |
| 75 | | os.mkdir(path) |
| 76 | | return path |
| 77 | | |
| 78 | | def get_base_editor_directory(self): |
| 79 | | return os.path.join( |
| 80 | | os.path.dirname(os.path.dirname(__file__)), 'editors') |
| 81 | | |
| 82 | | def get_plugins_directory(self): |
| 83 | | path = os.path.join(self.pida_home, 'plugins') |
| 84 | | if not os.path.exists(path): |
| 85 | | os.mkdir(path) |
| 86 | | return path |
| 87 | | |
| 88 | | def get_firstrun_filename(self): |
| 89 | | return os.path.join(self.pida_home, 'first_run_wizard') |
| 90 | | |
| 91 | | def has_firstrun(self): |
| 92 | | return os.path.exists(self.get_firstrun_filename()) |
| | 66 | def has_firstrun(): |
| | 67 | return os.path.exists(firstrun_filename) |
| 93 | 68 | |
| 94 | 69 | # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: |
-
|
r1165
|
r1170
|
|
| 41 | 41 | from pida.core.servicemanager import ServiceLoader, ServiceLoadingError |
| 42 | 42 | from pida.core.options import OptionItem, manager, OTypeStringList, OTypeString |
| | 43 | |
| | 44 | from pida.core.environment import plugins_dir |
| 43 | 45 | |
| 44 | 46 | from pida.utils.web import fetch_url |
| … |
… |
|
| 148 | 150 | self.item = None |
| 149 | 151 | self.installed_item = None |
| 150 | | self.plugins_dir = '' |
| 151 | 152 | self.first_start = True |
| 152 | 153 | self.installed_list.set_columns([ |
| … |
… |
|
| 385 | 386 | self._viewedit = PluginsEditView(self) |
| 386 | 387 | self.task = None |
| 387 | | self.plugin_path = self.boss._env.get_plugins_directory() |
| 388 | 388 | self._start_list = OptionItem('plugins', 'start_list', _('Start plugin list'), |
| 389 | 389 | OTypeStringList, [], _('List of plugin to start'), None) |
| … |
… |
|
| 429 | 429 | def update_installed_plugins(self, start=False): |
| 430 | 430 | self._view.clear_installed() |
| 431 | | l_installed = list(self._loader.get_all_service_files([self.plugin_path])) |
| | 431 | l_installed = list(self._loader.get_all_service_files([plugins_dir])) |
| 432 | 432 | if start: |
| 433 | 433 | start_list = manager.get_value(self._start_list) |
| … |
… |
|
| 481 | 481 | def _fetch_available_plugins(self): |
| 482 | 482 | # get installed items |
| 483 | | l_installed = list(self._loader.get_all_service_files([self.plugin_path])) |
| | 483 | l_installed = list(self._loader.get_all_service_files([plugins_dir])) |
| 484 | 484 | installed_list = [] |
| 485 | 485 | for service_name, service_file in l_installed: |
| … |
… |
|
| 517 | 517 | def install(self, item, content): |
| 518 | 518 | # write plugin |
| 519 | | plugin_path = os.path.join(self.plugin_path, item.plugin) |
| 520 | | filename = os.path.join(self.plugin_path, os.path.basename(item.url)) |
| | 519 | plugin_path = os.path.join(plugins_dir, item.plugin) |
| | 520 | filename = os.path.join(plugins_dir, os.path.basename(item.url)) |
| 521 | 521 | file = open(filename, 'wb') |
| 522 | 522 | file.write(content) |
| … |
… |
|
| 525 | 525 | # check if we need to stop and remove him |
| 526 | 526 | l_installed = [p[0] for p in |
| 527 | | self._loader.get_all_service_files([self.plugin_path])] |
| | 527 | self._loader.get_all_service_files([plugins_dir])] |
| 528 | 528 | item.directory = plugin_path |
| 529 | 529 | if item.plugin in l_installed: |
| … |
… |
|
| 533 | 533 | tar = tarfile.open(filename, 'r:gz') |
| 534 | 534 | for tarinfo in tar: |
| 535 | | tar.extract(tarinfo, path=self.plugin_path) |
| | 535 | tar.extract(tarinfo, path=plugins_dir) |
| 536 | 536 | tar.close() |
| 537 | 537 | os.unlink(filename) |
| 538 | 538 | |
| 539 | 539 | # start service |
| 540 | | self.start_plugin(plugin_path) |
| | 540 | self.start_plugin(plugin_dir) |
| 541 | 541 | self.boss.cmd('notify', 'notify', title=_('Plugins'), |
| 542 | 542 | data=_('Installation of %s completed') % item.plugin) |
-
|
r1038
|
r1170
|
|
| 73 | 73 | self.add_main_widget(vbox) |
| 74 | 74 | for service in self.svc.boss.get_services() + [ |
| 75 | | self.svc.boss.get_editor()]: |
| | 75 | self.svc.boss.editor]: |
| 76 | 76 | if len(service.get_keyboard_options()): |
| 77 | 77 | sli = ServiceListItem(service) |
-
|
r1139
|
r1170
|
|
| 121 | 121 | def _center_on_parent(self, view, size): |
| 122 | 122 | gdkwindow = view.get_parent_window() |
| 123 | | px, py, pw, ph, pbd = view.svc.boss.get_window().window.get_geometry() |
| | 123 | px, py, pw, ph, pbd = view.svc.window.window.get_geometry() |
| 124 | 124 | w, h = size |
| 125 | 125 | cx = (pw - w) / 2 |
-
|
r1157
|
r1170
|
|
| 363 | 363 | |
| 364 | 364 | if not self.svc._executable: |
| 365 | | self.boss.get_window().error_dlg( |
| | 365 | self.boss.window.error_dlg( |
| 366 | 366 | 'Debug controller is not fully configured.') |
| 367 | 367 | else: |
| 368 | 368 | if self.svc._is_running: |
| 369 | | self.boss.get_window().error_dlg( |
| | 369 | self.boss.window.error_dlg( |
| 370 | 370 | 'Debugger already running.') |
| 371 | 371 | else: |
| … |
… |
|
| 373 | 373 | self.svc.emit('debugger_started') |
| 374 | 374 | else: |
| 375 | | self.boss.get_window().error_dlg( |
| | 375 | self.boss.window.error_dlg( |
| 376 | 376 | 'Debug session failed to launch.') |
| 377 | 377 | |