Allright I tried a couple of things with your suggested appraoch:

- I printed all the strings used to define paths and files, this all
seems correct.

- The os.mkdir() command is passed without raising an error, but
without creating the directory either, this results in an "IOError: No
such file or directory" because of course a file can't be created in a
non-existing directory.

- I tried creating files in different already existing directories and
this works as expected.

- I tried to use os.makedirs() instead of os.mkdir(), this raises an
interesting error: "mkdir() takes exactly 1 argument (2 given)", I
tried calling the script outside of Django and this should work the
way I'm using it:

        kmlpath = "%s/%s" % (basepath, game_id)
        if not os.path.isdir(kmlpath):
            os.makedirs(kmlpath)

- I tried creating a file without any directory structure in the path,
the file is created in the root of the website, if I try creating a
directory with os.mkdir() it should take the root as well I presume,
but no directory is created.

It seems that Django 1.2.1 has problems calling the os.mkdir() and
makedirs() commands ?

Mark

On 16 aug, 08:32, Mike Dewhirst <mi...@dewhirst.com.au> wrote:
> On 16/08/2010 12:57pm, Mike Dewhirst wrote:
>
>
>
>
>
> > On 16/08/2010 1:06am, Mark Mooij wrote:
> >> Hi Mike,
>
> >> Thanks for your reply. I haven't changed anything else, I am
> >> processing the MS updates, but I don't think this is the problem, as
> >> this all worked fine before the migration to 1.2.1, also if I call the
> >> script directly (outside Django) it works fine.
> >> My view looks like this:
> >> ..
> >> import createKML
> >> ..
> >> def my_view(request, arg):
> >> ...
> >> createKML.createKML(arg)
>
> > I don't really know what is happening here that might have changed in
> > 1.2.1 maybe someone else can suggest something.
>
> > In the meantime here is suggested approach to discovering the exact
> > problem ...
>
> > import os
> > ...
> > def createKML(id, basepath="D:/path/to/mysite/templates/maps"):
> > ...
> > try:
> > if id:
> > kmlpath = "%s/%s" % (basepath, str(id))
>
> actually .. kmlpath = "%s/%s" % (basepath, id)
>
> > if not os.path.isdir(kmlpath):
> > os.makedirs(kmlpath)
> > writefile = "%s/%s" % (kmlpath, str(id))
>
> actually .. writefile = "%s/%s" % (kmlpath, id)
>
>
>
> > f = open(writefile, 'wb')
> > else:
> > raise
> > except Exception as e:
> > print("id = %s\nbasepath = %s\n%s" % (id, basepath, e)
> > ...
>
> > mike
>
> >> ...
>
> >> In the createKML.py the problem arises in:
> >> ...
> >> import os
> >> ...
> >> def createKML(id):
> >> ...
> >> os.mkdir("D:/path/to/mysite/templates/maps/"+str(id))
> >> writefile = "D:/path/to/mysite/templates/maps/"+str(id)+"/"+str(id)
> >> + ".kml"
> >> f = open(writefile, 'wb')
> >> ...
>
> >> I hope this helps?
>
> >> On 14 aug, 21:55, Mike Dewhirst<mi...@dewhirst.com.au> wrote:
> >>> On 15/08/2010 12:10am, Mark Mooij wrote:
>
> >>>> Hi all,
>
> >>>> I recently migrated from Django 1.1.1 to 1.2.1. In 1.1.1 I had an
> >>>> application which imports an external python script in which a
> >>>> directory and some files are created. Since the migrate this doesn't
> >>>> work anymore, I get a number of IOErrors because the files (and
> >>>> directory) that should be created can't be found. I've tried changing
> >>>> my directories and slashes (I'm using Windows), but no success.
>
> >>> Have you changed anything else?
>
> >>> For example, are you processing the Microsoft Windows update patches
> >>> which (for WinXP) insert extra permission steps? Have you changed your
> >>> OS from XP to Win7?
>
> >>> Can you post the source of the script?
>
> >>>> Can't I use the os python functions anymore in Django 1.2.1? In the
> >>>> documentation I've read about Managing files in models but I prefer to
> >>>> handle this through my external script.
>
> >>>> I hope anybody can help me.
>
> >>>> Thanks,
> >>>> Mark

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to