# HG changeset patch
# User William Stein <wstein@gmail.com>
# Date 1208880595 25200
# Node ID 032aefc044d29f168d6dad4d9ace7e8d2f934727
# Parent  13a377fb7ead03a6a0be6a9f7884446889e7fb8e
trac #2997 notebook -- change current directory before running notebook)

diff -r 13a377fb7ead -r 032aefc044d2 sage/server/notebook/notebook_object.py
--- a/sage/server/notebook/notebook_object.py	Tue Apr 22 05:46:59 2008 -0700
+++ b/sage/server/notebook/notebook_object.py	Tue Apr 22 09:09:55 2008 -0700
@@ -139,7 +139,11 @@ class NotebookObject:
     \end{verbatim}
     """
     def __call__(self, *args, **kwds):
-        return self.notebook(*args, **kwds)
+        curdir = os.path.abspath(os.curdir)
+        try:
+            self.notebook(*args, **kwds)
+        finally:
+            os.chdir(curdir)
 
     notebook = run_notebook.notebook_twisted
     setup    = run_notebook.notebook_setup
diff -r 13a377fb7ead -r 032aefc044d2 sage/server/notebook/run_notebook.py
--- a/sage/server/notebook/run_notebook.py	Tue Apr 22 05:46:59 2008 -0700
+++ b/sage/server/notebook/run_notebook.py	Tue Apr 22 09:09:55 2008 -0700
@@ -61,7 +61,9 @@ def notebook_twisted(self,
              start_path = "",
              fork = False,
              quiet = False):
-             
+    """
+    Change the current directory into the notebook file directory and run the notebook server.
+    """
     if directory is None:
         directory = '%s/sage_notebook'%DOT_SAGE
     else:
@@ -232,7 +234,8 @@ s.setServiceParent(application)
         if secure and not quiet:
             print "There is an admin account.  If you do not remember the password,"
             print "quit the notebook and type notebook(reset=True)."
-        cmd = 'sage -twistd --pidfile="%s"/twistd.pd -ny "%s"/twistedconf.tac'%(directory, directory)
+        os.chdir(directory)
+        cmd = 'sage -twistd --pidfile=twistd.pd -ny twistedconf.tac'
         if fork:
             return pexpect.spawn(cmd)
         else:
