Access class from staticmethod

2010-04-30 Thread Thomas Allen
Is that possible?

class A(object):
  @staticmethod
  def set_b(x):
# A.b = x, without knowing A is A
pass

Thomas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Access class from staticmethod

2010-04-30 Thread Thomas Allen
Ah ha, @classmethod.

On Apr 30, 3:47 pm, Thomas Allen thomasmal...@gmail.com wrote:
 Is that possible?

 class A(object):
   @staticmethod
   def set_b(x):
     # A.b = x, without knowing A is A
     pass

 Thomas

-- 
http://mail.python.org/mailman/listinfo/python-list


SimpleXMLRPCServer daemon

2010-01-29 Thread Thomas Allen
I have a script that runs an instance of SimpleXMLRPCServer and in
general it works as expected. In its __del__, it is supposed to clean
up its PID file (written on boot). I have two problems with this
server instance: The first is that tt doesn't always clean up its PID
file; is there a more reliable way to do this than how I am currently?
The second is that when it does crash, I don't know about it...what
would be sufficient as a keep-alive script to restart it? I suppose
I could use something like EventMachine (already installed on my
server) to watch the PID file if it were deleted reliably.

Thomas Allen
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python simple web development

2009-06-26 Thread Thomas Allen
On Jun 25, 3:29 am, Private Private mail...@gmail.com wrote:
 Hi,

 I am looking for a python library which will allow me to do a simple
 web development. I need to use
 some forms (but nice looking :-) ), creating images based on input
 from those forms, etc. I have read a bit about Django and TurboGears
 but I am afraid that this is too big for my requirements (am I
 wrong ?).

 Can you suggest anything ?

I don't think anything's lighter than web.py.

http://webpy.org/

Thomas
-- 
http://mail.python.org/mailman/listinfo/python-list


FTP libs for Python?

2009-02-20 Thread Thomas Allen
I'm interested in writing a script to ease deployment of minor changes
on some websites here, and it would involve some SFTP transfers. Do
you know of good alternatives to ftplib, which is relatively low-
level?

Thomas
--
http://mail.python.org/mailman/listinfo/python-list


Re: FTP libs for Python?

2009-02-20 Thread Thomas Allen
On Feb 20, 9:45 am, coldpizza vri...@gmail.com wrote:
 Why don't you just use Curl? It does a dozen of protocols including
 SFTP. And if the command line version is not enough for you then there
 are Python bindings for Curl.

I'm actually hoping to eventually package these tools using py2exe for
some co-workers, which is why I'm not looking to Unix utilities

