Re: WMI in Python

2010-09-13 Thread KING LABS
On Sep 14, 10:39 am, KING LABS  wrote:
> On Sep 13, 8:31 pm, Jerry Hill  wrote:
>
> > On Mon, Sep 13, 2010 at 8:45 AM, KING LABS  wrote:
> > > Hi All,
>
> > > I am new to programming and python, Being a system administrator I
> > > have chose Inventory (Software & Hardware ) as my first project.
>
> > You'll probably want to look at the python WMI 
> > module:http://timgolden.me.uk/python/wmi/index.html
>
> > as well as the pywin32 module:http://sourceforge.net/projects/pywin32/
>
> > IIRC, there's been quite a bit of discussion about inventorying
> > installed software on the pywin32 mailing 
> > list:http://mail.python.org/mailman/listinfo/python-win32
>
> > --
> > Jerry
>
> Thank you all, I will go through the links provided and suggestions.
> Shall get back to you on this soon.

The following information is exactly what I am trying to collect for
the inventory. I can find vb scripts with googling. I want to do the
same with Python & Win32. Use Server/Client architecture .
Client(agent) updates the information to server.



BIOS:

System serial number, manufacturer, and model
Bios manufacturer, version, and date

Processors:

Type, count (how many of them), manufacturer, speed, and cache

Memory:

Physical memory type, manufacturer, capacity, and slot number
Total physical memory
Total swap/paging memory

Video:

Video adapter: Chipset/model, manufacturer, memory size, speed, and
screen resolution

Display monitor: Manufacturer, description, refresh rate, type, serial
number, and caption

Storage/removable devices:

Manufacturer, model, size, type, speed( all when applicable)

Drive letter, filesystem type, partition/volume size, free space

Network adapters/telephony:

Manufacturer, model, type, speed, and description
MAC and IP address, mask and IP gateway, DHCP server used

Miscellaneous hardware:

Input devices: Keyboard, mouse, and pointing device
Sound devices: Manufacturer name, type, and description
System slots: Name, type, and designation
System ports: Type, name, caption, and description

Software Information: ( from registry & add/remove program )

Operating system: Name, version, comments, and registration info
Installed software: Name, publisher, version (from Add / Remove
software or Programs and Features menu)
Custom-specified registry queries (applicable to Windows OS)

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


Re: WMI in Python

2010-09-13 Thread KING LABS
On Sep 13, 8:31 pm, Jerry Hill  wrote:
> On Mon, Sep 13, 2010 at 8:45 AM, KING LABS  wrote:
> > Hi All,
>
> > I am new to programming and python, Being a system administrator I
> > have chose Inventory (Software & Hardware ) as my first project.
>
> You'll probably want to look at the python WMI 
> module:http://timgolden.me.uk/python/wmi/index.html
>
> as well as the pywin32 module:http://sourceforge.net/projects/pywin32/
>
> IIRC, there's been quite a bit of discussion about inventorying
> installed software on the pywin32 mailing 
> list:http://mail.python.org/mailman/listinfo/python-win32
>
> --
> Jerry

Thank you all, I will go through the links provided and suggestions.
Shall get back to you on this soon.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Frustrating segfaults with Shelf

2010-09-13 Thread Edward Grefenstette
Dear Emile,

Thank you for your response. Upgrading python and starting with a
blank database somehow did the trick!

Best,
Edward

