Changeset 1170:f59845f5741b

Show
Ignore:
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:
10 modified

Legend:

Unmodified
Added
Removed
  • pida-plugins/gtags/gtags.py

    r1157 r1170  
    2828 
    2929# PIDA Imports 
    30 from pida.core.environment import Environment, get_uidef_path 
     30from pida.core.environment import get_uidef_path 
    3131from pida.core.service import Service 
    3232from pida.core.events import EventsConfig 
  • pida-plugins/koders/koders.py

    r1036 r1170  
    3030 
    3131# PIDA Imports 
    32 from pida.core.environment import Environment, get_uidef_path 
    3332from pida.core.service import Service 
    3433from pida.core.actions import ActionsConfig 
  • pida-plugins/rfc/rfc.py

    r1140 r1170  
    2929 
    3030# PIDA Imports 
    31 from pida.core.environment import Environment, get_uidef_path 
     31from pida.core.environment import pida_home, get_uidef_path 
    3232from pida.core.service import Service 
    3333from pida.core.actions import ActionsConfig 
     
    189189 
    190190    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') 
    192192        self._view = RfcView(self) 
    193193        self._has_loaded = False 
  • pida/core/application.py

    r1040 r1170  
    7676# This can test if PIDA is installed 
    7777try: 
    78     from pida.core.environment import Environment 
     78    from pida.core import environment as env 
    7979    from pida.core.boss import Boss 
    8080    from pida import PIDA_VERSION 
     
    8888 
    8989 
    90 def run_pida(env): 
    91     b = Boss(env) 
     90def run_pida(): 
     91    b = Boss() 
    9292    PosixSignalHandler(b) 
    9393    try: 
     
    126126 
    127127def main(): 
    128     env = Environment(sys.argv) 
    129     sys.argv = sys.argv[:1] 
    130128    if env.is_debug(): 
    131129        os.environ['PIDA_DEBUG'] = '1' 
     
    136134        set_trace() 
    137135    if env.is_version(): 
    138         run_func = run_version 
     136        run_version() 
    139137    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) 
    145142 
    146143 
  • pida/core/boss.py

    r1158 r1170  
    66from pida.core.servicemanager import ServiceManager 
    77from pida.core.log import get_logger 
    8  
     8from pida.core import environment as env 
    99from pida.ui.icons import IconRegister 
    1010from pida.ui.window import PidaWindow 
     
    2323 
    2424 
    25     def __init__(self, env=None): 
    26         self._env = env 
    27  
     25    def __init__(self): 
    2826        if env.is_debug(): 
    2927            get_logger().setLevel(logging.DEBUG) 
     
    4240 
    4341    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(): 
    4543            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) 
    4745            self.override_editor = editor 
    4846            self.quit_before_started = not success 
     
    8785 
    8886    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__ 
    9689 
    9790    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__ 
    10493 
    105     def get_editor(self): 
     94    @property 
     95    def editor(self): 
    10696        return self._sm.editor 
    107  
    108     editor = property(get_editor) 
    10997 
    11098    def get_plugins(self): 
     
    130118 
    131119    def get_pida_home(self): 
    132         return self._env.pida_home 
     120        return env.pida_home 
    133121 
    134122    def show_splash(self): 
  • pida/core/environment.py

    r1056 r1170  
    11import os 
     2import sys 
    23from optparse import OptionParser 
    34 
     
    3132    return get_resource_path('data', name) 
    3233 
     34pida_home = os.path.expanduser('~/.pida2') 
     35firstrun_filename = os.path.join(pida_home, 'first_run_wizard') 
     36plugins_dir = os.path.join(pida_home, 'plugins') 
    3337 
    34 class Environment(object): 
     38if not os.path.exists(pida_home): 
     39    os.mkdir(pida_home) 
    3540 
    36     pida_home = os.path.expanduser('~/.pida2') 
     41op = OptionParser() 
     42op.add_option('-v', '--version', action='store_true', 
     43    help=_('Print version information and exit.')) 
     44op.add_option('-D', '--debug', action='store_true', 
     45    help=_('Run PIDA with added debug information.')) 
     46op.add_option('-T', '--trace', action='store_true', 
     47    help=_('Run PIDA with tracing.')) 
     48op.add_option('-F', '--firstrun', action='store_true', 
     49    help=_('Run the PIDA first run wizard.')) 
    3750 
    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) 
     51opts, args = op.parse_args(sys.argv) 
     52env = dict(os.environ) 
    4353 
    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) 
     54def is_version(): 
     55    return opts.version 
    5556 
    56     def is_version(self): 
    57         return self.opts.version 
     57def is_debug(): 
     58    return opts.debug 
    5859 
    59     def is_debug(self): 
    60         return self.opts.debug 
     60def is_trace(): 
     61    return opts.trace 
    6162 
    62     def is_trace(self): 
    63         return self.opts.trace 
     63def is_firstrun(): 
     64    return opts.firstrun 
    6465 
    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()) 
     66def has_firstrun(): 
     67    return os.path.exists(firstrun_filename) 
    9368 
    9469# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: 
  • pida/services/plugins/plugins.py

    r1165 r1170  
    4141from pida.core.servicemanager import ServiceLoader, ServiceLoadingError 
    4242from pida.core.options import OptionItem, manager, OTypeStringList, OTypeString 
     43 
     44from pida.core.environment import plugins_dir 
    4345 
    4446from pida.utils.web import fetch_url 
     
    148150        self.item = None 
    149151        self.installed_item = None 
    150         self.plugins_dir = '' 
    151152        self.first_start = True 
    152153        self.installed_list.set_columns([ 
     
    385386        self._viewedit = PluginsEditView(self) 
    386387        self.task = None 
    387         self.plugin_path = self.boss._env.get_plugins_directory() 
    388388        self._start_list = OptionItem('plugins', 'start_list', _('Start plugin list'), 
    389389                OTypeStringList, [], _('List of plugin to start'), None) 
     
    429429    def update_installed_plugins(self, start=False): 
    430430        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])) 
    432432        if start: 
    433433            start_list = manager.get_value(self._start_list) 
     
    481481    def _fetch_available_plugins(self): 
    482482        # 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])) 
    484484        installed_list = [] 
    485485        for service_name, service_file in l_installed: 
     
    517517    def install(self, item, content): 
    518518        # 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)) 
    521521        file = open(filename, 'wb') 
    522522        file.write(content) 
     
    525525        # check if we need to stop and remove him 
    526526        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])] 
    528528        item.directory = plugin_path 
    529529        if item.plugin in l_installed: 
     
    533533        tar = tarfile.open(filename, 'r:gz') 
    534534        for tarinfo in tar: 
    535             tar.extract(tarinfo, path=self.plugin_path) 
     535            tar.extract(tarinfo, path=plugins_dir) 
    536536        tar.close() 
    537537        os.unlink(filename) 
    538538 
    539539        # start service 
    540         self.start_plugin(plugin_path) 
     540        self.start_plugin(plugin_dir) 
    541541        self.boss.cmd('notify', 'notify', title=_('Plugins'), 
    542542                data=_('Installation of %s completed') % item.plugin) 
  • pida/services/shortcuts/shortcuts.py

    r1038 r1170  
    7373        self.add_main_widget(vbox) 
    7474        for service in self.svc.boss.get_services() + [ 
    75                                 self.svc.boss.get_editor()]: 
     75                                self.svc.boss.editor]: 
    7676            if len(service.get_keyboard_options()): 
    7777                sli = ServiceListItem(service) 
  • pida/ui/paneds.py

    r1139 r1170  
    121121    def _center_on_parent(self, view, size): 
    122122        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() 
    124124        w, h = size 
    125125        cx = (pw - w) / 2 
  • pida/utils/debugger/debugger.py

    r1157 r1170  
    363363 
    364364        if not self.svc._executable: 
    365             self.boss.get_window().error_dlg( 
     365            self.boss.window.error_dlg( 
    366366                'Debug controller is not fully configured.') 
    367367        else: 
    368368            if self.svc._is_running: 
    369                 self.boss.get_window().error_dlg( 
     369                self.boss.window.error_dlg( 
    370370                    'Debugger already running.') 
    371371            else: 
     
    373373                    self.svc.emit('debugger_started') 
    374374                else: 
    375                     self.boss.get_window().error_dlg( 
     375                    self.boss.window.error_dlg( 
    376376                        'Debug session failed to launch.') 
    377377