Re: weird problem with os.chmod
On Fri, 11 Nov 2005 16:49:23 -0800, James Colannino wrote: > Ok, so now I have a very interesting problem, this time related to > os.chmod. I have the following in a text file: 0600. My script reads > that number as a string and converts it to an integer for use with > chmod. However, when I do this, instead of the rw-- permissions 0600 is the octal representation of 384. "man chmod" should help you. Just use perm = int(string, 8) instead of perm = int(string) when converting to int the string you read from the file. -- Saluti, Mardy http://interlingua.altervista.org -- http://mail.python.org/mailman/listinfo/python-list
Advice on distutils and distribution policies
Hi, I've built a small project (http://eligante.sf.net) which I'm actually trying to package using distutils. The directory structure is going to be like this: eligante/ eligante.py sitobase.py personas.py [...other python files...] modulos/ mbox.py gaim.py [...other python files...] web/ indice.py cerca.py [...other python files...] stylo.css testata.html [and maybe, in the future, other HTML files] The python files in the eligante/web directory are intended to be called by a webserver (now Apache, but soon I'll switch to the python module CGIHTTPServer for simplicity) as CGIs. Currently, these CGIs read the testata.html file and use it as the beginning of their output, while the style.css is served by the HTTP server. However, I don't know if this directory layout is suitable for site-packages, since at a first glance it looks to me that datafiles might not be welcome under it. Is it so? In that case, where should I move the .html files, and how should I access them from inside python? If, on the other hand, this layout is OK for site-packages, how do I instruct distutils to put the .html and .css files under the eligante/web directory? Sorry for the long post, and thanks in advance for any help or suggestion. -- Saluti, Mardy http://interlingua.altervista.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Advice on distutils and distribution policies
Hi Magnus, thanks a lot for your posting, you made me clear several things. However, there something I still want to discuss: Le die Mon, 21 Nov 2005 20:08:24 +0100, Magnus Lycka ha scribite: [...] > In an apache cgi-bin directory: The main Python CGI script(s) that are > called by the web server. These might be scripts that are modified as a > part of the installation process to e.g. point out data files. These > should be short files. Import a module, set up configuration and run > something in the imported module. Good point! > Under /usr/lib/python2.x/site-packages/ you keep the bulk of your > software (as described above). > > HTML and CSS files that are to be handled directly by the web browser is > placed under Apache's DOCUMENT_ROOT etc. E.g. $DOCUMENT_ROOT/eligante. Actually, for the moment, this is just the CSS file. > Data files that are read and processed by you own programs (i.e. not > directly by the web server) van be anywhere under /var, e.g. > /var/eligante. And this is the HTML one (which is a template that is used by the python scripts). The number of HTML might even grow in the future, but it's extremely unlikely they'll be ever more than 5. I'm even thinking of including the HTML in a python file, that will save me the trouble of storing it elsewhere. The other files accessed by the webserver will be the CSS and eventually some images (and the favicon). For these I'll follow your advice of storing them under DOCUMENT_ROOT. This variable, though, seems to be defined only in the processes spawned by the webserver; so my guess is that I'll have to instruct the setup.py script to ask the user where his webserver's document root is (either interactively, or from the command line when invoking the setup script). I guess this involves subclassing some Distutils class, does anyone have a starter for this? Thanks again for your help, Alberto -- Saluti, Mardy http://interlingua.altervista.org -- http://mail.python.org/mailman/listinfo/python-list
Re: the name of a module in which an instance is created?
Hi Steven, Le die Mon, 21 Nov 2005 11:37:37 -0700, Steven Bethard ha scribite: [...] > In the basic situation, where the instance is created in the same module > as the class, I can figure out 'mod' and 'name' like:: > > cls = type(self) > name = cls.__module__ > mod = __import__(cls.__module__) I'm not sure I got your problem correctly, however see if this helps: $ cat > test.py class myclass: name = __module__ ^D $ python Python 2.3.5 (#2, Jun 19 2005, 13:28:00) [GCC 3.3.6 (Debian 1:3.3.6-6)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import test >>> a = test.myclass() >>> a.name 'test' This works, as we define "name" to be a class attribute. Is this useful to you? -- Saluti, Mardy http://interlingua.altervista.org -- http://mail.python.org/mailman/listinfo/python-list
Getting standard config directory
Hi, I'm looking for a standard way to determine where to store a configuration file for my app, using distutils. At the moment, I'm using os.geteuid() == 0 to decide whether the configuration file should be written in /etc/myapp.cfg or in $HOME/.myapp.cfg (if the user running the setup.py is root, I suppose it's doing a global installation). But I don't know how this will work in Windows. Is there some way to obtain the standard path for config files (maybe from inside distutils)? -- Saluti, Mardy http://interlingua.altervista.org -- http://mail.python.org/mailman/listinfo/python-list
Help me to catch this exception :-)
Hi all, I have written a slightly modified version of the CGIHTTPServer; the difference with the module included in the standard python distrubution is that, since I know that the CGI to be executed is a python script, I always execute it via the execfile() function, instead of opening a separate process. But there's a problem: in the CGI, I'm using the cgitb module to catch exceptions and send them to the browser. This doesn't work. Here is what happens when a exception is raised from the CGI: 1) the client (HTTP browser) waits for data, which don't came (while I'd like the cgitb module to display the exception); 2) the exception is propagated to the CGIHTTPServer, which shows it on the standard error (where noone will ever see it); 3) when I interrupt the HTTP server with Ctrl+C, the KeyboardInterrupt exception is sent (beautified by cgitb) to the HTTP browser!!! I can correct (3) by saving the value of sys.excepthook before the call to execfile and restoring it in the finally clause, but this doesn't solve my problem. Is there a way to run a python file as if it were a separate process? That is, forbidding execfile() to modify anything in the caller? -- Saluti, Mardy http://interlingua.altervista.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me to catch this exception :-)
Le die Thu, 24 Nov 2005 07:09:26 -0800, Fuzzyman ha scribite: > I don't know the answer, but I like the problem. :-) > > What happens with the standard CGIHttpServer ? The standard CGIHttpServer uses fork() on Unix and popen() on Windows; since both these functions run the module in a separate process, the problem doesn't show up. But on Mac, it uses execfile(), so I guess the problem is the same. For the moment, I've come up with a hybrid solution: in CGIHTTPServer, doing "import cgitb; cgitb.enable()" before the try block which calls execfile(), and add an empty except clause which prints the exception: except: cgitb.handler() There's still something not working perfectly, but I think this is close to the solution. -- Saluti, Mardy http://interlingua.altervista.org -- http://mail.python.org/mailman/listinfo/python-list
Distutils postinstall script: useless?
Hi, the bdist_wininst command of distutils allows me to specify a script to be executed at the end of the installation. That's great, but how can I know the installation path from inside the script? I've already tried os.getcwd(), but it just return the directory where the setup was started. -- Saluti, Mardy http://interlingua.altervista.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Distutils postinstall script: useless?
Le die Wed, 30 Nov 2005 15:46:43 +, Mardy ha scribite: > the bdist_wininst command of distutils allows me to specify a script to > be executed at the end of the installation. That's great, but how can I > know the installation path from inside the script? Answering to myself, sys.prefix combined with the dictionary INSTALL_SCHEMES from distutils.commands.install might do the work. -- Saluti, Mardy http://interlingua.altervista.org -- http://mail.python.org/mailman/listinfo/python-list
Need help on designing a project
Hi all, I'm starting to think the way I've implemented my program (http://www.mardy.it/eligante) is all wrong. Basically, what I want is a web application, which might run as CGI scripts in apache (and this is working) or even as a standalone application, in which case it would use it's own internal webserver. The question is about this homemade webserver: right now it's a slightly modified version of the standard CGIHTTPServer module. Since I know all my CGIs are python scripts, I thought that performance would be best if they are executed with the execfile command, in the same process as the webserver. This works, but my problem is that SQL connections (MySQL or sqlite) don't get closed when the script execution finishes, and at the next execution of a CGI they may lock the database (this is especially true with sqlite, but even mysql on Windows gave me these problems). I tryed to call atexit.register() from inside the CGI script (in order to close the connection) but my atexit function get called only when the webserver itself exits. So, I'd like to know if there is a quick solution, or if I have to rewrite the whole mechanism (maybe using some existing framework? which one?). What I care most, is the ease of installation and use of my program (and portability). That's why I'm not contented with apache. -- Saluti, Mardy http://interlingua.altervista.org -- http://mail.python.org/mailman/listinfo/python-list
Re: CGI module does not parse data
Le die Thu, 01 Dec 2005 15:08:14 -0800, amfr ha scribite: > I have included some of the content of that file, I am writing this as > an extension to my ebserver which is based on BaseHTTPServer. This > part of the code was taken directly from the CGIHTTPServer file, > nothing changed I did the same, it is working for me. About Mac problems, the only thing I know is that in the code of CGIHTTPServer itself a comment says that execfile() is the only way to run a CGI on Mac. But it should work. Maybe it's just your browser, which doesn't show you the output of the CGI. Did you try connecting to the webserver by telnet? -- Saluti, Mardy http://interlingua.altervista.org -- http://mail.python.org/mailman/listinfo/python-list
Re: CGI and long running job
Le die Fri, 02 Dec 2005 20:35:52 -0800, merry.sailor ha scribite: > For step 3 I use either os.system or os.popen(2). The problem is that > the web server does not send the information of step 2 back to the > browser, unless step 3 is completed. The browser simply waits for a > response, without displaying anything. How can I just read the params, > display the info I want, start the simulation and then terminate either > the script or at least the connection to the browser without having to > wait for the simulation to finish? Sounds weird. What if you connect to the webserver via telnet? Do you get any output? you could try to call sys.stdout.flush() in the CGI, but I never had the need to do that. Maybe it's just a browser's problem? -- Saluti, Mardy http://interlingua.altervista.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help on designing a project
Le die Fri, 02 Dec 2005 11:34:45 +, Steve Holden ha scribite: > Note that if you are using execfile()then the best structure for your > scripts would be something like: > > conn = db.open() > try: > #do CGI stuff > finally: > conn.close() That was of great help! Thanks! -- Saluti, Mardy http://interlingua.altervista.org -- http://mail.python.org/mailman/listinfo/python-list
Re: CGI module does not parse data
Le die Fri, 02 Dec 2005 12:18:28 -0800, amfr ha scribite: > import cgi > form = cgi.FieldStorage() > print form["test"] > print "test" > > I would only be able to see "test", not "hello world" > I am sure its not my browser As Tim said, you have tu use "form['test'].value", because "print form['test']" will make pythoun output something like this: and your browser won't show it, mistaking it as an HTML tag. -- Saluti, Mardy http://interlingua.altervista.org -- http://mail.python.org/mailman/listinfo/python-list