FAILTASTIC

I use python as a replacement for shell scripting on *nix systems all the time. unfortunately the os.path and shutil modules don't work under Windows (this is with ActivePython which is supposed to be even more Windows friendly than the standard CPython release).

os.path.exists and os.path.isdir can essentially be used as random boolean generators, and shutil.move doesn't actually move anything, it just copies it.

SCREW THAT
Fail indeed.
Do you have any particular reason for not using CPython, though? I've never had problems with it.
Those work perfectly in CPython.

'Tis your choice of Python that is the true failure Razz
Kllrnohj wrote:
Those work perfectly in CPython.

'Tis your choice of Python that is the true failure Razz
I believe it would be Windows that is the true failure here.
KermMartian wrote:
I believe it would be Windows that is the true failure here.


Nah, Windows has its place, and I highly doubt Windows suddenly failed to move and detect files Wink
The Tari wrote:
Fail indeed.
Do you have any particular reason for not using CPython, though? I've never had problems with it.


ActivePython lets me do things like play with the registry, interface COM objects, and use Python scripts as NT services.
Well, I'm guessing the actual problem is your code. I doubt that they actually messed up the moving and file checking routines.

So, code snippet?
that's not a win python, THIS is a win python:

Big image linkthrough (it's a snake):
http://timesnews.typepad.com/photos/uncategorized/python_1.jpg
Kllrnohj wrote:
Well, I'm guessing the actual problem is your code. I doubt that they actually messed up the moving and file checking routines.

So, code snippet?

I found the source of the failness.

what do you think is the output of this code:
os.path.join(*os.getcwd().split("\"))

when your current working directory is "F:\Documents\tbg"

I'll give you a hint. its not "F:\Documents\tbg"

its "F:Documents\tbg"
I didn't even realize that Windows XP allowed you to specify file paths with that syntax, I'm assuming its some sort of foul holdover from DOS? if you don't know what it means, play around on the command line a little and figure it out. Basically if my script had been run from the root of the drive it would have worked fine.


looked like this:

Code:
for oldfile in extras:
   newfile = "tbgbackups".join(oldfile.split("thebuildersgame"))
   #print "O: %s N: %s" % (oldfile,newfile)
   if not(os.path.exists(oldfile)):
      print "wtf: %s is missing" % oldfile
      raw_input()
   #print os.path.exists(newfile)
   dirs = newfile.split("\\")[:-1]
   dirs.reverse()
   curdir = ""
   while dirs:
      #print curdir
      #print dirs
      ndir = dirs.pop()
      #print ndir
      curdir = os.path.abspath(os.path.join(curdir,ndir))
      #print curdir
      #print ""
      print os.path.exists(os.path.abspath(curdir))
      #print os.path.abspath(curdir)
      if not os.path.exists(curdir):
         os.mkdir(curdir)
         #print "blah"
         #print os.path.isdir(curdir)
      #else:
         print "meh"
         print curdir
         #print os.path.isdir(curdir)
      print ""
      try:
         shutil.move(oldfile, newfile)
      except IOError, (errno, strerror):
         print "I/O error(%s): %s" % (errno, strerror)



os.path.exists() would say "OH YES, THAT DIRECTORY EXISTS" (same with os.path.isdir())
but then shutil.move() would say "OH NO IT DOESN'T BETCH, GET BACK IN LINE"

after 30 minutes of various debugging attempts I discovered the problem, and changed it to this:


Code:

for oldfile in extras:
   newfile = "tbgbackups".join(oldfile.split("tbg"))
   #print "O: %s N: %s" % (oldfile,newfile)
   if not(os.path.exists(oldfile)):
      print "wtf: %s is missing" % oldfile
      raw_input()
   #print os.path.exists(newfile)
   dirs = newfile.split("\\")[1:-1]
   dirs.reverse()
   curdir = "F:\\"
   while dirs:
      #print curdir
      #print dirs
      ndir = dirs.pop()
      #print ndir
      curdir = os.path.abspath(os.path.join(curdir,ndir))
      #print curdir
      #print ""
      print os.path.exists(os.path.abspath(curdir))
      #print os.path.abspath(curdir)
      if not os.path.exists(curdir):
         os.mkdir(curdir)
         #print "blah"
         #print os.path.isdir(curdir)
      #else:
         print "meh"
         print curdir
         #print os.path.isdir(curdir)
      print ""
      try:
         shutil.move(oldfile, newfile)
      except IOError, (errno, strerror):
         print "I/O error(%s): %s" % (errno, strerror)





shutil.move() still didn't move the files, it just copied them over, which kind of defeated the purpose of the whole experiment. I ended up writing *another* script to delete any file from the main tbg folder that was also in the backup directory.

[edit]
also, if you don't know who/what ActiveState is or haven't been on the ASPN hasn't spent nearly enough time programming real applications in Python.
http://mail.python.org/pipermail/python-list/2007-July/447987.html
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement