Commits

Anonymous committed 8a45737

Calling starting_rope function when starting rope in ~.rope
Calling opening_project function when opening a project in .ropeproject/config.py

Comments (0)

Files changed (6)

docs/dev/issues.txt

 * What to do about `NoProject`
 
 
-``config.py``
--------------
-
-* Push or poll model::
-
-    def opening_project(project):
-        pass
-
-    def closing_project(project):
-        pass
-
-* Changing dot rope?::
-
-    def starting_rope(core):
-        pass
-
-    def closing_rope(core):
-        pass
-
-
 Enhancing `CallInfoManager`
 ===========================
 

docs/dev/workingon.txt

 ``.ropeproject`` Folder
 =======================
 
-- ``Project(ropefolder='.ropeproject')``
-- In ``.rope``: ``core.set('project_rope_folder', '.ropefolder')``
-- `Project.ropefolder` property
-- How to specify ignored resources; `Project.set_ignored_patterns`
-- Ignored folders and children
-- Add `FSCommandsTest` for testing ignores and VCSs
-
-Next:
-
-* Adding ``.ropeproject/config.py`` and its default
-* Executing the `opening_project(project)` function
-* Changing `.rope` to use `starting_rope(core)`
+- Adding ``.ropeproject/config.py`` and its default
+- The default ``config.py``
+- Executing the `opening_project(project)` function
+- Changing `.rope` to use `starting_rope(core)`
 
 * What happens when `NoProject` saves call information
 * Adding method to static method refactoring

rope/base/project.py

         super(Project, self).__init__(fscommands)
         self.ignored_patterns = []
         self.set_ignored_resources(['*.pyc', '.svn', '*~', '.ropeproject'])
-        self._ropefolder = self._create_rope_folder(ropefolder)
+        self._ropefolder = self._init_rope_folder(ropefolder)
 
     def get_files(self):
         return self._get_files_recursively(self.root)
                 result.extend(self._get_files_recursively(folder))
         return result
 
-    def _create_rope_folder(self, ropefolder):
+    def _init_rope_folder(self, ropefolder):
         if ropefolder is not None:
             result = self.get_folder(ropefolder)
             if not result.exists():
                 result.create()
+            if result.has_child('config.py'):
+                config = result.get_child('config.py')
+            else:
+                config = result.create_file('config.py')
+                config.write(
+                    '# The default ``config.py``\n\n\n'
+                    'def opening_project(project):\n'
+                    '    """This function is called when this project is opened"""\n'
+                    '    #project.set_ignored_resources'
+                    "(['*.pyc', '.svn', '*~', '.ropeproject'])\n")
+            run_globals = {}
+            run_globals.update({'__name__': '__main__',
+                                '__builtins__': __builtins__,
+                                '__file__': config.real_path})
+            execfile(config.real_path, run_globals)
+            if 'opening_project' in run_globals:
+                run_globals['opening_project'](self)
             return result
 
     def set_ignored_resources(self, patterns):
 import os
+import imp
 
 import tkFileDialog
 from Tkinter import *
                                 '__builtins__': __builtins__,
                                 '__file__': dot_rope})
             execfile(dot_rope, run_globals)
+            if 'starting_rope' in run_globals:
+                run_globals['starting_rope'](self)
         except IOError, e:
             print 'Unable to load <~.rope> file: ' + e
 

rope/ui/dot_rope.py

 # Note: Since this file is not inside a project you cannot perform
 #   refactorings on it.
 #
-import rope.ui.core
 
 
-core = rope.ui.core.get_core()
+def starting_rope(core):
+    """Change rope preferences.
 
-# Changing editor font
-#core.set('font', ('Courier', 14))
+    This function is called when rope starts.
 
+    """
 
-# Hiding menu bar
-#core.set('show_menu_bar', False)
+    # Changing editor font
+    #core.set('font', ('Courier', 14))
 
-# Hiding buffer list
-#core.set('show_buffer_list', False)
+    # Hiding menu bar
+    #core.set('show_menu_bar', False)
 
-# Hiding status bar
-#core.set('show_status_bar', False)
+    # Hiding buffer list
+    #core.set('show_buffer_list', False)
 
+    # Hiding status bar
+    #core.set('show_status_bar', False)
 
-# If you don't like emacs keybindings, change this to False
-i_like_emacs = True
-if not i_like_emacs:
+
+    # If you don't like emacs keybindings, change this to False
+    i_like_emacs = True
+    if not i_like_emacs:
+        _change_key_binding(core)
+
+
+    # Add your python templates
+    core.add('templates', ('say_hello', "print 'Hello, my name is ${name}'\n"))
+    core.add('templates', ('set_field', "self.${field}${cursor} = ${field}\n"))
+
+
+    # The folder relative to project root that holds config files and
+    # information about the project.  If this folder does not exist it is
+    # created.  Specifying `None` means do not make and use a rope folder.
+    #core.set('project_rope_folder', '.ropeproject')
+
+
+    # Adding your own `Action`\s:
+    # If you're interested in adding your own actions to rope you can do so
+    # like this.
+    # Plugins can use this interface for registering their actions.  For
+    # more information see `rope.ui.extension` module.
+    from rope.ui.extension import SimpleAction
+
+    def say_hello(context):
+        print 'Hello Action!'
+
+    hello_action = SimpleAction('hello_action', say_hello, 'C-h h')
+    core.register_action(hello_action)
+
+
+def _change_key_binding(core):
     core.rebind_action('open_project', 'C-P')
     core.rebind_action('close_project', None)
     core.rebind_action('create_file', None)
     core.rebind_action('contributing', None)
     core.rebind_action('library', None)
     core.rebind_action('about', None)
-
-
-# Add your python templates
-core.add('templates', ('say_hello', "print 'Hello, my name is ${name}'\n"))
-core.add('templates', ('set_field', "self.${field}${cursor} = ${field}\n"))
-
-
-# The folder relative to project root that holds config files and
-# information about the project.  If this folder does not exist it is
-# created.  Specifying `None` means do not make and use a rope folder.
-#core.set('project_rope_folder', '.ropeproject')
-
-
-# Adding your own `Action`\s:
-# If you're interested in adding your own actions to rope you can do so
-# like this.
-# Plugins can use this interface for registering their actions.  For
-# more information see `rope.ui.extension` module.
-
-from rope.ui.extension import SimpleAction
-
-def say_hello(context):
-    print 'Hello Action!'
-
-hello_action = SimpleAction('hello_action', say_hello, 'C-h h')
-core.register_action(hello_action)

ropetest/projecttest.py

         myfile.create()
         self.assertEquals('', fscommands.log)
 
+    def test_loading_config_dot_py(self):
+        project = Project(self.project_root, ropefolder='.ropeproject')
+        config = project.get_file('.ropeproject/config.py')
+        if not config.exists():
+            config.create()
+        config.write('def opening_project(project):\n'
+                     '    project.root.create_file("loaded")\n')
+        project = Project(self.project_root, ropefolder='.ropeproject')
+        self.assertTrue(project.get_file('loaded').exists())
+
 
 def suite():
     result = unittest.TestSuite()