durusmail: durus-users: Patch: add a startup file to 'durus -c'
Patch: add a startup file to 'durus -c'
2005-01-06
2005-01-07
2005-01-07
Patch: add a startup file to 'durus -c'
David Binger
2005-01-07
On Jan 6, 2005, at 2:34 PM, A.M. Kuchling wrote:

> Here's a small patch that causes 'durus -c' to find and execute the
> file named by the DURUSSTARTUP env. var (by analogy with
> PYTHONSTARTUP).  Possibly the filename should be run through
> os.path.expanduser() before opening it.
>
> It would be nice to have a way to add text to the help banner, but I
> don't see a tidy way to do that with modifying Python's code.py, so
> never mind.

Here's a different implementation, with the help banner.

--- client.py   (revision 25822)
+++ client.py   (working copy)
@@ -26,7 +26,8 @@
      except ImportError:
          pass

-def interactive_client(file, host, port, cache_size, readonly, repair):
+def interactive_client(file, host, port, cache_size, readonly, repair,
+                       startup):
      if file:
          storage = FileStorage(file, readonly=readonly, repair=repair)
          description = file
@@ -45,6 +46,8 @@
                   'pp': pprint}
      configure_readline(namespace,
os.path.expanduser("~/.durushistory"))
      console = InteractiveConsole(namespace)
+    if startup:
+        console.runsource('execfile("%s")' %
os.path.expanduser(startup))
      help = ('    connection -> the connection\n'
              '    root       -> get(0)\n'
              '    get(oid)   -> get an object\n'
@@ -78,9 +81,16 @@
      parser.add_option(
          '--readonly', dest='readonly', action='store_true',
          help='Open the file in read-only mode.')
+    parser.add_option(
+        '--startup', dest='startup',
+        default=os.environ.get('DURUSSTARTUP', ''),
+        help=('Full path to a python startup file to execute on
startup.'
+              '(default=DURUSSTARTUP from environment, if set)')
+        )
      (options, args) = parser.parse_args()
      interactive_client(options.file, options.host, options.port,
-                       options.cache_size, options.readonly,
options.repair)
+                       options.cache_size, options.readonly,
options.repair,
+                       options.startup)


reply