Ticket #19567: changeset_r24034.diff

File changeset_r24034.diff, 7.0 KB (added by jjstickel@…, 15 years ago)

patch for enthoughtbase

  • EnthoughtBase/trunk/enthought/etsconfig/etsconfig.py

     
    4949    #### properties ###########################################################
    5050
     51    def get_application_data(self, create=False):
     52        """ Return the application data directory path.
     53       
     54            **Parameters**
     55
     56            create: create the corresponding directory or not
     57
     58            **Notes**
     59
     60            This is a directory that applications and packages can safely
     61            write non-user accessible data to i.e. configuration
     62            information, preferences etc.
     63
     64            Do not put anything in here that the user might want to navigate to
     65            e.g. projects, user data files etc.
     66
     67            The actual location differs between operating systems.
     68       """
     69        if self._application_data is None:
     70            self._application_data = \
     71                    self._initialize_application_data(create=create)
     72
     73        return self._application_data
     74       
     75
    5176    def _get_application_data(self):
    52         """
    53         Property getter.
    54 
    55         This is a directory that applications and packages can safely write
    56         non-user accessible data to i.e. configuration information, preferences
    57         etc.
    58 
    59         Do not put anything in here that the user might want to navigate to
    60         e.g. projects, user data files etc.
    61 
    62         The actual location differs between operating systems.
    63 
    64         """
    65 
    66         if self._application_data is None:
    67             self._application_data = self._initialize_application_data()
    68 
    69         return self._application_data
     77        """ Property getter, see get_application_data's docstring.
     78        """
     79        return self.get_application_data(create=True)
    7080
    7181
     
    8090        return
    8191
    82 
     92    def get_application_home(self, create=False):
     93        """ Return the application home directory path.
     94       
     95            **Parameters**
     96
     97            create: create the corresponding directory or not
     98
     99            **Notes**
     100
     101            This is a directory named after the current, running
     102            application that imported this module that applications and
     103            packages can safely write non-user accessible data to i.e.
     104            configuration information, preferences etc.  It is a
     105            sub-directory of self.application_data, named after the
     106            directory that contains the "main" python script that started
     107            the process.  For example, if application foo is started with
     108            a script named "run.py" in a directory named "foo", then the
     109            application home would be: <ETSConfig.application_data>/foo,
     110            regardless of if it was launched with "python
     111            <path_to_foo>/run.py" or "cd <path_to_foo>; python run.py"
     112
     113            This is useful for library modules used in apps that need to
     114            store state, preferences, etc. for the specific app only, and
     115            not for all apps which use that library module.  If the
     116            library module uses ETSConfig.application_home, they can
     117            store prefs for the app all in one place and do not need to
     118            know the details of where each app might reside.
     119
     120            Do not put anything in here that the user might want to
     121            navigate to e.g. projects, user home files etc.
     122
     123            The actual location differs between operating systems.
     124
     125       """
     126        if self._application_home is None:
     127            self._application_home = path.join(
     128                                self.get_application_data(create=create),
     129                                self._get_application_dirname())
     130
     131        return self._application_home
     132
     133
     134 
    83135    application_data = property(_get_application_data, _set_application_data)
    84136
    85137
    86138    def _get_application_home(self):
    87         """
    88         Property getter.
    89 
    90         This is a directory named after the current, running application that
    91         imported this module that applications and packages can safely write
    92         non-user accessible data to i.e. configuration information, preferences
    93         etc.  It is a sub-directory of self.application_data, named after the
    94         directory that contains the "main" python script that started the
    95         process.  For example, if application foo is started with a script named
    96         "run.py" in a directory named "foo", then the application home would be:
    97         <ETSConfig.application_data>/foo, regardless of if it was launched
    98         with "python <path_to_foo>/run.py" or "cd <path_to_foo>; python run.py"
    99 
    100         This is useful for library modules used in apps that need to store
    101         state, preferences, etc. for the specific app only, and not for all apps
    102         which use that library module.  If the library module uses
    103         ETSConfig.application_home, they can store prefs for the app all in
    104         one place and do not need to know the details of where each app might
    105         reside.
    106 
    107         Do not put anything in here that the user might want to navigate to
    108         e.g. projects, user home files etc.
    109 
    110         The actual location differs between operating systems.
    111 
    112         """
    113 
    114         if self._application_home is None:
    115             self._application_home = path.join(self.application_data,
    116                                                self._get_application_dirname())
    117 
    118         return self._application_home
     139        """ Property getter, see get_application_home's docstring.
     140        """
     141        return self.get_application_home(create=True)
    119142
    120143
     
    294317
    295318
    296     def _initialize_application_data(self):
     319    def _initialize_application_data(self, create=True):
    297320        """
    298321        Initializes the (default) application data directory.
     
    322345        application_data = os.path.join(parent_directory, directory_name)
    323346
    324         # If a file already exists with this name then make sure that it is
    325         # a directory!
    326         if os.path.exists(application_data):
    327             if not os.path.isdir(application_data):
    328                 raise ValueError('File "%s" already exists' % application_data)
    329 
    330         # Otherwise, create the directory.
    331         else:
    332             os.makedirs(application_data)
     347        if create:
     348            # If a file already exists with this name then make sure that it is
     349            # a directory!
     350            if os.path.exists(application_data):
     351                if not os.path.isdir(application_data):
     352                    raise ValueError('File "%s" already exists'
     353                                                    % application_data)
     354
     355            # Otherwise, create the directory.
     356            else:
     357                os.makedirs(application_data)
    333358
    334359        return application_data