Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #18328

Re: Can't write to a directory made w/ os.makedirs

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'context': 0.04; '(although': 0.05; 'sys': 0.05; 'example)': 0.07; 'script,': 0.07; 'python': 0.08; 'argument,': 0.09; 'context.': 0.09; 'directories?': 0.09; 'failing': 0.09; 'none)': 0.09; 'subprocess': 0.09; 'am,': 0.12; 'exception': 0.12; 'def': 0.13; "'')": 0.16; 'crack': 0.16; 'filename.': 0.16; 'invoking': 0.16; 'mkdir': 0.16; 'res': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'jan': 0.19; 'cc:no real name:2**0': 0.20; 'trying': 0.21; 'header:In-Reply-To:1': 0.22; 'default,': 0.23; 'item.': 0.23; 'cc:2**0': 0.24; 'creating': 0.25; 'parameters': 0.25; 'windows': 0.26; "i'm": 0.26; 'skip:[ 10': 0.27; 'import': 0.27; 'separate': 0.28; "skip:' 10": 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'cmd': 0.30; 'parent': 0.30; 'stat': 0.30; 'sub': 0.30; 'tjg': 0.30; 'yes.': 0.30; '(the': 0.30; 'skip:( 20': 0.31; 'list': 0.32; "isn't": 0.33; 'header:User-Agent:1': 0.33; 'there': 0.33; 'probably': 0.34; 'certain': 0.34; 'calling': 0.34; 'root': 0.34; 'running': 0.35; 'something': 0.35; 'unless': 0.35; 'david': 0.36; 'but': 0.37; 'run': 0.37; 'received:192': 0.37; 'think': 0.37; 'doing': 0.38; 'correctly': 0.39; 'processing': 0.39; 'should': 0.39; 'files': 0.39; 'called': 0.40; "it's": 0.40; 'received:192.168': 0.40; 'you.': 0.63; 'here': 0.65; 'nothing.': 0.67; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'golden': 0.73; '10:14': 0.84; 'deliberate': 0.84; 'directories,': 0.84; 'fl:': 0.84; 'subject:write': 0.84; 'elevated': 0.91; 'subject:made': 0.93; 'absolutely': 0.98
Date Mon, 02 Jan 2012 09:09:27 -0500
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15
MIME-Version 1.0
To David Goldsmith <eulergaussriemann@gmail.com>
Subject Re: Can't write to a directory made w/ os.makedirs
References <50693cc2-93c9-481d-9fb1-42312e69b2d9@c42g2000prb.googlegroups.com> <mailman.4289.1325410678.27778.python-list@python.org> <91830ffb-00d9-4fd1-b771-ad59374334ec@n22g2000prh.googlegroups.com> <mailman.4292.1325430363.27778.python-list@python.org> <6348b96c-f7a9-4ca6-a704-c90d25f07788@y25g2000prg.googlegroups.com>
In-Reply-To <6348b96c-f7a9-4ca6-a704-c90d25f07788@y25g2000prg.googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:8uIfhHbf4GCVEN9GnbXam9r/HDgJ1GRWbv2JGgwZ7uC bN7ASYHHv1S1/EP3AFQVNyI5tUt6UoawKysGCOrWwYg2JNQgBB +vJS8H/5m2wufe1l+xakkrKlNXR8UJh5Mk4nMf4HLR5ZGocMki ma8NA2MptOdhKBWKKeotKQbR6IT728MlSZGnPnF4CeRAqIkz/A b5LBJmj6nck7IyJBQ/Pv/0SrHMm2mnxvml+hPO1iYY6SEVyMJS oki+I2nJijhoFDFvS4L7BYO2/QtbzDkfYsSUNDLvg3/AKfzYYX TeCGJTnqep8FVzpY2nYnHAGXHtnsqIOJrXtPbYIC4Uh2em1Nh6 9JgqWCVh6uG1s+AYzJUE=
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To d@davea.name
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4314.1325513376.27778.python-list@python.org> (permalink)
Lines 86
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1325513376 news.xs4all.nl 6977 [2001:888:2000:d::a6]:51350
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:18328

Show key headers only | View raw