On Sep 13, 7:09 pm, Emile van Sebille  wrote:
> On 9/13/2010 10:05 AM Edward Grefenstette said...
>
> > Dear Pythonistas,
>
> > Below is a simple script that reads relations from a generator
> > (they're just tuples of strings) and attempts to write them to a
> > database. It's simple as hell,
>
> Ecept of course that no one else can test it due to the dependencies.
>
> > and if I simply ignore the database and
> > have it print to stdout by replacing the line "depsDB[str(index)] =
> > rels" with "print rels" it works just fine. However every time I try
> > to run it just inexplicably segfaults. Help, anyone?
>
> There are reported problems with the backend database in pre 2.3 python
> versions.  There are also known problems with shelves being accessed by
> differing versions.
>
> So, I'd start by updating as needed, creating a new repository, then
> testing that.  Once it works, migrate the data over if needed.
>
> If it doesn't work, it'll be tough to help out if narrowing things down
> to a specific reproducible test case is difficult.  Describe the
> debugging techniques you're trying with the results you're getting, and
> we can help contribute with other things to try.
>
> HTH,
>
> Emile

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


Re: Expected bahaviour of os.chroot and os.getcwd

2010-09-13 Thread Lawrence D'Oliveiro
In message , r0g wrote:

> i.e. So do I always have to change directory after changing into a chroot?

When all else fails, read the man page .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: smtplib with Google

2010-09-13 Thread narke
On 2010-09-13, member thudfoo  wrote:
> On Mon, Sep 13, 2010 at 9:20 AM, narke  wrote:
>>
>> Hi,
>>
>> Can anyone please show me a workable example that can let me use
>> google's smtp server to send out a message?  Thanks.
>>
>
> Go here:
>
>   http://code.activestate.com/recipes/langs/python/
>
> and search for this
>
>  gmail

Thanks!

-- 
Life is the only flaw in an otherwise perfect nonexistence
   -- Schopenhauer

narke


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


Re: SendKeys and Python 2.7

2010-09-13 Thread Jakson A. Aquino
On Mon, Sep 13, 2010 at 4:02 PM, Michel Claveau - MVP
 wrote:
> Re!
>
> Sorry for time, but I am very busy...
>
>
> With Python + Pywin32, you can force the activation of a window (before
> send some keys...)
> See:
>  win32gui.SetForegroundWindow(w_handle)
>
> or
>  win32gui.SetActiveWindow(w_handle)
>
>
>
> For to find a windows (and his handle), see:
>  win32gui.EnumWindows()
>  win32gui.GetWindowTex()
> or
>  win32gui.FindWindowEx()

Thanks! I have found a simple workaround: sending Alt+Tab to R
Console. Tomorrow I will test your solution. I can't do it right now
because I don't have a real machine running Windows here.

Best regards,

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


Re: Converting an ugly path to a shell path

2010-09-13 Thread Jerry Hill
On Mon, Sep 13, 2010 at 7:07 PM,   wrote:
> The problem that occurs now is when the user selects an "ugly" path like
> this /home/user/!" §$/.
> The shell don't understand the special chars so i have to escape them with
> "\" .
> Is there a function that does this ?

http://stackoverflow.com/questions/35817/whats-the-best-way-to-escape-ossystem-calls-in-python
seems to cover most of the possibilities.

Particularly, do you really need shell=True?  If not, you can just
call Popen([command, path], stdout=PIPE, stderr=PIPE) and not worry
about it.

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


Re: WMI in Python

2010-09-13 Thread prakash jp
Very true most systems admins requirement range from : knoowing the Service
tag for a given IP to knowing the system harware details such as RAM sizes
etc. This is where Remote Inventory Management comes in handy. There is
vault of already existing vb scripts/perl scripts and batch files. To me it
looks fine if one can create a common interface and link the preexistant
scripts.

Else,

wmi command line can be directly implemented in python through
os.system("COMMAND WMI") so that redistributable python exe be created
through py2exe

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


Re: Newbie question about Python + CouchDB

2010-09-13 Thread James Mills
On Tue, Sep 14, 2010 at 8:59 AM, C3  wrote:

> i was wondering if it is possible to;
>
> 1. capture the HTTP status code for each post
> 2. write logic around that code (such as "skip post if error code was a
> 409")


An appropriate exception should by thrown when it "crashes".

Use an appropriate try/except block to "catch" the exception(s).

cheers
James



-- 
-- James Mills
--
-- "Problems are solved by method"
-- 
http://mail.python.org/mailman/listinfo/python-list


Converting an ugly path to a shell path

2010-09-13 Thread AmFreak

Hi,

im using a QFileDialog to let the user select a path that is used later in  
a command send to the shell like this:


retcode = Popen(command + " " + path, shell=True, stdout = PIPE, stderr =  
PIPE)


The problem that occurs now is when the user selects an "ugly" path like  
this /home/user/!" §$/.
The shell don't understand the special chars so i have to escape them with  
"\" .

Is there a function that does this ?
If there isn't i would use a RegEx but I can't even seem to find a list  
containing all special chars :/


Greetings

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


Newbie question about Python + CouchDB

2010-09-13 Thread C3
Total newbie here - have a quick question

I have a script that takes data in a flat text file, breaks it up and builds a 
CouchDB with all my data - however during the loop in which the data is loaded 
into couchdb - I sometimes get crashes becuase of a duplicate Document ID 
(which in my case is the serial number of a product)

i was wondering if it is possible to;

1. capture the HTTP status code for each post
2. write logic around that code (such as "skip post if error code was a 409")

thanks in advance






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


Re: is there a way to get the encoding of python file

2010-09-13 Thread Thomas Jollans
On Monday 13 September 2010, it occurred to Robert Kern to exclaim:
> On 9/13/10 2:00 PM, Stef Mientki wrote:
> >   On 12-09-2010 19:28, Robert Kern wrote:
> >> On 9/12/10 4:14 AM, Stef Mientki wrote:
> >>>hello,
> >>> 
> >>> Is it possible to get the encoding of a python file from the first
> >>> source line, (if there's any),
> >>> after importing it ( with '__import__' )
> >>> 
> >>> # -*- coding: windows-1252 -*-
> >> 
> >> The regular expression used to match the encoding declaration is given
> >> here:
> >> 
> >> http://docs.python.org/reference/lexical_analysis.html#encoding-declarat
> >> ions
> > 
> > yes, but then I've to read the first line of the file myself.
> > 
> > In the meanwhile I found  another (better ?) solution, (I'm using Python
> > 2.6)
> > 
> > 
> > Place these 2 lines at the top of the file
> > # -*- coding: windows-1252 -*-
> > from __future__ import unicode_literals
> > 
> > or these
> > # -*- coding: utf-8 -*-
> > from __future__ import unicode_literals
> > 
> > then you always get the correct unicode string back.
> 
> Ah. I see. You don't actually need to know the encoding; you just want to
> use literals with raw, unescaped characters embedded in them.
> 
> This may interfere with the cases when you need a real str object.

If you assume that unicode_literals from __future__ works, you can also assume 
that the b'bytestring' syntax works.

> In
> Python 2.x, if you want a unicode literal, just use one like so: u'ß'. As
> long as the encoding declaration is correct, this will work just fine.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a way to get the encoding of python file

2010-09-13 Thread Robert Kern

On 9/13/10 2:00 PM, Stef Mientki wrote:

  On 12-09-2010 19:28, Robert Kern wrote:

On 9/12/10 4:14 AM, Stef Mientki wrote:

   hello,

Is it possible to get the encoding of a python file from the first source line,
(if there's any),
after importing it ( with '__import__' )

# -*- coding: windows-1252 -*-


The regular expression used to match the encoding declaration is given here:

http://docs.python.org/reference/lexical_analysis.html#encoding-declarations


yes, but then I've to read the first line of the file myself.

In the meanwhile I found  another (better ?) solution, (I'm using Python 2.6)


Place these 2 lines at the top of the file
# -*- coding: windows-1252 -*-
from __future__ import unicode_literals

or these
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

then you always get the correct unicode string back.


Ah. I see. You don't actually need to know the encoding; you just want to use 
literals with raw, unescaped characters embedded in them.


This may interfere with the cases when you need a real str object. In Python 
2.x, if you want a unicode literal, just use one like so: u'ß'. As long as the 
encoding declaration is correct, this will work just fine.


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: How Python works: What do you know about support for negative indices?

2010-09-13 Thread Raymond Hettinger
On Sep 10, 2:13 pm, Terry Reedy  wrote:

> Reading the third paragraph out of context, one can miss the restriction
> to built-in objects. I had assumed that the conversion using len(), when
> available, happened prior to the __getitem__ call.

Yes, that's a common misconception.  It is probably based on
the current wording of the docs and on the PySequence_GetItem()
optimized fast-path for builtin and extension sequences.

>From the users point-of-view, the important thing is that it
(effectively) occurs in the __getitem__() code, that builtin
sequences and extensions support it, and that else where it is
optional.

Another way of saying it is:  if you are ever writing a __getitem__()
method in Python (even for a subclass of a builtin sequence), then it
is up to you to decide whether to add support for negative indices
and slicing.


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


Re: SendKeys and Python 2.7

2010-09-13 Thread Michel Claveau - MVP
Re!

Sorry for time, but I am very busy...


With Python + Pywin32, you can force the activation of a window (before
send some keys...)
See: 
  win32gui.SetForegroundWindow(w_handle)

or
  win32gui.SetActiveWindow(w_handle)



For to find a windows (and his handle), see:
  win32gui.EnumWindows()
  win32gui.GetWindowTex()
or 
  win32gui.FindWindowEx()


@-salutations
-- 
Michel Claveau 


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


Re: business date and calendar libraries?

2010-09-13 Thread David Robinow
On Mon, Sep 13, 2010 at 1:06 PM, Chris Withers  wrote:
> I'm wondering what libraries people would use to answer the following
> questions relating to business days:
>
> - on a naive level; "what's give me the last business day" (ie: skipping
> weekends)
import datetime
def is_weekend(year, month, day):
return datetime.date(year, month, day).weekday() in (5,6)

That should get you started.

> - on a less-naive level; same question but taking into account public
> holidays
 This depends on which government is oppressing you.
>
> - on a horrific level; same question, but taking into account business days
> of a particular market (NYSE, LSE, etc)
 This is just an instance of the public holiday case. You need to
define the holidays.
 If you read lisp you might want to look at the emacs calendar module
for some hints on how they describe holidays, such as, for a US-biased
example,  Martin Luther King day is the third Monday in January,
Memorial Day is the last Monday in May, Good Friday is not a public
holiday but some markets are closed.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a way to get the encoding of python file

2010-09-13 Thread Stef Mientki
 On 12-09-2010 19:28, Robert Kern wrote:
> On 9/12/10 4:14 AM, Stef Mientki wrote:
>>   hello,
>>
>> Is it possible to get the encoding of a python file from the first source 
>> line,
>> (if there's any),
>> after importing it ( with '__import__' )
>>
>> # -*- coding: windows-1252 -*-
>
> The regular expression used to match the encoding declaration is given here:
>
> http://docs.python.org/reference/lexical_analysis.html#encoding-declarations
>
yes, but then I've to read the first line of the file myself.

In the meanwhile I found  another (better ?) solution, (I'm using Python 2.6)


Place these 2 lines at the top of the file
# -*- coding: windows-1252 -*-
from __future__ import unicode_literals

or these
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

then you always get the correct unicode string back.

thanks,
Stef
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: From IDL to Python

2010-09-13 Thread kBob
On Sep 13, 9:58 am, Chris  wrote:
> Hi,
>
> I'm an IDL user since years and try now to learn Python since a few
> days.
> I'm blogging the various steps of this transition 
> to:http://idl2python.blogspot.com/
> I hope that other IDL switchers can help me by commenting on the blog
> and helping (me and others) to learn quickly the basics of Python.
> Cheers,
> Christophe

I have been using IDL and ENVI for years and started working with
Python this summer. Mostly, as I find myself working with ArcGIS users
and Python is popular among this group. I couldn't convinced them that
IDL/ENVI was easier.

Did my first "widget" with Python/Tkinter, which does require more
work. Still can't get my Python version of the Widget/Hourglass to
work correctly. However, you see, you may have to rebuild those IDL
routines your so use to using in IDL.

However, some areas are alot easier with Python like XML and Net URL
stuff (working on OGC WMS and WFS project). There is plenty of
examples to help you out.

Maybe I should start my own blog spot, just to share my experiences.

Kelly Dean
Milliken, CO

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


PIL : "The _imaging C module is not installed"

2010-09-13 Thread Michel Claveau - MVP
Hello!

(*** sorry for my bad english***)


I have the message (title), but only with PIL 1.1.7 (Windows XP, Vista 
or 7 (32 bits or 64 bits)).

I tried:

 _imaging.pyd  exist in C:\Python26\Lib\site-packages\PIL
OK

 python -v
 >>> import Image
OK

 sys.path contain C:\Python26\Lib\site-packages\PIL
OK


 python
 >>> import _imaging
OK


I tested on more than 6 computers, with new installations, or update 
installations. Same problem.
Same problem, also, with Python 2.6 or Python 2.7

If I install again PIL 1.1.6, all scripts run OK.

Then, I install again PIL 1.1.7, the problem returns.


It is the only thing than I wait before update to Python 2.7


One idea?  Thanks in advance.

-- 
Michel Claveau 




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


Re: Expected bahaviour of os.chroot and os.getcwd

2010-09-13 Thread Ian Kelly
On Mon, Sep 13, 2010 at 12:04 PM, r0g  wrote:

> i.e. So do I always have to change directory after changing into a chroot?
>

Yes, as documented in the man page for the chroot system call:

This call changes an ingredient in the pathname resolution process and does
> nothing else.
>
> This call does not change the current working directory, so that after the
> call '.' can be outside the tree rooted at '/'. In particular, the superuser
> can escape from a 'chroot jail' by doing 'mkdir foo; chroot foo; cd ..'.
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How Python works: What do you know about support for negative indices?

2010-09-13 Thread Raymond Hettinger
[Ben Finney]
> I encourage anyone whose messages are munged like that to seek
> correction from their mail service provider, and switch to a different
> one until it's fixed.

The post was typed on a mobile device into the text window on Google
Groups.

It's too bad that inane concerns with newline placement overwhelmed
the substance of the post.


Raymond



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


Re: Frustrating segfaults with Shelf

2010-09-13 Thread Emile van Sebille

On 9/13/2010 10:05 AM Edward Grefenstette said...

Dear Pythonistas,

Below is a simple script that reads relations from a generator
(they're just tuples of strings) and attempts to write them to a
database. It's simple as hell,


Ecept of course that no one else can test it due to the dependencies.


and if I simply ignore the database and
have it print to stdout by replacing the line "depsDB[str(index)] =
rels" with "print rels" it works just fine. However every time I try
to run it just inexplicably segfaults. Help, anyone?


There are reported problems with the backend database in pre 2.3 python 
versions.  There are also known problems with shelves being accessed by 
differing versions.


So, I'd start by updating as needed, creating a new repository, then 
testing that.  Once it works, migrate the data over if needed.


If it doesn't work, it'll be tough to help out if narrowing things down 
to a specific reproducible test case is difficult.  Describe the 
debugging techniques you're trying with the results you're getting, and 
we can help contribute with other things to try.


HTH,

Emile

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


Expected bahaviour of os.chroot and os.getcwd

2010-09-13 Thread r0g

Hi CLP!

Not been here for ages, I hope everyone is doing well :)

I just want to check if this is the intended behaviour (2.2 to 2.7)...


import os
print os.getcwd()
os.chroot("/home/r0g/whatever/")
print os.getcwd()
os.chdir("/")
print os.getcwd()



/home/r0g/AAA_BACKED_UP/Code/py
/home/r0g/AAA_BACKED_UP/Code/py
/


i.e. So do I always have to change directory after changing into a chroot?

The reason I ask is because an app I was running inside the chrooted 
environment (specifically: apt-get) was trying to access files outside 
the chroot and erroring when it couldn't. I figured it must be doing a 
getcwd() and getting the cwd of the script that initialized the chroot. 
I just wanted to confirm that's how it's supposed to work so I'd 
appreciate it if anyone either knows or can point me to the docs that 
explain in more detail than http://docs.python.org/library/os.html


Also, out of curiosity... If it does work (and should work) the way I 
think it does how come os.chroot doesn't set the cwd to "/" for you? 
It's not a costly operation and it could prevent errors of ignorance 
such as my own. Are there any good reasons why a person (who isn't a 
hacker / cracker / kludger) would want chrooted processes to be able to 
see the calling script's cwd anyway? Maybe I'm having a failure of 
imagination today but the only things I can think that info could be 
useful for are jailbreaking, nefarious reconnaissance and real ugly 
hacks. Maybe someone here can enlighten me :)


Yours curiously,

Roger Heathcote



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


Re: smtplib with Google

2010-09-13 Thread member thudfoo
On Mon, Sep 13, 2010 at 9:20 AM, narke  wrote:
>
> Hi,
>
> Can anyone please show me a workable example that can let me use
> google's smtp server to send out a message?  Thanks.
>

Go here:

  http://code.activestate.com/recipes/langs/python/

and search for this

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


Frustrating segfaults with Shelf

2010-09-13 Thread Edward Grefenstette
Dear Pythonistas,

Below is a simple script that reads relations from a generator
(they're just tuples of strings) and attempts to write them to a
database. It's simple as hell, and if I simply ignore the database and
have it print to stdout by replacing the line "depsDB[str(index)] =
rels" with "print rels" it works just fine. However every time I try
to run it just inexplicably segfaults. Help, anyone?

Best,
Edward



from WNvectorBuilder import relBuilder
import sys
import cPickle as pickle
import shelve

def main(argv):

## read filenames from command line arguments
depsFile = open(argv[1])
lemmaFile = open(argv[2])
depsDB = shelve.open(argv[3],"c")

## load lemma dictionary from lemma file
lemmaDict = pickle.load(lemmaFile)

## index of database entries
index = 0

## read relations from relation generator, write each relation to
database under new index
for rels in relBuilder(depsFile,lemmaDict):
index += 1
depsDB[str(index)] = rels
del rels

if __name__ == '__main__':
main(sys.argv)


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


business date and calendar libraries?

2010-09-13 Thread Chris Withers

Hi All,

I'm wondering what libraries people would use to answer the following 
questions relating to business days:


- on a naive level; "what's give me the last business day" (ie: skipping 
weekends)


- on a less-naive level; same question but taking into account public 
holidays


- on a horrific level; same question, but taking into account business 
days of a particular market (NYSE, LSE, etc)


cheers,

Chris

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


Re: reddit = porn fodder

2010-09-13 Thread namekuseijin

Xah Lee escreveu:

reddit = porn fodder

Didn't realize, but Reddit is now a porn fodder.

http://www.reddit.com/r/LegalTeens/
http://www.reddit.com/r/highheels
http://www.reddit.com/r/gonewild/

Its traffic also seems to incleased 10 times since 2008. See: Computer
Language Websites Popularity.

From my experience, if you just add one page that is remotely related
to sex, that page's traffic will eclipse your other hundred pages

[snip]

note that reddit was originally somewhat a site for programers,
written in common lisp.


guess the lesson here is that Python is more sexy than Lisp. :p

--
a game sig: http://tinyurl.com/d3rxz9

--- news://freenews.netfront.net/ - complaints: n...@netfront.net ---
--
http://mail.python.org/mailman/listinfo/python-list


smtplib with Google

2010-09-13 Thread narke
Hi,

Can anyone please show me a workable example that can let me use
google's smtp server to send out a message?  Thanks.

-- 
Life is the only flaw in an otherwise perfect nonexistence
   -- Schopenhauer

narke


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


From IDL to Python

2010-09-13 Thread Chris
Hi,

I'm an IDL user since years and try now to learn Python since a few
days.
I'm blogging the various steps of this transition to: 
http://idl2python.blogspot.com/
I hope that other IDL switchers can help me by commenting on the blog
and helping (me and others) to learn quickly the basics of Python.
Cheers,
Christophe
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: palindrome iteration

2010-09-13 Thread Cousin Stanley

> To deal with "real" palindromes such as, "Madam, I'm Adam," 
> you should probably strip all spaces and punctuation:
>
> # untested
> pat = re.compile(r'[a-z]')
> def is_palindrome(s):
> letters = pat.findall(s.lower())
> return letters == reversed(letters)

  Using python 2.5 the above solution always returned False
  for me until the  reversed( letters )  iterator was explicitly
  coerced into a list  

return letters == list( reversed( letters ) ) 
 

-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

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


Re: Python script for MySQL Passwords Unreliable on first boot (rc.local)

2010-09-13 Thread Thomas Jollans
On Monday 13 September 2010, it occurred to cloudcontrol to exclaim:
> The script below works great when logged in as root and run from the
> command line, but when run at first boot using /etc/rc.local in Ubuntu
> 10.04, it fails about 25% of the time- the system root, mysql root and
> some mysql user passwords are set correctly, but one will fail with
> console log reporting standard mysql login error: "ERROR 1045 (28000):
> Access denied for user 'root' @ 'localhost' (using password: YES)"

It looks like MySQL itself isn't properly set up (yet) in those cases. But 
why/how?

Ubuntu uses upstart to boot up. I don't know much about how this works, but I 
understand it's dependency-based, and I expect it's parallel as well, where 
possible. This means that different init scripts could run in a different 
order sometimes, or even at the same time.

However, rc.local should really always be run last. It does not, by and of 
itself, specify any dependencies, but it could require anything. It would be 
ludicrous for Ubuntu to run rc.local before or at the same time as other 
scripts, such as the MySQL one. The only plausible explanation for this 
strange behaviour I can think of right now would be that either
 a) Upstart/Ubuntu is just plain stupid, or
 b) The MySQL init script spawns MySQL in the background and doesn't wait for
it to start up correctly. This seams highly unlikely and atypical of MySQL
init scripts, but maybe that's what's happening.
So this might be a bug in Ubuntu.

The way to fix this might simply be to detect the login error and retry, say, 
5 times with 1-second intervals. 

> 
> Is there something about running python scripts from init jobs that I
> should account for, such as an environment variable?
> 
> #!/usr/bin/env python
> 
> # Udates system & MySQL root passwords on first boot
> files = ['/home/ubuntu/passwords','/opt/data1/alfresco/extensions/
> extension/alfresco-global.properties','/opt/data/etc/mysql/
> debian.cnf','/home/ubuntu/duncil']
> userpasswords = {'root':'ROOTPASSWORD'}
> mysqlpasswords =
> {'root':'MYSQLPASSWORD','alfresco':'alfrescoPASSWORD','debian-sys-
> maint':'debian-sys-maintPASSWORD'}
> otherpasswords = ['OTHERPASSWORD']
> log = '/var/log/firstrun'
> 
> import random, string
> import crypt
> import re
> from subprocess import PIPE, Popen
> 
> def getsalt(chars = string.letters + string.digits):
> # generate a random 2-character 'salt'
> return random.choice(chars) + random.choice(chars)
> 
> def getpwd(chars = string.letters + string.digits, len = 12):
> retval = "";
> for i in range(0, len):
> # generate 12 character alphanumeric password
> retval += random.choice(chars)
> 
> return retval
> 
> def replace_pass(filename):
> handle = open(filename, 'r')
> hbuf = handle.read()
> handle.close()
> for placeholder, password in pdict.iteritems():
> hbuf = re.sub(placeholder, password, hbuf)
> 
> try:
> # Output file
> handle = open(filename, 'w')
> handle.write(hbuf)
> handle.close()
> except:
> pass
> #logh.write('failed to update ' + filename  + "\n")
> #logh.write('maybe you don\'t have permision to write to it?
> \n')
> 
> logh = open(log, "a")
> logh.write("Starting...\n")
> # Generate passwords
> pdict = {}
> for user, placeholder in userpasswords.iteritems():
> syspass = getpwd()
> Popen(['usermod', '--password', crypt.crypt(syspass, getsalt()),
> user])
> logh.write(placeholder + ": User " + user + " --> " + syspass +
> "\n")
> pdict[placeholder] = syspass
> 
> # What's the MySQL Root password placeholder?
> mplace = mysqlpasswords['root']
> for user, placeholder in mysqlpasswords.iteritems():
> mpass = getpwd()
> if (("root" in mysqlpasswords) and (mysqlpasswords['root'] in
> pdict)):
> mrootpass = pdict[mysqlpasswords['root']]
> else:
> mrootpass = ""
> 
> Popen(['mysql', '-uroot', "--password=" + mrootpass, "-e", "UPDATE
> user SET Password = PASSWORD('" + mpass + "') WHERE User = '" + user +
> "';FLUSH PRIVILEGES;","mysql"])
> logh.write(placeholder + ": MySQL " + user + " --> " + mpass +
> "\n")
> pdict[placeholder] = mpass
> 
> for placeholder in otherpasswords:
> opass = getpwd()
> logh.write(placeholder + ": " + opass + "\n")
> pdict[placeholder] = opass
> 
> # Update passwords
> for file in files:
> logh.write("Replacing placeholders in " + file + "\n")
> replace_pass(file)
> 
> logh.write("Finished\n")
> logh.close
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: WMI in Python

2010-09-13 Thread Jerry Hill
On Mon, Sep 13, 2010 at 8:45 AM, KING LABS  wrote:
> Hi All,
>
> I am new to programming and python, Being a system administrator I
> have chose Inventory (Software & Hardware ) as my first project.

You'll probably want to look at the python WMI module:
http://timgolden.me.uk/python/wmi/index.html

as well as the pywin32 module: http://sourceforge.net/projects/pywin32/

IIRC, there's been quite a bit of discussion about inventorying
installed software on the pywin32 mailing list:
http://mail.python.org/mailman/listinfo/python-win32

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


Re: [Tutor] Arguments from the command line

2010-09-13 Thread Giacomo Boffi
Dennis Lee Bieber  writes:

> On Fri, 10 Sep 2010 12:25:17 +0200, Giacomo Boffi
>  declaimed the following in
> gmane.comp.python.general:
>
>> Lawrence D'Oliveiro  writes:
>> 
>> > In message <8662yfklzu@aiuole.stru.polimi.it>, Giacomo Boffi wrote:
>> >
>> >> Dennis Lee Bieber  writes:
>> >> 
>> >>> FORTRAN just differentiates by having the main file start with
>> >>> PROGRAM random_name
>> >>> whereas subfiles are all either (or both)
>> >>> SUBROUTINE another_name(args)
>> >>> FUNCTION that_other_name(args)
>> >> 
>> >> no BLOCKDATA?
>> >
>> > I think you mean COMMON.
>> 
>> i meant BLOCKDATA
>
>   It exists but I've only seen it used once... And I don't recall it
> being "executable" in the same way as program/function/subroutine.

i simply meant that the BLOCKDATA statement can begin a subfile as
well as SUBROUTINE or FUNCTION
-- 
Sarò un'ingenua ma continuo a pensarla come prima, anche se
probabilmente i fatti mi smentiscono.  -- Francy, in IHC
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: WMI in Python

2010-09-13 Thread Aahz
In article ,
KING LABS   wrote:
>
>I would like to collect the complete information of system hardware &
>and also software  installed from registry and add/remove program and
>feed this data into database.

You should subscribe to the win32 mailing list:

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

Before you ask questions there, do a bit of searching first -- there are
lots of examples.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

[on old computer technologies and programmers]  "Fancy tail fins on a
brand new '59 Cadillac didn't mean throwing out a whole generation of
mechanics who started with model As."  --Andrew Dalke
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for Python and Python/Django workplaces in Chicago

2010-09-13 Thread Aahz
In article <894aa094-70c8-4c0e-b2c6-f2b783f68...@l20g2000yqe.googlegroups.com>,
Erik Reppen   wrote:
>
>I'm a really strong front end web dev with an interest in becoming
>more of a generalist web and app dev through Python. Anybody aware of
>studios/agencies that actually prefer Python in Chicago I could keep
>an eye on.

Nobody else has responded, so I'll just refer you to the usual job
boards, including

http://www.python.org/community/jobs/
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

[on old computer technologies and programmers]  "Fancy tail fins on a
brand new '59 Cadillac didn't mean throwing out a whole generation of
mechanics who started with model As."  --Andrew Dalke
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static typing, Python, D, DbC

2010-09-13 Thread Paul Rubin
Bearophile  writes:
> But in some situations you want a faster final program. Running the
> run-time contracts only when you test the code and removing them when
> you run the program for real sounds silly or dangerous. But life is
> made of trade-offs, and running those contracts during testing is
> better than _never_ running them. 

For some programs, having the contracts fail during running "for real"
is intolerable, so if you're not ready to remove the runtime tests, then
program is not ready to run for real.

The Wikipedia article about DBC

   http://en.wikipedia.org/wiki/Design_by_contract

makes it sound like what I thought, the preferred enforcement method is
static, but runtime testing can be used as a fallback.  I'm pretty sure
Eiffel itself comes with static DBC tools.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: WMI in Python

2010-09-13 Thread Ed Leafe
On Sep 13, 2010, at 9:51 AM, KING LABS wrote:

> I am trying to learn Python programming. Since I need a custom
> inventory management tool for my work place. I am considering it as a
> project in the process of learning Python.
> 
> I am not looking for easiest way of doing things.
> I am considering using Python . Also I would need to build a setup of
> the tool for easy installation.
> 
> Hope I am clear this time


If you're looking for a rich client (i.e., desktop) application, and 
not a web app, you should check out Dabo: http://dabodev.com. We have hundreds 
of developers around the world using Dabo to build many different kinds of 
business applications.


-- Ed Leafe



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


Re: WMI in Python

2010-09-13 Thread KING LABS
On Sep 13, 6:42 pm, Rodrick Brown  wrote:
> The easiest way to do this is to use the native OS tools readily available to 
> do the collection and log to a central location or if possible shared 
> location accessible by all systems, once you have all the data you want to 
> feed into your RDBMS you could easily parse these logs using python and the 
> native db access module.
>
> I hope this give you a pointer.
>
> Sent from my iPhone 4.
>
> On Sep 13, 2010, at 8:45 AM, KING LABS  wrote:
>
>
>
> > Hi All,
>
> > I am new to programming and python, Being a system administrator I
> > have chose Inventory (Software & Hardware ) as my first project.
>
> > I would like to know experts advice on the best way to build the same
> > using python. I would like to this tool to evolve into full fledge
> > application.
>
> > I would like to collect the complete information of system hardware &
> > and also software  installed from registry and add/remove program and
> > feed this data into database.
>
> > Regards,
> > KINGLABS
> > --
> >http://mail.python.org/mailman/listinfo/python-list

I am trying to learn Python programming. Since I need a custom
inventory management tool for my work place. I am considering it as a
project in the process of learning Python.

I am not looking for easiest way of doing things.
I am considering using Python . Also I would need to build a setup of
the tool for easy installation.

Hope I am clear this time

Regards,
KINGLABS
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: WMI in Python

2010-09-13 Thread Rodrick Brown
The easiest way to do this is to use the native OS tools readily available to 
do the collection and log to a central location or if possible shared location 
accessible by all systems, once you have all the data you want to feed into 
your RDBMS you could easily parse these logs using python and the native db 
access module. 

I hope this give you a pointer.

Sent from my iPhone 4.

On Sep 13, 2010, at 8:45 AM, KING LABS  wrote:

> Hi All,
> 
> I am new to programming and python, Being a system administrator I
> have chose Inventory (Software & Hardware ) as my first project.
> 
> I would like to know experts advice on the best way to build the same
> using python. I would like to this tool to evolve into full fledge
> application.
> 
> I would like to collect the complete information of system hardware &
> and also software  installed from registry and add/remove program and
> feed this data into database.
> 
> Regards,
> KINGLABS
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Dabo 0.9.3 released

2010-09-13 Thread Ed Leafe
It's been a while, but we've finally released version 0.9.3 of the Dabo 
framework! Since Dabo has a Web Update feature that lets developers receive 
regular updates between releases, the changes won't be too big for most current 
users of the framework, but compared to the 0.9.2 release, lots has been fixed 
and improved! Full release notes are at:
http://svn.dabodev.com/dabo/tags/dabo-0.9.3/ChangeLog

...but here are the major changes since 0.9.2:

- integration of the native Python logging module for all Dabo logging
- support for DES3 cryptography in Dabo encryption
- changed all pathing to be relative to the app's HomeDirectory
- full parameterization of SQL calls
- addition of the dRichTextBox control
- improvement of unicode support with the dabo.lib.ustr() method

You can grab the latest version, as always, from 
http://dabodev.com/download


-- Ed Leafe



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


WMI in Python

2010-09-13 Thread KING LABS
Hi All,

I am new to programming and python, Being a system administrator I
have chose Inventory (Software & Hardware ) as my first project.

I would like to know experts advice on the best way to build the same
using python. I would like to this tool to evolve into full fledge
application.

I would like to collect the complete information of system hardware &
and also software  installed from registry and add/remove program and
feed this data into database.

Regards,
KINGLABS
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hide DOS console for .pyc file

2010-09-13 Thread Jonathan Hartley
On Sep 11, 11:32 am, Lawrence D'Oliveiro  wrote:
> In message , Peter Otten wrote:
>
> > Lawrence D'Oliveiro wrote:
>
> >> In message
> >> <3a2d194c-9b34-4b84-8680-28bdfb53b...@y3g2000vbm.googlegroups.com>, Muddy
> >> Coder wrote:
>
> >>> For a quick testing purpose, I deliver .pyc files to my customer. I
> >>> don't want the black DOS console appearing behind my GUI, but I have
> >>> no idea how to do it. Somebody can help? Thanks!
>
> >> Don’t run it on Windows.
>
> > If you switch the OS for every minor problem you'll run out of operating
> > systems pretty soon...
>
> Not if you choose a suitably flexible and portable one to begin with.



It isn't the OP choosing, it's his client. Now, I dislike aspects of
Windows as much as anybody, but even I can see that dictating which OS
your client is allowed to use if they want to run your program is
sometimes not a viable option.

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


Re: Static typing, Python, D, DbC

2010-09-13 Thread Bearophile
John Nagle:

> All signed Windows 7 drivers must pass Microsoft's static checker,
> which checks that they don't have bad pointers and call all the
> driver APIs correctly.

I didn't know this, thank you. I'll read more about this topic.



Eric S. Johansson:

> If you are careless, assertions can build up to a
> significant percentage of the code base and Slow execution. the argument for
> dealing with this, last time I looked, was that you turn off assertions when
> your code is "running". This logic is flawed because bugs exist and will 
> assert
> themselves at the worst possible time which usually means after you turned off
> the assertions.

These are real problems.

In some situations the code is "fast enough" even with those runtime
tests, so in those situations it's better to keep them active even in
release builds or when you use the program (this is often true for
small script-like programs).

But in some situations you want a faster final program. Running the
run-time contracts only when you test the code and removing them when
you run the program for real sounds silly or dangerous. But life is
made of trade-offs, and running those contracts during testing is
better than _never_ running them. In practice if your tests are done
well enough (they are similar to the real usage of the program), the
contracts are able to catch most of the bugs anyway before the release
build.

The run-time contracts may slow down the code, but there are few ways
to reduce this problem. You have to write your contracts taking care
of not changing the computational complexity of the routine/method
they guard (so you usually don't want to perform a O(n) test for a
routine with O(n ln n) worst-case complexity).

You run your tests often, so if some tests are too much slow you see
it soon and you may fix the problem (the same is true for slow unit
tests).

In D there are several ways to "layer" the work you perform at
runtime, there is not just the release build and test build. You have
the version and debug statements, you may use them inside DbC
contracts too. So in normal test builds I use faster contracts, but if
I spot a bug I lower the debug level and I recompile the D code,
activating heavier tests, to better spot where the bug is. One good
thing of DbC is that when the "density" of presence of contracts in
your programs gets higher of some threshold, most of the bugs present
in the code show themselves up as failed assertions/contracts. To me
it seems related to percolation theory :-) (http://en.wikipedia.org/
wiki/Percolation_threshold ).

In D you may also use enforce(), that's essentially a camouflaged
throw/raise statement, if you use it outside DbC contracts, they are
tests that run even in release builds when your contracts are
disabled.

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Refactoring similar subclasses

2010-09-13 Thread Bruno Desthuilliers

Steven D'Aprano a écrit :
I have some code that currently takes four different classes, A, B, C and 
D, and subclasses each of them in the same way:


class MyA(A):
def method(self, x):
result = super(MyA, self).method(x)
if result == "spam":
return "spam spam spam"
return result
# many more methods overloaded


class MyB(B):
def method(self, x):
result = super(MyB, self).method(x)
if result == "spam":
return "spam spam spam"
return result
# many more methods overloaded



If that's really what your code is doing - I mean, calling the super() 
implementation, checking the result and eventually returning something 
else instead - then a simple decorator might be enough... Could even be 
"applied" by the metaclass.


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


Re: Minimal-D

2010-09-13 Thread Lawrence D'Oliveiro
In message <798a0db8-0ef0-4f35-9427-
b713fec45...@g10g2000vbc.googlegroups.com>, Kruptein wrote:

> On Sep 13, 3:23 am, Lawrence D'Oliveiro 
> wrote:
>
>> In message
>> <383a7e4b-819f-4bdf-9b0c-e22baa9b6...@n7g2000vbo.googlegroups.com>,
>> Kruptein wrote:
>>
>> > Hey I'm creating a program called minimal-d which brings together many
>> > "things" you would otherwise use seperate to develop.  These things
>> > are a file-manager,text-editor,ftp-client and sql-client.
>>
>> We have that already. It’s called a ”Linux distro”.
> 
> Well I didn't know that although I use it perhaps daily?

You didn’t know that all those features are just a checkbox in the package 
manager away?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reddit = porn fodder

2010-09-13 Thread Marc Mientki

Am 13.09.2010 05:14, schrieb Xah Lee:


note that reddit was originally somewhat a site for programers,
written in common lisp.


It is still for Lisp programmers:
http://www.reddit.com/r/lisp/

regards
Marc

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