On Feb 20, 9:48 am, Mike Kent mrmak...@cox.net wrote:
 I use Fabric (http://www.nongnu.org/fab/) as my Python-based
 deployment tool, but it uses ssh/scp, not sftp.

I'm looking at Paramiko right now which I saw some people
recommending, as SSH utils are required as well

Thomas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Maximum recursion depth exceeded...why?

2009-02-19 Thread Thomas Allen
On Feb 18, 10:15 pm, rdmur...@bitdance.com wrote:
 Thomas Allen thomasmal...@gmail.com wrote:
  On Feb 18, 4:51 am, alex23 wuwe...@gmail.com wrote:
   On Feb 18, 7:34 pm, rdmur...@bitdance.com wrote:

Yeah, but wget -r -k will do that bit of it, too.

   Wow, nice, I don't know why I never noticed that. Cheers!

  Hm...doesn't do that over here. I thought it may have been because of
  absolute links (not to site root), but it even leaves things like a
  href=/. Does it work for you guys?

 It works for me.  The sample pages I just tested on it don't use
 any href=/ links, but my 'href=/about.html' got properly
 converted to 'href=../about.html'.  (On the other hand my '/contact.html'
 got converted to a full external URL...but that's apparently because the
 contact.html file doesn't actually exist :)

 --RDM

Thanks for the help everyone. The idea of counting the slashes was the
linchpin of this little script, and with a little trial and error, I
successfully generated a local copy of the site. I don't think my
colleague knows what went into this, but he seemed appreciative :^)

Thomas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Maximum recursion depth exceeded...why?

2009-02-18 Thread Thomas Allen
On Feb 18, 4:51 am, alex23 wuwe...@gmail.com wrote:
 On Feb 18, 7:34 pm, rdmur...@bitdance.com wrote:

  Yeah, but wget -r -k will do that bit of it, too.

 Wow, nice, I don't know why I never noticed that. Cheers!

Hm...doesn't do that over here. I thought it may have been because of
absolute links (not to site root), but it even leaves things like a
href=/. Does it work for you guys?
--
http://mail.python.org/mailman/listinfo/python-list


Maximum recursion depth exceeded...why?

2009-02-17 Thread Thomas Allen
I must not be understanding something. This is a simple recursive
function that prints all HTML files in argv[1] as its scans the
directory's contents. Why do I get a RuntimeError for recursion depth
exceeded?

#!/usr/bin/env python

import os, sys

def main():
absToRel(sys.argv[1], sys.argv[2])

def absToRel(dir, root):
for filename in os.listdir(dir):
if os.path.isdir(filename):
absToRel(filename, root)
else:
if(filename.endswith(html) or filename.endswith(htm)):
print filename

if __name__ == __main__:
main()
--
http://mail.python.org/mailman/listinfo/python-list


Re: Maximum recursion depth exceeded...why?

2009-02-17 Thread Thomas Allen
On Feb 17, 4:46 pm, Thomas Allen thomasmal...@gmail.com wrote:
 I must not be understanding something. This is a simple recursive
 function that prints all HTML files in argv[1] as its scans the
 directory's contents. Why do I get a RuntimeError for recursion depth
 exceeded?

 #!/usr/bin/env python

 import os, sys

 def main():
     absToRel(sys.argv[1], sys.argv[2])

 def absToRel(dir, root):
     for filename in os.listdir(dir):
         if os.path.isdir(filename):
             absToRel(filename, root)
         else:
             if(filename.endswith(html) or filename.endswith(htm)):
                 print filename

 if __name__ == __main__:
     main()

Please note that I'm not using os.walk(sys.argv[1]) because the
current depth of recursion is relevant to the transformation I'm
attempting. Basically, I'm transforming a live site to a local one and
the live site uses all absolute paths (not my decision...). I planned
on performing the replace like so for each line:

line.replace(root, ../ * depth)

So that a file in the top-level would simple remove all instances of
root, one level down would sub ../, etc.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Maximum recursion depth exceeded...why?

2009-02-17 Thread Thomas Allen
On Feb 17, 5:31 pm, Peter Otten __pete...@web.de wrote:
 Thomas Allen wrote:
  I must not be understanding something. This is a simple recursive
  function that prints all HTML files in argv[1] as its scans the
  directory's contents. Why do I get a RuntimeError for recursion depth
  exceeded?

  #!/usr/bin/env python

  import os, sys

  def main():
      absToRel(sys.argv[1], sys.argv[2])

  def absToRel(dir, root):
      for filename in os.listdir(dir):

           filename = os.path.join(dir, filename)

          if os.path.isdir(filename):
              absToRel(filename, root)
          else:
              if(filename.endswith(html) or filename.endswith(htm)):
                  print filename

  if __name__ == __main__:
      main()

 Without the addition for a directory and a subdirectory of the same
 name, dir/dir, os.listdir(dir) has dir (the child) in the result list
 which triggers an absToRel() call on dir (the parent) ad infinitum.

 Peter

I have two problems in this case:

1. I don't know how to reliably map the current filename to an
absolute path beyond the top-most directory because my method of doing
so would be to os.path.join(os.getcwd(), filename)

2. For some reason, only one folder in the directory gets marked as a
directory itself when there are about nine others in the top-most
directory. I don't even know where to begin to solve this one.

I'm sure the first is an easy answer, but what do I need to do to
solve the second?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Maximum recursion depth exceeded...why?

2009-02-17 Thread Thomas Allen
On Feb 17, 6:05 pm, Peter Otten __pete...@web.de wrote:
 Thomas Allen wrote:
  On Feb 17, 5:31 pm, Peter Otten __pete...@web.de wrote:
  Thomas Allen wrote:
   I must not be understanding something. This is a simple recursive
   function that prints all HTML files in argv[1] as its scans the
   directory's contents. Why do I get a RuntimeError for recursion depth
   exceeded?

   #!/usr/bin/env python

   import os, sys

   def main():
   absToRel(sys.argv[1], sys.argv[2])

   def absToRel(dir, root):
   for filename in os.listdir(dir):

  filename = os.path.join(dir, filename)

   if os.path.isdir(filename):
   absToRel(filename, root)
   else:
   if(filename.endswith(html) or filename.endswith(htm)):
   print filename

   if __name__ == __main__:
   main()

  Without the addition for a directory and a subdirectory of the same
  name, dir/dir, os.listdir(dir) has dir (the child) in the result
  list which triggers an absToRel() call on dir (the parent) ad
  infinitum.

  Peter

  I have two problems in this case:

  1. I don't know how to reliably map the current filename to an
  absolute path beyond the top-most directory because my method of doing
  so would be to os.path.join(os.getcwd(), filename)

 Don't make things more complicated than necessary. If you can do
 os.listdir(somedir) you can also do [os.path.join(somedir, fn) for fn in
 os.listdir(somedir)].

  2. For some reason, only one folder in the directory gets marked as a
  directory itself when there are about nine others in the top-most
  directory. I don't even know where to begin to solve this one.

  I'm sure the first is an easy answer, but what do I need to do to
  solve the second?

 If you solve the first properly the second might magically disappear. This
 is what my crystal ball tells me because there is no code in sight...

 Peter

I'm referring to the same code, but with a print:

for file in os.listdir(dir):
if os.path.isdir(file):
print D, file

in place of the internal call to absToRel...and only one line prints
such a message. I mean, if I can't trust my OS or its Python
implementation (on a Windows box) to recognize a directory, I'm
wasting everyone's time here.

In any case, is this the best way to go about the problem in general?
Or is there already a way to recursively walk a directory, aware of
the current depth?

Thanks,
Thomas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Maximum recursion depth exceeded...why?

2009-02-17 Thread Thomas Allen
On Feb 17, 7:05 pm, Christian Heimes li...@cheimes.de wrote:
 Thomas Allen wrote:
  I'm referring to the same code, but with a print:

  for file in os.listdir(dir):
      if os.path.isdir(file):
          print D, file

  in place of the internal call to absToRel...and only one line prints
  such a message. I mean, if I can't trust my OS or its Python
  implementation (on a Windows box) to recognize a directory, I'm
  wasting everyone's time here.

 You are under a wrong assumption. You think os.listdir() returns a list
 of absolute path elements. In fact it returns just a list of names. You
 have to os.path.join(dir, file) to get an absolute path.

 Anyway stop reinventing the wheel and use os.walk() as I already
 explained. You can easily spot the depth with directory.count(os.sep).
  os.path.normpath() helps you to sanitize the path before counting the
 number of os.sep.

 Christian

If you'd read the messages in this thread you'd understand why I'm not
using os.walk(): I'm not using it because I need my code to be aware
of the current recursion depth so that the correct number of ../ are
substituted in.

Also, somebody mentioned wget -R...did you mean wget -r? In any case,
I have all of these files locally already and am trying to replace
absolute paths with relative ones so that a colleague can present some
website content at a location with no internet.

Thomas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Maximum recursion depth exceeded...why?

2009-02-17 Thread Thomas Allen
On Feb 17, 9:08 pm, Christian Heimes li...@cheimes.de wrote:
 Thomas Allen wrote:
  If you'd read the messages in this thread you'd understand why I'm not
  using os.walk(): I'm not using it because I need my code to be aware
  of the current recursion depth so that the correct number of ../ are
  substituted in.

 I'm well aware of your messages and your requirements. However you
 didn't either read or understand what I was trying to tell you. You
 don't need to know the recursion depths in order to find the correct
 number of ../.

 base = os.path.normpath(base)
 baselevel = root.count(os.sep)

 for root, dirs, files in os.walk(base):
     level = root.count(os.sep) - baselevel
     offset = level * ../
     ...

 See?

 Christian

Very clever (and now seemingly obvious)! That certainly is one way to
measure directory depth; I hadn't thought of counting the separator.
Sorry that I misunderstood what you meant there.

Thanks,
Thomas
--
http://mail.python.org/mailman/listinfo/python-list