On 01/01/2012 10:14 PM, David Goldsmith wrote:
> On Jan 1, 7:05 am, Tim Golden<m...@timgolden.me.uk>  wrote:
>> On 01/01/2012 12:05, David Goldsmith wrote:
>>   >>  ie can the Python process creating the directories,
>>   >
>>   >  Yes.
>>   >
>>   >>  and a subprocess called from it create a simple file?
>>   >
>>   >  No.
>>   >
>>   >>  Depending on where you are in the filesystem, it may indeed
>>   >>  be necessary to be running as administrator. But don't try
>>   >>  to crack every security nut with an elevated sledgehammer.
>>   >
>>   >  If you mean running as admin., those were my sentiments exactly.  So,
>>   >  there isn't something specific I should be doing to assure that my
>>   >  subproceses can write to directories?
>>
>> In the general case, no. By default, a subprocess will have
>> the same security context as its parent. The exception is
>> where the parent (the Python processing invoking subprocess.call
>> in this example) is already impersonating a different user;
>> in that case, the subprocess will inherit its grandparent's
>> context.
>>
>> But unless you're doing something very deliberate here then
>> I doubt if that's biting you.
>>
>> Can I ask: are you absolutely certain that the processes
>> you're calling are doing what you think they are and failing
>> where you think they're failing?
>>
>> TJG
> I'm a mathematician: the only thing I'm absolutely certain of is
> nothing.
>
> Here's my script, in case that helps:
>
> import os
> import sys
> import stat
> import os.path as op
> import subprocess as sub
> from os import remove
> from os import listdir as ls
> from os import makedirs as mkdir
>
> def doFlac2Mp3(arg, d, fl):
>      if '.flac' in [f[-5:] for f in fl]:
>          newD = d.replace('FLACS', 'MP3s')
>          mkdir(newD)
>          for f in fl:
>              if f[-5:]=='.flac':
>                  root = f.replace('.flac', '')
>                  cmd = ['"C:\\Program Files (x86)\\aTunes\\win_tools\
> \flac.exe" -d ' +
>                         '--output-prefix=' + newD + '\\', f]
>                  res = sub.call(cmd)#, env={'PATH': os.defpath})
>                  if not res:
>                      cmd = ['"C:\\Program Files (x86)\\aTunes\\win_tools
> \\lame.exe" -h',
>                              newD + root + '.wav',  newD + root +
> '.mp3']
>                      res = sub.call(cmd)#, env={'PATH': os.defpath})
>                      if not res:
>                          rf = newD + root + '.wav'
>                          remove(rf)
>
> top=sys.argv[1]
> op.walk(top, doFlac2Mp3, None)
The line cmd= is bogus.  You're trying to run a program with a -h after 
the filename.  The reason you're passing a list to sub.call is to 
separate the parameters from the program name, not to mention with 
quotes in its name.  So the -h has to be  a separate list item.  
(Although Windows will probably handle it correctly if you combine the 
-h with the FOLLOWING argument, it's still bad practice]

cmd = [ "c:\\program files .... \\lame.exe", "-h", newD + root + ....."



-- 

DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[Windows 7, Python 2.6] Can't write to a directory made w/ os.makedirs OlyDLG <d.l.goldsmith@gmail.com> - 2011-12-31 14:13 -0800
  Re: [Windows 7, Python 2.6] Can't write to a directory made w/ os.makedirs Tim Golden <mail@timgolden.me.uk> - 2012-01-01 09:37 +0000
    Re: Can't write to a directory made w/ os.makedirs David Goldsmith <eulergaussriemann@gmail.com> - 2012-01-01 04:05 -0800
      Re: Can't write to a directory made w/ os.makedirs Tim Golden <mail@timgolden.me.uk> - 2012-01-01 15:05 +0000
        Re: Can't write to a directory made w/ os.makedirs David Goldsmith <eulergaussriemann@gmail.com> - 2012-01-01 19:14 -0800
          Re: Can't write to a directory made w/ os.makedirs MRAB <python@mrabarnett.plus.com> - 2012-01-02 03:43 +0000
            Re: Can't write to a directory made w/ os.makedirs David Goldsmith <eulergaussriemann@gmail.com> - 2012-01-03 07:17 -0800
          Re: Can't write to a directory made w/ os.makedirs Tim Golden <mail@timgolden.me.uk> - 2012-01-02 11:11 +0000
          Re: Can't write to a directory made w/ os.makedirs Dave Angel <d@davea.name> - 2012-01-02 09:09 -0500
            Re: Can't write to a directory made w/ os.makedirs David Goldsmith <eulergaussriemann@gmail.com> - 2012-01-02 18:34 -0800

csiph-web