Extraction of model and date created tag from own picture/video recordings

2017-03-14 Thread zljubisic
I am looking for the way to extract two simple information from pictures/videos 
that I have recorded with different devices that I own: model (of the device 
that has recorded) and recordings (local) creation time.

So far, I tried different approaches. 

I tried to use pymediainfo (https://pypi.python.org/pypi/pymediainfo/), which 
is kind of good for iPhone videos, but doesn't recognize model of the android 
videos and it is bed for pictures, but at the moment, I don't have anything 
better.

I also tried ExifRead (https://pypi.python.org/pypi/ExifRead), that is good for 
some pictures, but not for all.

For such a simple requirement (model and creation date) is there a library that 
can:
1.  Cover both pictures and videos
2.  Work with android and iPhone

Does someone have an experience with such task in order to suggest a library to 
me?
-- 
https://mail.python.org/mailman/listinfo/python-list


Extraction of model and date created tag from own picture/video recordings

2017-03-14 Thread zljubisic
I am looking for the way to extract two simple information from pictures/videos 
that I have recorded with different devices that I own: model (of the device 
that has recorded) and recordings (local) creation time.

So far, I tried different approaches. 

I tried to use pymediainfo (https://pypi.python.org/pypi/pymediainfo/), which 
is kind of good for iPhone videos, but doesn't recognize model of the android 
videos and it is bed for pictures, but at the moment, I don't have anything 
better.

I also tried ExifRead (https://pypi.python.org/pypi/ExifRead), that is good for 
some pictures, but not for all.

For such a simple requirement (model and creation date) is there a library that 
can:
1.  Cover both pictures and videos
2.  Work with android and iPhone

Does someone have an experience with such task in order to suggest a library to 
me?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: When will os.remove fail?

2017-03-14 Thread Steve D'Aprano
On Mon, 13 Mar 2017 08:47 pm, eryk sun wrote:

> On Sun, Mar 12, 2017 at 5:48 PM, Steve D'Aprano
>  wrote:
>>
>> Does os.remove work like this under Windows too?
> 
> os.remove calls DeleteFile on Windows. 
[...]

Thanks for the unexpectedly detailed explanation! A few follow-up questions:


> One hurdle to getting delete access is the sharing mode. If there are
> existing File objects that reference the file, they all have to share
> delete access. Otherwise the open fails with a sharing violation. This
> is often the show stopper because the C runtime (and thus CPython,
> usually) opens files with read and write sharing but not delete
> sharing.

This is the famous "can't delete a file which is open under Windows"
problem, am I right?

I take it that you *can* delete open files, but only if the process that
opens them takes special care to use "delete sharing". Is that correct?

I don't have a machine to test this on, but I'd like to deal with this
situation in my (cross-platform) code. If I have one Python script do this:


with open("My Documents/foo") as f:
time.sleep(10)


and while it is sleeping another script does this:

os.remove("My Documents/foo")


what exception will I get? Is that unique to this situation, or is a generic
exception that could mean anything?

My aim is to do:

try:
os.remove(thefile)
except SomeError:
# Could be a virus checker or other transient process.
time.sleep(0.2)
os.remove(thefile)  # try again


Does that seem reasonable to you, as a Windows user?


[...]
> OK, that covers the basics.

The basics, he says :-)


> In user mode, a kernel object such as a File instance is referenced as
> a handle. 

Out of curiosity, I only know the term "handle" from classic Macintosh
(pre-OS X) where a handle was a managed pointer to a pointer to a chunk of
memory. Being managed, the OS could move the memory around without the
handles ending up pointing to garbage. Is that the same meaning in Windows
land?


[...]
> When the delete disposition is set, no new File references can be
> instantiated (i.e. any level of access is denied, even just to read
> the file attributes), but the file isn't immediately unlinked. It's
> still listed in the parent directory. Any existing File reference that
> has delete access can unset the delete disposition.
> 
> When all handle and pointer references to a File object are closed,
> the file system decrements the reference count on the FCB. When the
> FCB reference count drops to 0, if the delete disposition is currently
> set, then finally the file is unlinked from the parent directory.

So technically file deletions aren't atomic in Windows? In principle, I
could say:

delete file X

which then returns immediately, and if I try to open(X) it will fail. But I
can still see it if I do a dir() on the parent directory?

Eventually the last reference to X will go away, and then it is unlinked.
What happens if I pull the plug in the meantime? Will the file magically
come back on rebooting?


[...]
> Finally, I'm sure most people are familiar with the read-only file
> attribute. If this attribute is set you can still open a file with
> delete access to rename it, but setting the delete disposition will
> fail with access denied.

That was actually the situation I was thinking about when I started on this
question. From Python code, I was considering writing something like this:


def delete_readonly(thefile):
try:
os.remove(thefile)
except ReadOnlyFileError:  # what is this really?
try:
# change the user permissions to unset Read-Only
old_perms = ... ?
set_perms(...)
except OSError:
pass
else:
# We changed Read-Only. Try deleting again. If it fails, 
# revert the flags and fail.
try:
os.remove(thefile)
except OSError:
# Restore permissions
...
else:
# Success on the second attempt!
return
raise



That's intended to emulate the behaviour on Unix where deleting a file that
you own will succeed even if you don't have write access to the file.

(The bash rm command will ask you before deleting, but Python's os.remove
just removes it.)


Does this seem reasonable? Or overly complicated for not enough benefit?





-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Issues with in try except and excel spreadsheet

2017-03-14 Thread Rhodri James

On 13/03/17 20:37, padawanweb...@gmail.com wrote:

On Monday, March 13, 2017 at 11:10:36 AM UTC-7, Rhodri James wrote:

On 13/03/17 17:40, padawanweb...@gmail.com wrote:

Hello, I'm having a problem with a try except inside a while loop. The problem 
I see occuring has to do with an excel file the script tries to write to while 
the excel file is open. The exception captures and gives an error:

OError: [Errno 13] Permission 
denied:'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx'

This is expected and is not the problem. However, the issue occurs when I close 
the excel file. As an example, if I run the script and the excel file is open 
thru 3 iterations, meaning that the script can't write to the excel file until 
the excel file is closed, then after the excel file is closed the script prints 
to the excel file 3 times. I don't need it to write to the excel file 3 times. 
I only need it to write just once. If the excel file is closed before I run the 
script than it works like its suppose too.
I hope I made my case clear. I look forward to some feedback. Any would be 
greatly appreciated!


When you say "...the excel file is open thru 3 iterations", what do you
mean?  Three iterations of what?  You haven't shown us a loop, so it's
not obvious.

How do you know it prints (writes?) to the excel file three times?
Again, there's nothing in the code snippet that would tell you.


here is part of the code:

connectionResults = None
returnResults = InternetQualityTest.connectionTest(connectionResults)
if returnResults == True:
try:
execfile('assetMapping.py')
time.sleep(4)
sys.exit()
except Exception as e:
print "error",e
time.sleep(20)


This looks plausible, though honestly the execfile makes me feel icky
for unrelated reasons.  I repeat, though; this isn't a loop, and my
crystal ball isn't up to telling me how it gets invoked.


FYI: The assetMapping.py runs another module from inside, and it's this module 
running from assetMapping that writes to the excel file.




--
Rhodri James *-* Kynesim Ltd


I apologize if I short-changed you with the code. It's a bigger piece of code 
and I thought maybe with my explanation and the piece I showed it would be 
enough. I was wrong. Here is the rest. I apologize in advance if there are any 
more confusions.

I do appreciate your help! Thanks in advance :-)


THIS IS: Main.py

import InternetQualityTest
import assetMapping
import time
import sys



if __name__ == '__main__':

while True:

connectionResults = None
returnResults = InternetQualityTest.connectionTest(connectionResults)
if returnResults == True:
try:
execfile('assetMapping.py')
time.sleep(4)
sys.exit()
except Exception as e:
print "error",e
time.sleep(20)


[Large amount of code with no suspicious-looking loops snipped]

Thanks for the extra code.  It's hard to get the balance right between 
giving people enough information to help and giving us so much 
information we can't see the wood for the trees.


Anyway, I'll go back to my questions.  What output do you have that 
convinces you that assetMapping.py is invoked three (or however many) 
times while the excel file is open?  What output do you have that 
convinces you that it then writes three (or however many) times?  As far 
as I can tell, the loop above can only repeat the call to execfile() if 
it catches an exception: what were those exceptions?


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: When will os.remove fail?

2017-03-14 Thread Chris Angelico
On Tue, Mar 14, 2017 at 10:32 PM, Steve D'Aprano
 wrote:
> On Mon, 13 Mar 2017 08:47 pm, eryk sun wrote:
>> One hurdle to getting delete access is the sharing mode. If there are
>> existing File objects that reference the file, they all have to share
>> delete access. Otherwise the open fails with a sharing violation. This
>> is often the show stopper because the C runtime (and thus CPython,
>> usually) opens files with read and write sharing but not delete
>> sharing.
>
> This is the famous "can't delete a file which is open under Windows"
> problem, am I right?
>
> I take it that you *can* delete open files, but only if the process that
> opens them takes special care to use "delete sharing". Is that correct?

Yes, but you can't always control the process that opens them. For
example, it's annoyingly difficult to update a running executable.

>> In user mode, a kernel object such as a File instance is referenced as
>> a handle.
>
> Out of curiosity, I only know the term "handle" from classic Macintosh
> (pre-OS X) where a handle was a managed pointer to a pointer to a chunk of
> memory. Being managed, the OS could move the memory around without the
> handles ending up pointing to garbage. Is that the same meaning in Windows
> land?

The old Mac meaning was very concrete and specific: it's a pointer to
a pointer. Since all *you* ever see is the first pointer, the OS is
free to (atomically) move the destination.

More generally, a handle is just an opaque cookie that represents a
thing. If you do cross-platform socket programming, you'll find that
on Unix, creating a socket returns a "file descriptor"; but on
Windows, it returns a "socket handle". Aside from the fact that socket
handles can only be used with socket functions (making them harder to
pass to other processes etc), the two concepts work broadly the same
way: you have a small integer value that represents a large resource.

>> When the delete disposition is set, no new File references can be
>> instantiated (i.e. any level of access is denied, even just to read
>> the file attributes), but the file isn't immediately unlinked. It's
>> still listed in the parent directory. Any existing File reference that
>> has delete access can unset the delete disposition.
>>
>> When all handle and pointer references to a File object are closed,
>> the file system decrements the reference count on the FCB. When the
>> FCB reference count drops to 0, if the delete disposition is currently
>> set, then finally the file is unlinked from the parent directory.
>
> So technically file deletions aren't atomic in Windows? In principle, I
> could say:
>
> delete file X
>
> which then returns immediately, and if I try to open(X) it will fail. But I
> can still see it if I do a dir() on the parent directory?
>
> Eventually the last reference to X will go away, and then it is unlinked.
> What happens if I pull the plug in the meantime? Will the file magically
> come back on rebooting?

Without actually testing it, my answers (based on experience of using
Windows) would be that the file doesn't disappear at all until it's
actually deleted. The "no new File refs can be instantiated" would
mean that it kicks back an error, not that it looks like the file
doesn't exist. If you pull the plug, it won't "magically come back" -
it'll have never gone.

> That's intended to emulate the behaviour on Unix where deleting a file that
> you own will succeed even if you don't have write access to the file.
>
> (The bash rm command will ask you before deleting, but Python's os.remove
> just removes it.)

(And the rm command won't ask if you say "-f".)

> Does this seem reasonable? Or overly complicated for not enough benefit?

I'm terrified to think what the interactions would be between this and
the Ubuntu subsystem in Win 10. What're the semantics of unlinkat()?
What about the common practice of creating a file and then unlinking
it so it doesn't show up in the directory? (And is that different on a
file system that supports hard links?) Or are heaps of POSIX features
simply not available?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: When will os.remove fail?

2017-03-14 Thread Jon Ribbens
On 2017-03-14, Chris Angelico  wrote:
>> (The bash rm command will ask you before deleting, but Python's os.remove
>> just removes it.)
>
> (And the rm command won't ask if you say "-f".)

rm does not ask before deleting. However some Linux distributions
take it upon themselves to put "alias rm='rm -i'" in /etc/profile.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: When will os.remove fail?

2017-03-14 Thread Chris Angelico
On Wed, Mar 15, 2017 at 12:30 AM, Jon Ribbens  wrote:
> On 2017-03-14, Chris Angelico  wrote:
>>> (The bash rm command will ask you before deleting, but Python's os.remove
>>> just removes it.)
>>
>> (And the rm command won't ask if you say "-f".)
>
> rm does not ask before deleting. However some Linux distributions
> take it upon themselves to put "alias rm='rm -i'" in /etc/profile.

I have no such alias, but it still prompts.

'man rm':

   If the -I or --interactive=once option is given,  and  there  are  more
   than  three  files  or  the  -r,  -R, or --recursive are given, then rm
   prompts the user for whether to proceed with the entire operation.   If
   the response is not affirmative, the entire command is aborted.

   Otherwise,  if  a file is unwritable, standard input is a terminal, and
   the -f or --force  option  is  not  given,  or  the  -i  or  --interac‐
   tive=always  option is given, rm prompts the user for whether to remove
   the file.  If the response is not affirmative, the file is skipped.

This is the GNU coreutils rm command. Obviously behaviour may be
different with non-GNU rm's.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


managing the RDFLib NamespaceManager

2017-03-14 Thread Adam Funk
I'm using RDFLib 4.2.2 (installed with pip3) in Python 3.5.2, and the
automatic behaviour of the NamespaceManager is giving me conniptions,
because the automatically generated namespaces go too far to the right
in the URIs and make the right-hand parts of the QNames meaningless.

For example, I have this code:

nsMgr = NamespaceManager(rdflib.Graph())
nsMgr.bind('dbpedia', Namespace('http://dbpedia.org/resource/'))
# plus some others


but in the serialized RDF I get these (and some other ns-numbered
ones):

@prefix dbpedia:  .
@prefix ns3:  .
@prefix ns5:  .

and obviously the QName outputs are wrong.  Is there any way to make
an RDFLib NamespaceManager *not* generate any namespaces
automatically?

Thanks,
Adam
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: When will os.remove fail?

2017-03-14 Thread Frank Millman
"Chris Angelico"  wrote in message 
news:captjjmrim9tjhfolgynujatx_hkvxxq_d8yjpkx8y32qhcz...@mail.gmail.com...


On Wed, Mar 15, 2017 at 12:30 AM, Jon Ribbens  
wrote:


(And the rm command won't ask if you say "-f".)


rm does not ask before deleting. However some Linux distributions
take it upon themselves to put "alias rm='rm -i'" in /etc/profile.


I have no such alias, but it still prompts.



On Fedora 22 (and for many previous versions) I have noticed that, if I log 
in as 'root', it does prompt, but if I log in as an ordinary user, it does 
not.


If I type 'alias' at the console, it lists current aliases. 'root' shows 
exactly what Jon quoted above. 'frank' shows no alias for 'rm'.


I had a quick look to see what was setting it, but there is nothing in 
/etc/profile or in /etc/bashrc. I don't know where else to check.


Frank Millman


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


Re: When will os.remove fail?

2017-03-14 Thread Chris Angelico
On Wed, Mar 15, 2017 at 1:22 AM, Frank Millman  wrote:
> "Chris Angelico"  wrote in message
> news:captjjmrim9tjhfolgynujatx_hkvxxq_d8yjpkx8y32qhcz...@mail.gmail.com...
>
> On Wed, Mar 15, 2017 at 12:30 AM, Jon Ribbens 
> wrote:


 (And the rm command won't ask if you say "-f".)
>>>
>>>
>>> rm does not ask before deleting. However some Linux distributions
>>> take it upon themselves to put "alias rm='rm -i'" in /etc/profile.
>>
>>
>> I have no such alias, but it still prompts.
>>
>
> On Fedora 22 (and for many previous versions) I have noticed that, if I log
> in as 'root', it does prompt, but if I log in as an ordinary user, it does
> not.
>
> If I type 'alias' at the console, it lists current aliases. 'root' shows
> exactly what Jon quoted above. 'frank' shows no alias for 'rm'.
>
> I had a quick look to see what was setting it, but there is nothing in
> /etc/profile or in /etc/bashrc. I don't know where else to check.

Since root has the prompt, check /root/.profile and /root/.bashrc.
There may also be other files sourced from either of those, eg
/root/.bash_aliases.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: When will os.remove fail?

2017-03-14 Thread Frank Millman

"Frank Millman"  wrote in message news:oa8uaf$k9e$1...@blaine.gmane.org...

On Fedora 22 (and for many previous versions) I have noticed that, if I 
log

in as 'root', it does prompt, but if I log in as an ordinary user, it does
not.


If I type 'alias' at the console, it lists current aliases. 'root' shows

exactly what Jon quoted above. 'frank' shows no alias for 'rm'.


I had a quick look to see what was setting it, but there is nothing in

/etc/profile or in /etc/bashrc. I don't know where else to check.

I should have looked a bit harder. It is in /root/.bashrc -

   alias rm='rm -i'
   alias cp='cp -i'
   alias mv='mv -i'

Frank



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


Re: When will os.remove fail?

2017-03-14 Thread Jon Ribbens
On 2017-03-14, Chris Angelico  wrote:
> On Wed, Mar 15, 2017 at 12:30 AM, Jon Ribbens  
> wrote:
>> rm does not ask before deleting. However some Linux distributions
>> take it upon themselves to put "alias rm='rm -i'" in /etc/profile.
>
> I have no such alias, but it still prompts.

I'm think you must be mistaken. What do you see if you type
'alias rm' and 'which rm'? Are you perhaps trying to delete
files to which you do not have write permission?

> 'man rm':
>
>If the -I or --interactive=once option is given,  and  there  are  more
>than  three  files  or  the  -r,  -R, or --recursive are given, then rm
>prompts the user for whether to proceed with the entire operation.   If
>the response is not affirmative, the entire command is aborted.
>
>Otherwise,  if  a file is unwritable, standard input is a terminal, and
>the -f or --force  option  is  not  given,  or  the  -i  or  --interac‐
>tive=always  option is given, rm prompts the user for whether to remove
>the file.  If the response is not affirmative, the file is skipped.

Yes, this describes the behaviour if you specify -I or -i,
as I mentioned - not if you don't specify either of those options.

> This is the GNU coreutils rm command.

I am talking about the GNU coreutils rm command (and POSIX for that
matter, since the behaviour of GNU rm appears to be POSIX compliant
as far as what we are talking about goes).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Issues with in try except and excel spreadsheet

2017-03-14 Thread padawanwebdev
On Tuesday, March 14, 2017 at 4:42:39 AM UTC-7, Rhodri James wrote:
> On 13/03/17 20:37, padawanweb...@gmail.com wrote:
> > On Monday, March 13, 2017 at 11:10:36 AM UTC-7, Rhodri James wrote:
> >> On 13/03/17 17:40, padawanweb...@gmail.com wrote:
> >>> Hello, I'm having a problem with a try except inside a while loop. The 
> >>> problem I see occuring has to do with an excel file the script tries to 
> >>> write to while the excel file is open. The exception captures and gives 
> >>> an error:
> >>>
> >>> OError: [Errno 13] Permission 
> >>> denied:'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx'
> >>>
> >>> This is expected and is not the problem. However, the issue occurs when I 
> >>> close the excel file. As an example, if I run the script and the excel 
> >>> file is open thru 3 iterations, meaning that the script can't write to 
> >>> the excel file until the excel file is closed, then after the excel file 
> >>> is closed the script prints to the excel file 3 times. I don't need it to 
> >>> write to the excel file 3 times. I only need it to write just once. If 
> >>> the excel file is closed before I run the script than it works like its 
> >>> suppose too.
> >>> I hope I made my case clear. I look forward to some feedback. Any would 
> >>> be greatly appreciated!
> >>
> >> When you say "...the excel file is open thru 3 iterations", what do you
> >> mean?  Three iterations of what?  You haven't shown us a loop, so it's
> >> not obvious.
> >>
> >> How do you know it prints (writes?) to the excel file three times?
> >> Again, there's nothing in the code snippet that would tell you.
> >>
> >>> here is part of the code:
> >>>
> >>> connectionResults = None
> >>> returnResults = 
> >>> InternetQualityTest.connectionTest(connectionResults)
> >>> if returnResults == True:
> >>> try:
> >>> execfile('assetMapping.py')
> >>> time.sleep(4)
> >>> sys.exit()
> >>> except Exception as e:
> >>> print "error",e
> >>> time.sleep(20)
> >>
> >> This looks plausible, though honestly the execfile makes me feel icky
> >> for unrelated reasons.  I repeat, though; this isn't a loop, and my
> >> crystal ball isn't up to telling me how it gets invoked.
> >>
> >>> FYI: The assetMapping.py runs another module from inside, and it's this 
> >>> module running from assetMapping that writes to the excel file.
> >>>
> >>
> >>
> >> --
> >> Rhodri James *-* Kynesim Ltd
> >
> > I apologize if I short-changed you with the code. It's a bigger piece of 
> > code and I thought maybe with my explanation and the piece I showed it 
> > would be enough. I was wrong. Here is the rest. I apologize in advance if 
> > there are any more confusions.
> >
> > I do appreciate your help! Thanks in advance :-)
> >
> >
> > THIS IS: Main.py
> >
> > import InternetQualityTest
> > import assetMapping
> > import time
> > import sys
> >
> >
> >
> > if __name__ == '__main__':
> >
> > while True:
> >
> > connectionResults = None
> > returnResults = 
> > InternetQualityTest.connectionTest(connectionResults)
> > if returnResults == True:
> > try:
> > execfile('assetMapping.py')
> > time.sleep(4)
> > sys.exit()
> > except Exception as e:
> > print "error",e
> > time.sleep(20)
> 
> [Large amount of code with no suspicious-looking loops snipped]
> 
> Thanks for the extra code.  It's hard to get the balance right between 
> giving people enough information to help and giving us so much 
> information we can't see the wood for the trees.
> 
> Anyway, I'll go back to my questions.  What output do you have that 
> convinces you that assetMapping.py is invoked three (or however many) 
> times while the excel file is open?  What output do you have that 
> convinces you that it then writes three (or however many) times?  As far 
> as I can tell, the loop above can only repeat the call to execfile() if 
> it catches an exception: what were those exceptions?
> 
> -- 
> Rhodri James *-* Kynesim Ltd

As an example, If I have the excel file open and there is data that needs to be 
written to the excel file than the exception will catch this error: 

IOError: [Errno 13] Permission denied: 
'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx'

essentially, because the excel file is open during the process of writing to 
the excel file the "try" will keep attempting to write to the excel until its 
closed. So, if there were 5 attempts to write the data to the excel file, then 
after the excel file is closed that data will be written to the excel file n+1  
times (6 times). When this happens it shows 6 rows of the newly written data, 
however, it's the same data. To illustrate this here is the output from the 
shell line while the excel file is open and when it's closed. Note

Re: When will os.remove fail?

2017-03-14 Thread Jon Ribbens
On 2017-03-14, Frank Millman  wrote:
> If I type 'alias' at the console, it lists current aliases. 'root' shows 
> exactly what Jon quoted above. 'frank' shows no alias for 'rm'.
>
> I had a quick look to see what was setting it, but there is nothing in 
> /etc/profile or in /etc/bashrc. I don't know where else to check.

Perhaps one or more of:

/root/.profile
/root/.bash_profile
/root/.bashrc
/etc/profile.d/*
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: When will os.remove fail?

2017-03-14 Thread Chris Angelico
On Wed, Mar 15, 2017 at 1:30 AM, Jon Ribbens  wrote:
> On 2017-03-14, Chris Angelico  wrote:
>> On Wed, Mar 15, 2017 at 12:30 AM, Jon Ribbens  
>> wrote:
>>> rm does not ask before deleting. However some Linux distributions
>>> take it upon themselves to put "alias rm='rm -i'" in /etc/profile.
>>
>> I have no such alias, but it still prompts.
>
> I'm think you must be mistaken. What do you see if you type
> 'alias rm' and 'which rm'? Are you perhaps trying to delete
> files to which you do not have write permission?

This conversation was specifically about files for which one does not
have write permission. So yes. (It's pretty common; .git/objects is
mostly or entirely made up of such files.)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: When will os.remove fail?

2017-03-14 Thread Lele Gaifax
Jon Ribbens  writes:

>>Otherwise,  if  a file is unwritable, standard input is a terminal, 
>> and
>>the -f or --force  option  is  not  given,  or  the  -i  or  
>> --interac‐
>>tive=always  option is given, rm prompts the user for whether to 
>> remove
>>the file.  If the response is not affirmative, the file is skipped.
>
> Yes, this describes the behaviour if you specify -I or -i,
> as I mentioned - not if you don't specify either of those options.

English is not my native language, but that's not how I understand that
paragraph: if -i is given, it always ask, regardless the writable bit,
otherwise it does when f is readonly and no -f is given.

I think Chris is right, consider:

$ rm --version
rm (GNU coreutils) 8.26

$ which rm
/bin/rm

$ alias | grep rm | wc -l
0

$ ls -l *file*
-rw-rw-r-- 1 lele lele 0 Mar 14 15:52 myfile
-r 1 lele lele 0 Mar 14 15:52 myfile2
-rw-r--r-- 1 root root 0 Mar 14 15:52 othersfile

$ rm myfile

$ rm myfile2
rm: remove write-protected regular empty file 'myfile2'? y

$ rm othersfile
rm: remove write-protected regular empty file 'othersfile'? y

$ ls -l *file*
ls: cannot access '*file*': No such file or directory

my 0.02€
ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

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


Re: When will os.remove fail?

2017-03-14 Thread Jon Ribbens
On 2017-03-14, Lele Gaifax  wrote:
> Jon Ribbens  writes:
>>>Otherwise,  if  a file is unwritable, standard input is a terminal, and
>>>the -f or --force  option  is  not  given,  or  the  -i  or  --interac‐
>>>tive=always  option is given, rm prompts the user for whether to remove
>>>the file.  If the response is not affirmative, the file is skipped.
>>
>> Yes, this describes the behaviour if you specify -I or -i,
>> as I mentioned - not if you don't specify either of those options.
>
> English is not my native language, but that's not how I understand that
> paragraph: if -i is given, it always ask, regardless the writable bit,
> otherwise it does when f is readonly and no -f is given.

You're understanding that paragraph correctly, but are
misunderstanding what I wrote - I didn't disagree with
what you're saying.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Issues with in try except and excel spreadsheet

2017-03-14 Thread Rhodri James

On 14/03/17 14:26, padawanweb...@gmail.com wrote:

As an example, If I have the excel file open and there is data that needs to be 
written to the excel file than the exception will catch this error:

IOError: [Errno 13] Permission denied: 
'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx'


Ah yes, you did say that, sorry I missed it.


essentially, because the excel file is open during the process of writing to the excel 
file the "try" will keep attempting to write to the excel until its closed. So, 
if there were 5 attempts to write the data to the excel file, then after the excel file 
is closed that data will be written to the excel file n+1  times (6 times). When this 
happens it shows 6 rows of the newly written data, however, it's the same data. To 
illustrate this here is the output from the shell line while the excel file is open and 
when it's closed. Note, When I close it it will say Report Updated.


Ah, no.  According to your code, successfully writing to the file is 
what causes "Report Updated" to be printed, not the closing of the file. 
 It's important to be accurate about things like that, otherwise you 
spend hours looking for a connection in entirely the wrong place.




Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on 
win32
Type "copyright", "credits" or "license()" for more information.

 RESTART 


-1
Test = True

error [Errno 13] Permission denied: 
'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx'
-1
Test = True

error [Errno 13] Permission denied: 
'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx'
-1
Test = True

error [Errno 13] Permission denied: 
'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx'
-1
Test = True

error [Errno 13] Permission denied: 
'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx'
-1
Test = True

error [Errno 13] Permission denied: 
'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx'
-1
Test = True

Report Updated

This is what's written to the excel file:

3   NB19097 24.221.51.225   376_SouthYard   373_Reseda  03-14-2017  
07:03:46
4   NB19097 24.221.51.225   376_SouthYard   373_Reseda  03-14-2017  
07:04:07
5   NB19097 24.221.51.225   376_SouthYard   373_Reseda  03-14-2017  
07:04:27
6   NB19097 24.221.51.225   376_SouthYard   373_Reseda  03-14-2017  
07:04:47
7   NB19097 24.221.51.225   376_SouthYard   373_Reseda  03-14-2017  
07:05:07
8   NB19097 24.221.51.225   376_SouthYard   373_Reseda  03-14-2017  
07:05:28

As you can see from the shell line the number of attempts made, and from the 
excel file the number of rows taken, that there is a correlation between the 
attempts and what gets written to the excel file.


The interesting thing is that there is only one write.  This suggests 
that the information is being appended to another file somewhere, or 
held in some other way that persists between invocations of assetMapping.py.


Now I'm not going to hunt through your code for the answer, because 
there's too much of it and frankly the overly long lines don't survive 
email well on my machine.  However, you should look for the tidying up 
in your code that doesn't get done because the attempted write throws an 
exception.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: When will os.remove fail?

2017-03-14 Thread eryk sun
On Tue, Mar 14, 2017 at 11:32 AM, Steve D'Aprano
 wrote:
> On Mon, 13 Mar 2017 08:47 pm, eryk sun wrote:
>
>> One hurdle to getting delete access is the sharing mode. If there are
>> existing File objects that reference the file, they all have to share
>> delete access. Otherwise the open fails with a sharing violation. This
>> is often the show stopper because the C runtime (and thus CPython,
>> usually) opens files with read and write sharing but not delete
>> sharing.
>
> This is the famous "can't delete a file which is open under Windows"
> problem, am I right?

If you aren't allowed shared delete access, the error you'll get is a
sharing violation (32). If the file security doesn't allow delete
access, then the error is access denied (5). In Python both of these
raise a PermissionError, so telling the difference requires checking
the winerror attribute.

Two more cases are (1) a read-only file and (2) a file that's
memory-mapped as code or data. In these two cases you can open the
file with delete access, which allows you to rename it, but setting
the delete disposition fails with access denied.

If you have the right to set the file's attributes, then you can at
least work around the read-only problem via os.chmod(filename,
stat.S_IWRITE).

For the mapped file case the best you can do is rename the file to
another directory. At least it gets it out of the way if you're doing
an upgrade to a running program. This workaround is rarely used -- I
think mostly due to people not knowing that it's possible.

> I take it that you *can* delete open files, but only if the process that
> opens them takes special care to use "delete sharing". Is that correct?

Unix programmers can't simply use delete sharing as a way to get
familiar semantics on Windows. A file pending delete is in limbo on
Windows. It can't be opened again, and as long as there are File
objects that reference the common file control block (FCB), it can't
be unlinked. One of those File objects may even be used to restore the
file (i.e. unset the delete disposition) if it has delete access.
Notably, this limbo file prevents the containing directory from being
deleted.

> I don't have a machine to test this on, but I'd like to deal with this
> situation in my (cross-platform) code. If I have one Python script do this:
>
> with open("My Documents/foo") as f:
> time.sleep(10)
>
> and while it is sleeping another script does this:
>
> os.remove("My Documents/foo")
>
> what exception will I get? Is that unique to this situation, or is a generic
> exception that could mean anything?

This will fail with a sharing violation, i.e. winerror == 32.

> My aim is to do:
>
> try:
> os.remove(thefile)
> except SomeError:
> # Could be a virus checker or other transient process.
> time.sleep(0.2)
> os.remove(thefile)  # try again
>
> Does that seem reasonable to you, as a Windows user?

If you get an access-denied error, then you can try to remove the
read-only attribute if it's set. Otherwise you can try to rename the
file to get it out of the way. But if you're locked out by a sharing
violation, there isn't anything you can do short of terminating the
offending program.

Virus scanners and other filter drivers generally aren't an immediate
problem with deleting. They share all access. But they might keep a
file from being immediately unlinked, which could cause problems in
functions like shutil.rmtree. Removing the parent directory can fail
if the file hasn't been unlinked yet.

>> In user mode, a kernel object such as a File instance is referenced as
>> a handle.
>
> Out of curiosity, I only know the term "handle" from classic Macintosh
> (pre-OS X) where a handle was a managed pointer to a pointer to a chunk of
> memory. Being managed, the OS could move the memory around without the
> handles ending up pointing to garbage. Is that the same meaning in Windows
> land?

That sounds similar to an HGLOBAL handle used with
GlobalAlloc/GlobalLock. This was a feature from 16-bit Windows, and
it's kept around for compatibility with older APIs that still use it.

I was talking about handles for kernel objects. Every process has a
table of handle entries that's used to refer to kernel objects. These
objects are allocated in the shared kernel space (the upper range of
virtual memory), so user-mode code can't refer to them directly.
Instead a program passes a handle to a system call, and kernel code
and drivers use the object manager to look up the pointer reference.

A kernel object has an associated type object (e.g. the "File" type),
and there's a "Type" metatype like in Python. The list of supported
methods is pretty basic:

DumpProcedure, OpenProcedure, ParseProcedure,
SecurityProcedure, QueryNameProcedure, OkayToCloseProcedure,
CloseProcedure, DeleteProcedure

The close method is called when a process closes a handle to the
object. It gets passed a reference to the Process that's closing the
handle and also the object's handle co

Re: When will os.remove fail?

2017-03-14 Thread eryk sun
On Tue, Mar 14, 2017 at 1:07 PM, Chris Angelico  wrote:
> On Tue, Mar 14, 2017 at 10:32 PM, Steve D'Aprano
>  wrote:
>
>> I take it that you *can* delete open files, but only if the process that
>> opens them takes special care to use "delete sharing". Is that correct?
>
> Yes, but you can't always control the process that opens them. For
> example, it's annoyingly difficult to update a running executable.

One option is to move it out of the way. For example:

src = Path(sys.executable)
dst = Path('C:/Temp/python.exe')

>>> src.exists(), dst.exists()
(True, False)

>>> src.rename(dst)
>>> src.exists(), dst.exists()
(False, True)

>>> dst.rename(src)
>>> src.exists(), dst.exists()
(True, False)

> More generally, a handle is just an opaque cookie that represents a
> thing. If you do cross-platform socket programming, you'll find that
> on Unix, creating a socket returns a "file descriptor"; but on
> Windows, it returns a "socket handle". Aside from the fact that socket
> handles can only be used with socket functions (making them harder to
> pass to other processes etc), the two concepts work broadly the same
> way: you have a small integer value that represents a large resource.

Usually a socket is a handle for a File object, from opening the AFD
(ancillary function) device. You can use it with [Nt]ReadFile and
[Nt]WriteFile [1]. It's just better to use it with Winsock APIs like
WSARecv and WSASend, which make NtDeviceIoControlFile calls.

But there's also the headache of the deprecated layered service
providers, for which a socket isn't really a File object and using
File functions is inefficient.

[1]: https://msdn.microsoft.com/en-us/library/ms740522

Similarly for a console File handle you can use [Nt]ReadFile and
[Nt]WriteFile, which encode and decode byte streams using the console
input and output codepages. But it's generally better to use
ReadConsole and WriteConsole, which allow using the UTF-16 API via
NtDeviceIoControlFile. ReadConsole also allows defining a custom
control mask, if, for example, you want Ctrl+D to signal EOF.

> I'm terrified to think what the interactions would be between this and
> the Ubuntu subsystem in Win 10. What're the semantics of unlinkat()?
> What about the common practice of creating a file and then unlinking
> it so it doesn't show up in the directory? (And is that different on a
> file system that supports hard links?) Or are heaps of POSIX features
> simply not available?

WSL uses the VolFs file system for the Linux VFS. This should
implement native Linux file-system behavior.

The interesting interaction is for Windows drives that are made
available under /mnt. In the following example, in Windows Python I
set the delete disposition on a file named "spam". Then in WSL python3
I checked the directory listing and whether I could stat, remove, or
open the file:

>>> os.listdir()
['spam']

>>> os.stat('spam')
Traceback (most recent call last):
  File "", line 1, in 
FileNotFoundError: [Errno 2] No such file or directory: 'spam'

>>> os.remove('spam')
Traceback (most recent call last):
  File "", line 1, in 
FileNotFoundError: [Errno 2] No such file or directory: 'spam'

>>> open('spam')
Traceback (most recent call last):
  File "", line 1, in 
FileNotFoundError: [Errno 2] No such file or directory: 'spam'

>>> open('spam', 'w')
Traceback (most recent call last):
  File "", line 1, in 
FileNotFoundError: [Errno 2] No such file or directory: 'spam'

Back in Windows I called SetFileInformationByHandle to unset the
delete disposition. Then regular access was restored in WSL:

>>> s = os.stat('spam')
>>> s.st_ino, s.st_size
(35184372088857305, 10)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: When will os.remove fail?

2017-03-14 Thread Michael Felt

On 13/03/2017 02:51, Steve D'Aprano wrote:

On Mon, 13 Mar 2017 05:45 am, Alain Ketterlin wrote:


Steve D'Aprano  writes:

[...]

It seems that os.remove on Linux will force the delete even if the file
is read-only or unreadable, provided you own the file.

Your permissions on the file do not really matters. It's all about your
permissions on the parent directory (removing a file is really modifying
the parent dir). Actually, it is even slightly more complicated. Here is
an excerpt of the unlink(2) call (which does the job) listing common
error cases:
Granted, I am a bit behind in the discussion - and I know nothing about 
how Windows manages this since DOS 3.3 - there it also called unlink().


rm is the command we run. The system call it uses to remove a file is 
unlink(). unlink() removes the "link" of the name in the directory to 
the inode and lowers the count of the number of links to the file (a 
hard link is an additional directory link to the inode). To modify the 
inode (link counter) you need to own the file or have (super user) 
elevated privelidges. To remove the directory link you need to have 
write privilidge on the (special file type) directory.


On UNIX/Linux when the link count is zero the inode and the filesystem 
blocks it provides access to are cleared if no process is holding the 
file open. This means it is easy to unlink() (not remove!) an open file. 
The inode is active and can be used "normally". FYI, the classic 
mktemp() library routine on UNIX would create a file, open (better 
create) the file, unlink the file, and then return file descriptor. 
Regardless of how the program ended (crash or normal) the temp file 
would be cleaned up on exit.


I would be guessing - but FAT and/or NTFS may not be written to clean up 
on a file with no "links" - and this is why Windows behavior seems to be 
more restrictive than POSIX/LINUX.



Thanks for the detailed explanation, and to everyone else who corrected my
misunderstanding.





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


Re: Extraction of model and date created tag from own picture/video recordings

2017-03-14 Thread MRAB

On 2017-03-14 07:34, zljubi...@gmail.com wrote:

I am looking for the way to extract two simple information from pictures/videos 
that I have recorded with different devices that I own: model (of the device 
that has recorded) and recordings (local) creation time.

So far, I tried different approaches.

I tried to use pymediainfo (https://pypi.python.org/pypi/pymediainfo/), which 
is kind of good for iPhone videos, but doesn't recognize model of the android 
videos and it is bed for pictures, but at the moment, I don't have anything 
better.

I also tried ExifRead (https://pypi.python.org/pypi/ExifRead), that is good for 
some pictures, but not for all.

For such a simple requirement (model and creation date) is there a library that 
can:
1.  Cover both pictures and videos
2.  Work with android and iPhone

Does someone have an experience with such task in order to suggest a library to 
me?


It might be worth trying "ImageMagick".

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


Re: When will os.remove fail?

2017-03-14 Thread Grant Edwards
On 2017-03-13, eryk sun  wrote:

[An impressive 150-line explanation of file removal on Windows.]

Wow.  I have two comments:

1. I think I can see the VMS heritage of Windows shining through.

2. You have my condolences regarding whatever it was that required you
   to know all that...



VMS: for when just one overly complex solution to a simple problem
isn't enough.

-- 
Grant Edwards   grant.b.edwardsYow! Finally, Zippy
  at   drives his 1958 RAMBLER
  gmail.comMETROPOLITAN into the
   faculty dining room.

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


Re: When will os.remove fail?

2017-03-14 Thread Chris Angelico
On Wed, Mar 15, 2017 at 5:28 AM, Michael Felt  wrote:
> Granted, I am a bit behind in the discussion - and I know nothing about how
> Windows manages this since DOS 3.3 - there it also called unlink().
>
> rm is the command we run. The system call it uses to remove a file is
> unlink(). unlink() removes the "link" of the name in the directory to the
> inode and lowers the count of the number of links to the file (a hard link
> is an additional directory link to the inode). To modify the inode (link
> counter) you need to own the file or have (super user) elevated privelidges.
> To remove the directory link you need to have write privilidge on the
> (special file type) directory.
>
> On UNIX/Linux when the link count is zero the inode and the filesystem
> blocks it provides access to are cleared if no process is holding the file
> open. This means it is easy to unlink() (not remove!) an open file. The
> inode is active and can be used "normally". FYI, the classic mktemp()
> library routine on UNIX would create a file, open (better create) the file,
> unlink the file, and then return file descriptor. Regardless of how the
> program ended (crash or normal) the temp file would be cleaned up on exit.

You've fairly accurately summed up the POSIX model. The rm command
uses the unlink syscall, and the semantics are broadly as you
describe; the permissions question is handled by the standard
permission bits "rwxrwxrwx", but otherwise you're about right. And
yes, removing a file means removing one name from it, which is why a
log file growing to infinity can't simply be deleted when you run out
of disk space.

If the program ends while the OS is still alive, then yes, the temp
file will be cleaned up on exit. If the power is pulled, AIUI a fsck
will notice that there's a file with no directory entries, and clean
it up, although it may end up dropping it into lost+found rather than
just deleting it.

> I would be guessing - but FAT and/or NTFS may not be written to clean up on
> a file with no "links" - and this is why Windows behavior seems to be more
> restrictive than POSIX/LINUX.

The Windows semantics are very different. Firstly, FAT doesn't even
_have_ the concept of hardlinks (aka files with multiple directory
entries), so there's no way that it'll ever be able to do this kind of
thing. (And before you say "oh but FAT is dead these days", it's still
frequently used on removable media.) NTFS does have hardlinks, so in
theory it would be capable of POSIX semantics, but Windows semantics
are baked into a lot of programs' expectations, so I doubt that that's
going to change.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


python and pyqt4

2017-03-14 Thread Xristos Xristoou
i will want to create a simple python script with pyqt4 and Q designer where 
the user put a number (line_edit) and if that number is something the user take 
back three new codes(lineEdit_2,lineEdit_3,lineEdit_4) and if user press 
ok(buttonBox) then plugin do something else in the some GUI.
for that i create a new additional pushButton in Qdesigner and i create 
additional def function(run1) for execute code for pushButton.


first i add new pushbutton in __init__ :
def __init__(self, iface):
self.dlg = pluginDialog()
self.dlg.pushButton.clicked.connect(self.run1)

plugin work without error but dont show me the codes 
(lineEdit_2,lineEdit_3,lineEdit_4) in the plugin window if i press 
pushbutton
any idea ? my python code :

def run1(self):
distance = str(self.dlg.lineEdit.text())
if distance==0:
area1='some'
area2='hello'
area3='world'
self.dlg.lineEdit_2.setText(str(area1))
self.dlg.lineEdit_3.setText(str(area2))
self.dlg.lineEdit_4.setText(str(area3))



def run(self):
self.dlg.show()
result = self.dlg.exec_()

if result:
pass

and i try to replace run1 with :

def run1(self):
self.dlg.show()
result = self.dlg.exec_()
if result:
distance = str(self.dlg.lineEdit.text())
if distance==0:
area1='some'
area2='hello'
area3='world'
self.dlg.lineEdit_2.setText(str(area1))
self.dlg.lineEdit_3.setText(str(area2))
self.dlg.lineEdit_4.setText(str(area3))
pass

but no change.
-- 
https://mail.python.org/mailman/listinfo/python-list


python and databases

2017-03-14 Thread Xristos Xristoou
I have a database in  microsoft ACCESS with about 150 records.. if I want to 
get some data from this database using  a query in python and i want to store 
in some variables in python that will do this ? to avoid the 150 if ...: Using 
the standard library the python? know easily put it an SQL query but i canot 
use additional library python.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python3.6 a little conundrum

2017-03-14 Thread Ian Kelly
On Tue, Mar 14, 2017 at 2:25 PM, Gilmeh Serda
 wrote:
> Thanks. I guess I could get a new(-er) copy when that day comes and redo
> all this. I trust 3.6.0 won't be the last one. :)

As it says in the Book of Armaments, Chapter 2, verses 9–21:

"""
Three shall be the number thou shalt count, and the number of the
counting shall be three. Four shalt thou not count, neither count thou
two, excepting that thou then proceed to three. Five is right out.
"""

We should thus infer that Python 3.9 will be the final release as
Guido does not want a 3.10 and proceeding to 4.0 would be unholy.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python and pyqt4

2017-03-14 Thread Vincent Vande Vyvre

Le 14/03/17 à 20:56, Xristos Xristoou a écrit :

i will want to create a simple python script with pyqt4 and Q designer where 
the user put a number (line_edit) and if that number is something the user take 
back three new codes(lineEdit_2,lineEdit_3,lineEdit_4) and if user press 
ok(buttonBox) then plugin do something else in the some GUI.
for that i create a new additional pushButton in Qdesigner and i create 
additional def function(run1) for execute code for pushButton.


first i add new pushbutton in __init__ :
def __init__(self, iface):
 self.dlg = pluginDialog()
 self.dlg.pushButton.clicked.connect(self.run1)

plugin work without error but dont show me the codes 
(lineEdit_2,lineEdit_3,lineEdit_4) in the plugin window if i press
pushbutton
any idea ? my python code :

def run1(self):
 distance = str(self.dlg.lineEdit.text())
 if distance==0:
 area1='some'
 area2='hello'
 area3='world'
 self.dlg.lineEdit_2.setText(str(area1))
 self.dlg.lineEdit_3.setText(str(area2))
 self.dlg.lineEdit_4.setText(str(area3))



def run(self):
 self.dlg.show()
 result = self.dlg.exec_()

 if result:
 pass

and i try to replace run1 with :

def run1(self):
 self.dlg.show()
 result = self.dlg.exec_()
 if result:
 distance = str(self.dlg.lineEdit.text())
 if distance==0:
 area1='some'
 area2='hello'
 area3='world'
 self.dlg.lineEdit_2.setText(str(area1))
 self.dlg.lineEdit_3.setText(str(area2))
 self.dlg.lineEdit_4.setText(str(area3))
 pass

but no change.


distance is a string, then you have to compare it with the string "0" 
not the integer



Vincent

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


Re: When will os.remove fail?

2017-03-14 Thread Erik

On 14/03/17 13:56, Chris Angelico wrote:

On Wed, Mar 15, 2017 at 12:30 AM, Jon Ribbens  wrote:

rm does not ask before deleting. However some Linux distributions
take it upon themselves to put "alias rm='rm -i'" in /etc/profile.


I have no such alias, but it still prompts.


[snip]


This is the GNU coreutils rm command. Obviously behaviour may be
different with non-GNU rm's.


Yes, I believe this is something extra that particular versions of 'rm' 
may do (over and above the POSIX/unlink() semantics discussed already).


Although one has permission at the OS/filesystem level to unlink the 
file, unless '-f' is specified they may still ask ('-i' behaviour) if 
that file is otherwise not modifiable by the user running the command, 
as a safety net.


E.

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


Re: python and databases

2017-03-14 Thread Irving Duran
I don't know that there is a native library in python for you to call an MS
Access db.  Would you be able to extract the content into a CSV and read it
that way? Also, is there a particular reason why you couldn't use an
additional python lib?


Thank You,

Irving Duran

On Tue, Mar 14, 2017 at 2:59 PM, Xristos Xristoou  wrote:

> I have a database in  microsoft ACCESS with about 150 records.. if I want
> to get some data from this database using  a query in python and i want to
> store in some variables in python that will do this ? to avoid the 150 if
> ...: Using the standard library the python? know easily put it an SQL query
> but i canot use additional library python.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python and pyqt4

2017-03-14 Thread MRAB

On 2017-03-14 21:03, Vincent Vande Vyvre wrote:

Le 14/03/17 à 20:56, Xristos Xristoou a écrit :

i will want to create a simple python script with pyqt4 and Q designer where 
the user put a number (line_edit) and if that number is something the user take 
back three new codes(lineEdit_2,lineEdit_3,lineEdit_4) and if user press 
ok(buttonBox) then plugin do something else in the some GUI.
for that i create a new additional pushButton in Qdesigner and i create 
additional def function(run1) for execute code for pushButton.


first i add new pushbutton in __init__ :
def __init__(self, iface):
 self.dlg = pluginDialog()
 self.dlg.pushButton.clicked.connect(self.run1)

plugin work without error but dont show me the codes 
(lineEdit_2,lineEdit_3,lineEdit_4) in the plugin window if i press
pushbutton
any idea ? my python code :

def run1(self):
 distance = str(self.dlg.lineEdit.text())
 if distance==0:
 area1='some'
 area2='hello'
 area3='world'
 self.dlg.lineEdit_2.setText(str(area1))
 self.dlg.lineEdit_3.setText(str(area2))
 self.dlg.lineEdit_4.setText(str(area3))



def run(self):
 self.dlg.show()
 result = self.dlg.exec_()

 if result:
 pass

and i try to replace run1 with :

def run1(self):
 self.dlg.show()
 result = self.dlg.exec_()
 if result:
 distance = str(self.dlg.lineEdit.text())
 if distance==0:
 area1='some'
 area2='hello'
 area3='world'
 self.dlg.lineEdit_2.setText(str(area1))
 self.dlg.lineEdit_3.setText(str(area2))
 self.dlg.lineEdit_4.setText(str(area3))
 pass

but no change.


distance is a string, then you have to compare it with the string "0"
not the integer

In addition, if the condition is false, then area1, area2 and area3 
won't exist, and you'll get a NameError (although the GUI might be 
hiding that from you!).


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


Re: python and databases

2017-03-14 Thread Chris Angelico
On Wed, Mar 15, 2017 at 6:59 AM, Xristos Xristoou  wrote:
> I have a database in  microsoft ACCESS with about 150 records.. if I want to 
> get some data from this database using  a query in python and i want to store 
> in some variables in python that will do this ? to avoid the 150 if ...: 
> Using the standard library the python? know easily put it an SQL query but i 
> canot use additional library python.
>

If you can't use third-party libraries, then basically your only
option is to export it as text, eg CSV.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python and databases

2017-03-14 Thread BrJohan

On 2017-03-14 20:59, Xristos Xristoou wrote:

I have a database in  microsoft ACCESS with about 150 records.. if I want to 
get some data from this database using  a query in python and i want to store 
in some variables in python that will do this ? to avoid the 150 if ...: Using 
the standard library the python? know easily put it an SQL query but i canot 
use additional library python.

Some years ago I did some experiments using pyodbc and MS Access. Some 
success.

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


Re: python and databases

2017-03-14 Thread Irmen de Jong
On 14-3-2017 20:59, Xristos Xristoou wrote:
> I have a database in  microsoft ACCESS with about 150 records.. if I want to 
> get some
> data from this database using  a query in python and i want to store in some
> variables in python that will do this ? to avoid the 150 if ...: Using the 
> standard
> library the python? know easily put it an SQL query but i canot use additional
> library python.
> 

Is the data in the Access database static? 150 records is not much data. You 
might be
able to extract it ONCE, and store it directly in Python data structures 
instead. Or
extract it and store it in a sqlite database instead, which you can use from 
Python
using the standard library's sqlite3 module.

If the data is dynamic however because it is being changed by other sources, 
you'll have
to use a third party library to get to it I think


Irmen
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: When will os.remove fail?

2017-03-14 Thread eryk sun
On Tue, Mar 14, 2017 at 7:01 PM, Grant Edwards
 wrote:
>
> 1. I think I can see the VMS heritage of Windows shining through.

That's not surprising considering that VMS and NT have the same
architect -- Dave Cutler -- and that I/O system and file systems were
design by former DEC programmers that he brought with him, such as
Darryl Havens and Gary Kimura. The old joke is that WNT = VMS + 1.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python and databases

2017-03-14 Thread Michael Torrie
On 03/14/2017 01:59 PM, Xristos Xristoou wrote:
> I have a database in  microsoft ACCESS with about 150 records.. if I
> want to get some data from this database using  a query in python and
> i want to store in some variables in python that will do this ? to
> avoid the 150 if ...: Using the standard library the python? know
> easily put it an SQL query but i canot use additional library
> python.

If you simply want to move data to an sql server, your best bet is to
use mdbtools to dump the database schema and records out to an .sql file
that you can then massage and import into whatever sql server you are
using.

https://github.com/brianb/mdbtools

If you're looking for a way to use the access file directly, and
continue using it in MS Access, you might be able to get the odbc bridge
working (on windows of course), and communicate with it with pyodbc.
-- 
https://mail.python.org/mailman/listinfo/python-list


Open SourceCraft Interview w/Python Instructor Trey Hunner

2017-03-14 Thread Christina Lugo

Hello,

*I wanted to let you know about an interview I just published on Open 
SourceCraft with Trey Hunner, who worked his way from a freelance Python 
dev to a Python instructor.  He also runs weekly free Python chat where 
he discusses Python, teaching, open source, and more.  Here is the link 
to his interview:*


*http://codepop.com/open-sourcecraft/episodes/trey-hunner/*

*Thanks so much! *

*Christina Lugo*

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


Re: When will os.remove fail?

2017-03-14 Thread eryk sun
On Tue, Mar 14, 2017 at 10:05 PM, Dennis Lee Bieber
 wrote:
> On Wed, 15 Mar 2017 00:07:32 +1100, Chris Angelico 
>
>>Yes, but you can't always control the process that opens them. For
>>example, it's annoyingly difficult to update a running executable.
>>
> I wouldn't be surprised if Windows mmap()'s running executables into
> swap space, rather than actually swapping in-core image to the normal swap
> file.

Executables are memory mapped, and this also applies to memory-mapped
data files (i.e. CreateFileMapping / MapViewOfFile) like with Python's
mmap module. Notice how the fastfat driver's function that sets the
delete disposition, FatSetDispositionInfo [1], has to check for this
by calling the kernel memory-manager function MmFlushImageSection [2]
(note that a flush type of MmFlushForDelete also checks the number of
views of the data section). If the mapped view prevents deleting the
file it returns STATUS_CANNOT_DELETE. This status code gets translated
to the Windows error code ERROR_ACCESS_DENIED, for which Python raises
a PermissionError. This is misleading because you were probably
granted delete access. The file just can't be deleted.

Typically you can still open such files with delete access to allow
renaming (relinking) them to another directory on the volume. You're
just not allowed to unlink them.

[1]: 
https://github.com/Microsoft/Windows-driver-samples/blob/master/filesys/fastfat/fileinfo.c#L2417
[2]: https://msdn.microsoft.com/en-us/library/ff549808

It's also interesting that the sharing mode is special cased. Normally
if write access isn't shared you're denied the right to open the file
with either write or append access. But with executables mapped by the
loader, you can still open them for append access.

The C runtime's POSIX (low) I/O layer has its own implementation of
append mode that requires opening the file with both write and append
access (O_WRONLY | O_APPEND), which is what Python's "a" mode uses. So
you have to call CreateFile directly to get append-only access. For
example, using a virtual environment copy of python.exe:

append = 4
h = _winapi.CreateFile(sys.executable, append, 7, 0, 3, 0, 0)
_winapi.WriteFile(h, b'spam')

f = open(sys.executable, 'rb')
f.seek(-4, os.SEEK_END)

>>> f.read()
b'spam'
-- 
https://mail.python.org/mailman/listinfo/python-list