Locking a file under Windows

2005-11-24 Thread Guy Lateur
Hi all,

I'm working on an application that will be used by several users at the same 
time. The user should be able to both read and write to some data file 
stored on our file server. My question is: how can I prevent that one user 
writes to the file while another user is reading it?

I've seen some info on this in the fcntl module, but this module is not 
available under Windows, so I need something else. Here is what I've come up 
with so far:

def WriteToFile(filename):
for i in range(max_nr_tries):
try:
fd = os.open(filename, os.O_EXCL | os.O_WRONLY)
except OSError, (error, message):
if error == errno.ENOENT:
# create first
try:
fd = os.open(filename, os.O_CREAT | os.O_EXCL | 
os.O_WRONLY)
break
except:
print Oops!
else:
# try again later
time.sleep(1)
continue
time.sleep(20)
# + write  close file

I thought that, when this function gets to the last sleep(), I'd have an 
exclusive lock on the file. However, it seems I can still open the same file 
for reading/writing in another process (even os.O_EXCL).

Is this normal? What am I missing? How can I open a file exclusively (for 
writing)?

Thanks,
g


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


Re: Locking a file under Windows

2005-11-24 Thread Guy Lateur
Thank you, Tim.

The portalocker code seems to prevent reading while the file is locked for 
writing, but it doesn't seem to prevent multiple writes (nor multiple 
exclusive locks, for that matter).

I guess it'd be better if I use the second suggestion, i.e. temporarily 
renaming the file for writing, and renaming it back to unlock it.

Cheers,
g



Tim Golden [EMAIL PROTECTED] schreef in bericht 
news:[EMAIL PROTECTED]

Might be worth looking in the Python Cookbook area. I seem
to remember several recipes to do this kind of thing
cross-platform. eg,

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65203

Also the pywin32 docs come with a flock-style example. Hope
one of the two can help you.

TJG


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


Re: Locking a file under Windows

2005-11-24 Thread Guy Lateur
Correction: it's probably best to use the Flock class by John Nielsen. Much 
cleaner and working great. Info can be found here: 
http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/pywin32/Windows_NT_Files_.2d.2d_Locking.html


Best regards,
g


Guy Lateur [EMAIL PROTECTED] schreef in bericht 
news:[EMAIL PROTECTED]

 I guess it'd be better if I use the second suggestion, i.e. temporarily 
 renaming the file for writing, and renaming it back to unlock it.

 Cheers,
 g


 

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


Obtaining an member function by name

2005-11-19 Thread guy lateur
Hi all,

Suppose you have this class:

class foo:
def bar():

Suppose you also have the strings foo and bar. How can you obtain the 
function foo.bar()?

Surely somebody knows..

TIA,
g


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


Re: Obtaining an member function by name

2005-11-19 Thread guy lateur
Thanks for the feedback, people.

I actually only need the bar part (instance methods). I added the foo 
part to generalize the question without really thinking it through first. 
Still, it has gotten me more information than I ever imagined. So thanks 
again.

g 


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


how to use copy_reg/pickle (was Re: how to pickle unpicklable objects)

2005-09-26 Thread Guy Lateur
Thanks for the swift reply, Hans, and sorry for my delayed reaction.

I've been looking at the copy_reg module, but I can't seem to get it to 
work.

wx.Font has a method called GetNativeFontInfo(), which returns a string 
description of the font. Here's what I had hoped would have worked.

[code]
def reducef(objf):
return str(objf.GetNativeFontInfo())
def constrf(strf):
rv = wx.Font()
rv.SetNativeFontInfo(wx.String(strf))
return rv
copy_reg.pickle(wx.Font, reducef, constrf)
valf = wx.Font(10, wx.NORMAL, wx.NORMAL, wx.NORMAL, False, 'Arial')
rvf = pickle.dumps(valf)
[/code]

Unfortunately, this raises the exception:
pickle.PicklingError: Can't pickle wx._gdi.Font; proxy of C++ wxFont 
instance at _c8bb6101_p_wxFont: it's not found as 
wx._gdi.0;-13;0;0;0;400;0;0;0;1;0;0;0;32;Arial

Like I said, this is how I hoped it would work. I've read in the pickle docs 
you should return the name of a global var containing the value to be 
pickled as usual. I've tried this (without really understanding it), too, 
but without any success.

Could somebody please help me to modify this example so that it works?

Best regards,
g




Hans Georg Krauthaeuser [EMAIL PROTECTED] schreef in bericht 
news:[EMAIL PROTECTED]
 Guy Lateur schrieb:
 Hi all,

 I've been writing an application containing a lot of settings which can 
 be
 changed by the user. I'm using wx.Config to read/write these settings (to
 the windows registry). This means I can only store strings, ints and 
 floats.

 However, it would be very convenient if I could also store more general
 objects. It seems to work for wx.Colour, but not for wx.Font. It raises a
 TypeError: can't pickle PySwigObject objects.

 The object is wrapped by SWIG. So, python can not know anything about it
 and the object can not be pickled.

 As far as I see, there are two possibilities
 - define __getstate__ and __setstate__ in the c/c++-source or the .i
 file (used by swig). This is only possible if the source is available
 - use copy_reg (http://docs.python.org/lib/module-copyreg.html) to
 register a 'reduce' function (I never used that).

 I use the first option in the .i-File for a wrapped c++-class like this:

 %extend UMDMResult {
 %insert(python) %{
 def __getstate__(self):
return (self.v,self.u,self.l,self.unit,self.Z0,self.Eta0,self.t)
 def __setstate__(self,tup):
self.this = _umddevice.new_UMDMResult(tup[0],tup[1],tup[2],tup[3])
self.thisown=1
(self.Z0,self.Eta0,self.t)=[i for i in tup[4:]]
 %}
 }

 regards
 Hans Georg Krauthaeuser 


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


how to pickle unpicklable objects

2005-09-23 Thread Guy Lateur
Hi all,

I've been writing an application containing a lot of settings which can be 
changed by the user. I'm using wx.Config to read/write these settings (to 
the windows registry). This means I can only store strings, ints and floats.

However, it would be very convenient if I could also store more general 
objects. It seems to work for wx.Colour, but not for wx.Font. It raises a 
TypeError: can't pickle PySwigObject objects.

Does anybody a way to get around this? Is there some other module that would 
allow writing general (small) objects to the registry? Some sort of 
serialiser or something?

TIA,
g 


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


Re: Outlook COM: how to create a MailItem from a .msg file

2005-07-08 Thread Guy Lateur
Yes! I finally got it to work. I've written a VBscript which I'll call from 
python. It uses Outlook.Redemption's SafeMailItem. No need to use IMAP or 
whatever services.

Only weird thing is it doesn't put the msg in the Inbox, as I intended, but 
in the Drafts folder. Well, never mind that, it's a temp object anyway.

Here's the code:

Dim sItem, oItem
Dim myDestBox, myNS, myOL

Set myOL = CreateObject(Outlook.Application)
Set myNS = myOL.GetNamespace(MAPI)
Set sItem = CreateObject(Redemption.SafeMailItem)

Set myDestBox = myNS.GetDefaultFolder(6)
Set oItem = myDestBox.Items.Add(0)

sItem.Item = oItem
sItem.Import 
H:\Inhoud-iedereen\Inhoud-Guy\app\BBProject\data\test\Leemarchitect.msg, 3
sItem.Save



Cheers,
g




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


Re: Outlook COM: how to create a MailItem from a .msg file

2005-07-08 Thread Guy Lateur
python version:



import win32com.client

myOL = win32com.client.Dispatch(Outlook.Application)
myNS = myOL.GetNamespace(MAPI)
sItem = win32com.client.Dispatch(Redemption.SafeMailItem)

myDestBox = myNS.GetDefaultFolder(6)
oItem = myDestBox.Items.Add(0)

sItem.Item = oItem
sItem.Import(H:\\Inhoud-iedereen\\Inhoud-Guy\\app\\BBProject\\data\\test\\Leemarchitect.msg,
 
3)
sItem.Save()



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


Re: Outlook COM: how to create a MailItem from a .msg file

2005-07-06 Thread Guy Lateur
Ok, we didn't have the IMAP service running; we do now (no SSL).

Connecting to the server is not a problem anymore, but logging in is. It 
works with the administrator account, but not with my personal account. We 
have restricted access to all machines in 10.0.0.0/255.255.255.0, which 
includes my machine.

My password is empty (yeah, I know..). Could that be the problem? I'm using 
this: pw = ''

Thanks,
g 


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


Re: Outlook COM: how to create a MailItem from a .msg file

2005-07-05 Thread Guy Lateur
Thanks for the suggestion, Tim. Unfortunately, I get a 'connection refused' 
error on the line 'M = imaplib.IMAP4(server)'. It says socket.error: 
(10061, 'Connection refused'). I've tried both the external IP adress and 
the internal one (10.0.0.2). I'm sure there's a way to get over this, isn't 
there?

One more question: can I avoid having (plain text) passwords in my code? I 
guess I could make a special account for this with a password known by 
everybody.

Cheers,
g




Tim Williams (gmail) [EMAIL PROTECTED] schreef in bericht 
news:[EMAIL PROTECTED]

Lateral thinking ?

=== untested ===

import imaplib, time, sys

f = open(msg_file)
r = f.readlines()
f.close()
msg1 = ''.join(r)
server = 'my.exchangeserver.com' # or IP address

user = 'user'
pw = 'pw'

M = imaplib.IMAP4(server)
M.sock.settimeout(120)
M.login(user,pw)[1][0]
M.select()
M.append('INBOX',None ,time.time() , msg1) # Inbox or other folder name
print MESSAGE successfully saved
#M.close()  Don't use close,  deletes/purges items
M.logout()[1][0] 


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


Re: Outlook COM: how to create a MailItem from a .msg file

2005-07-05 Thread Guy Lateur
Are you saying it's unsafe to do that? I only need this for an application 
running locally, I mean, from within our LAN domain. We do have Exchange 
webmail.

I've asked our Exchange expert wether or not IMAP is running; awaiting an 
answer..



Richard Brodie [EMAIL PROTECTED] schreef in bericht 
news:[EMAIL PROTECTED]

 I would have thought most wouldn't run IMAP in the clear;
 over SSL maybe.

 


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


Re: Outlook COM: how to create a MailItem from a .msg file

2005-07-05 Thread Guy Lateur
 I just tried this and it failed with IP addresses but not
 hostnames/machine names,  try it again with the server name. :)

Nope, same problem. I think TJG might be right, and our server probably 
doesn't have IMAP running (yet).



 Depends how secure you need it to be.For my simple stuff I just do
 something like this
 [snip]

That's a nice thought, although the pw is still pretty visible. Maybe 
there's a way to encode/decode it using some sort of key (that only I know), 
that produces a truly unrecognisable pw?

Thanks for the input,
g


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


Re: Outlook COM: how to create a MailItem from a .msg file

2005-07-05 Thread guy lateur

Tim Williams (gmail) [EMAIL PROTECTED] schreef in bericht 
news:[EMAIL PROTECTED]
 Could you SMTP it back in ?   It would gain an extra Received: header
 but the rest of the email would most likely be unaltered.

I don't understand what you mean. How does this have to do with connecting 
to the (probably-not-running) IMAP service?



 Not my area of expertise I'm afraid.If you manually run the script
 then you could use getpass() to prompt you for the password at run
 time.

Not mine either.. ;)
I'd like to avoid having the user type in a pw every time. Outlook doesn't 
seem to need that, so, unless that's unsafe, why should I? Or could I get xp 
to 'remember' it? Btw, Outlook does ask permission if you try to, say, read 
the body of message.

Anyway, the approach I suggested earlier (pw encrypted using key) is 
probably unlikely to solve the security issue, either. I mean, if the key 
itself (or a reference to it) is in my code, then anyone reading that code 
can decrypt it, right?


g



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


Re: Outlook COM: how to create a MailItem from a .msg file

2005-07-05 Thread guy lateur

guy lateur [EMAIL PROTECTED] schreef in bericht 
news:[EMAIL PROTECTED]
|
| Tim Williams (gmail) [EMAIL PROTECTED] schreef in bericht
| news:[EMAIL PROTECTED]
|  Could you SMTP it back in ?   It would gain an extra Received: header
|  but the rest of the email would most likely be unaltered.
|
| I don't understand what you mean. How does this have to do with connecting
| to the (probably-not-running) IMAP service?
|

Hold on, I think I do know what you mean: using SMPT (running) instead of 
connecting to the IMAP service (probably-not-running). I'll let you know how 
I get along with that. I may still need a way to convert a DocumentItem to a 
MailItem, though.

Cheers,
g 


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


Outlook COM: how to create a MailItem from a .msg file

2005-07-04 Thread Guy Lateur
Hi all,

I've been writing some code to move some data into and out of Outlook (2003 
+ Exchange 2003). I have some email .msg files on our file server, and I 
can't seem to get them back into the Outlook object I need, ie a MailItem. 
I've tried to use App.CopyFile() to (temporarily) put the file in an OL 
folder. Problem is, however, this returns a DocumentItem and not a MailItem.

Is there any way I could 'cast' this DItem into a MItem? Apparently, OL 
treats it as any general document - which, btw, shows in the view, too; it 
has another icon and you have to open it to view it). Or maybe there's 
another way to open it; I really only need the object in memory. Any ideas?

TIA,
g


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


Re: Outlook COM: how to create a MailItem from a .msg file

2005-07-04 Thread Guy Lateur
Thanks for the tip, Simon, but unfortunately it doesn't work; it says The 
interface name 'MailItem' does not appear in the same library as object 
'win32com.gen_py.Microsoft Outlook 11.0 Object Library._DocumentItem 
instance at 0x29912600

Anything else I could try?

Cheers,
g




Simon Brunning [EMAIL PROTECTED] schreef in bericht 
news:[EMAIL PROTECTED]

Well, I don't know anything about Outlook's COM interface, so I don't
know if this will work, but you might try win32com.client.CastTo().
Something like:

my_MItem = win32com.client.CastTo(my_DItem, 'MItem')

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/ 


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


Re: Office COM automatisation - calling python from VBA

2005-06-28 Thread guy lateur
Just an update: I've succeeded in writing a COM server, exposing wxPy 
funtcionality. I've also used this object from within Outlook - 2 lines of 
VBA: dispatch COM object  call method. If anyone is interested, I could 
post the source.

A few days ago, I honestly didn't think I'd already be this far by now (it 
took about half a day). Especially the chapter of the book by Mark Hammond 
(my copy of which is being dispatched as we speak) was very helpful.

8)
g 


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


Office COM automatisation - calling python from VBA

2005-06-24 Thread guy lateur
Hi all,

I am trying to write some code (macro's, if you like) to glue together
our Office applications (mainly Word, Excel and Outlook). We have a lot
of different projects going on simultaneously. The idea is to develop a
centralized framework (starting point, common interface) for my users
to view/control their documents/correspondence, on a per project basis.

As an example, I'd like to have a control (button, menu entry) in
Outlook that allows my users to bring up, say, an email for a certain
contact (architect, owner, engineer, ..) on a certain project, with
certain attachments, .. Currently, I have a 'public folder' in OL
(Exchange) that reflects our project structure.

I'll be using COM, and I could probably make an application that
controls Outlook (externally). But I'd also like to have this
functionality exposed in OL itself. So I guess I'll need to use VBA,
but I don't really like VBA - relax, please, it's just an opinion.. ;)

So, ideally, I'd like to program as much as possible in python (I'm
pretty new to that, too, btw), and only use VBA if needed - say, to
call python objects/methods (+ wxGUI, please).


Would that be an easy, a hard, or an insane strategy? Maybe there are
some tutorials on this (searched the list, but didn't quite find any).
If anyone happens to have any xp/tips on this, please, fire away!


Best regards,
g

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


Re: Office COM automatisation - calling python from VBA

2005-06-24 Thread guy lateur
 You want to use --- Python ???

So far I haven't been informed of any serious arguments as to why I
wouldn't.


 How, pray tell, do you add  up (VBA+VBA+VBA+VBA+VBA)  and have it come out
 equaling Python?

My total was this: 57*python + wxPython.


 Do you think that might please a few of us here in this
 particular newsgroup?

Yes.

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


Where is Word - COM solution

2005-06-23 Thread Guy Lateur
Hi all,

This goes back to my previous post called Where is Word. In short, I 
wanted to make a temporary file (directory listing), open it in Word to let 
the user edit, layout and print it, and then delete the temp file 
afterwards.

I almost got it to work without using COM, but there was a problem when the 
user runs the script a second time without closing Word after the first 
time. In that case, the temp file could not be deleted (see original post).

Luckily, the following code was provided to me by a good fellow named 
Hughes, Chad O. Thanks again for your time and effort on this, Chad!


code
import os
from win32com.client import Dispatch

dirlist = os.listdir(os.getcwd())

word = Dispatch('Word.Application')
word.Documents.Add(Visible = True)
word.Visible = True

for line in dirlist:
  word.Selection.TypeText(line + '\r\n')
/code


So the questions 'where is Word' and 'how to delete the temp file' have 
become obsolete. Nice, eh? COM rules!

Cheers,
g






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


List of all installed applications (XP)?

2005-06-23 Thread Guy Lateur
Hi all,

I'm trying to generate a (exhaustive) list of all the applications that are 
installed on a user's machine. I've written some code that reads the 
registry ('App Paths'):

code
appKey = win32api.RegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, 
'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths', 0, win32con.KEY_READ)
sklist = win32api.RegEnumKeyEx(appKey)

for skey in sklist:
 print skey[0]

 try:
  wPath = win32api.RegQueryValue(appKey, skey[0])
  print '' + wPath
 except pywintypes.error,details:
  print '### Error [pywintypes.error]: ' + details[2]

win32api.RegCloseKey(appKey)
/code

This works, but I was wondering wether that is the best way to go about 
this? Can I be sure it lists *all* the applications? What does it mean when 
a pywintypes.error is thrown (code 13, 'Invalid data')?

Thanks,
g



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


Re: List of all installed applications (XP)?

2005-06-23 Thread Guy Lateur
| What -- from your point of view -- is an application?

Good question. Let me try to elaborate: I would like to know if people in 
our company (building techniques) are using non-licensed software (eg 
Photoshop, Office, AutoCad). So I guess by 'application' I mean commercial 
software packages like those.

Is it safe to assume those apps get listed in AppPath? I don't think my 
users are cunning enough to mess with the registry, so I guess we're talking 
about the 'standard' installation.



| Neither does every app have an Add/Remove Program
| entry. (And some things have entries which aren't apps).

Just out of curiosity: can one read the info/list one gets in Add/Remove 
Programs? It's not a problem I get results that aren't actually apps, but it 
is important I get all apps.



Thanks,
g




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


Re: List of all installed applications (XP)?

2005-06-23 Thread guy lateur
| [TJG]
| Hmmm. While I understand your requirement, it's not as
| thought there's some easily-discernible charactersistics
| of commercial software packages which should have licenses
| but which don't

No? Really? How disappointing.. ;)


| [TJG]
| By the sound of it, you're almost better off compiling
| a list of .exe from machines and building up a blacklist
| from those.

That was kind of the idea at first. However, we have a file server (H:), and 
I've seen apps installed on it. So it's pretty hard to know who actually 
uses that app just by the .exe - could be several people, too, I guess. 
That's why I thought of the registry - which, as you rightfully pointed out, 
isn't a perfect strategy, either.

I do understand that I can remove those apps by removing the .exe (+ 
containing folder, probably), but I'd also like to get an idea of who is 
using what right now (and why). That might come in handy at some point later 
on. Btw, is there a module called pyWhy or something? :)

Maybe I should also follow Paul's advice and go through the registry on a 
vendor/app basis. I mean, ATM, I'm not really concerned about a user having, 
say, Cubase installed without a license. My priority right now is to make 
sure we have licenses for certain apps we use professionally/commercially 
(ACad, Office, ..).


Thanks for the input, people, much appreciated,
g


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


Re: Where is Word?

2005-06-16 Thread Guy Lateur
Ok, I've tried various proposed solutions, and this is what I've come up 
with:

code
# get Word path
wordKey = win32api.RegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, 
'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths', 0, win32con.KEY_READ)
wPath = win32api.RegQueryValue(wordKey, 'winword.exe')
win32api.RegCloseKey(wordKey)

# open/write tempfile  delete afterwards
fD, fN = tempfile.mkstemp('.txt')
fH = os.fdopen(fD, 'w')
fH.write('blabla')
fH.close()
os.spawnl(os.P_WAIT, wPath, 'winword.exe', fN)
os.remove(fN)
/code


The above seems to work ok, but if you run the script a second time without 
first closing Word(1), the os.spawnl() doesn't seem to block. As a 
consequence, the tempfile is not removed (because Word still has it open 
when os.remove(fN) is called).

Is this behaviour normal? Anything I can do about this?

Thanks,
g


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


Where is Word?

2005-06-14 Thread Guy Lateur
Hi all,

I need a way to get the path where MS Word/Office has been installed. I need 
to start Word from a script (see earlier post), but it doesn't work if I 
don't know its path. So os.system(winword.exe %s % fileName) doesn't 
always work; I need to say os.system(C:\Program Files\Microsoft 
Office\Office10\winword.exe %s % fileName).

Any ideas?

TIA,
g 


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


Re: Where is Word?

2005-06-14 Thread Guy Lateur
Unfortunately, I need to open/edit a (temporary) text file with Word, and 
those are opened by default with UltraEdit (or Notepad or..). Thanks for the 
tip, though.

Anything else? Do I need to read the registry?

g




While this doesn't answer the question you're asking, I
believe it does solve the problem you're facing. Relying
on the fact that the Microsoft Office products will
have associated themselves as the default (Open) action
with files of the appropriate extensions, you can use
os.startfile:

code
import os

os.startfile (c:/temp/blah.doc)
/code

HTH
TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
 


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


Re: Where is Word?

2005-06-14 Thread Guy Lateur
Thanks, but could you pretty please post some code that does this? I'm new 
to Python, let alone COM..

TIA,
g



Tomasz Lisowski [EMAIL PROTECTED] schreef in bericht 
news:[EMAIL PROTECTED]
 You may try to launch Word as a COM object and control it directly from 
 Python using the COM object methods. This does not require you to know the 
 application's path, only the COM object identifier.

 TLis 


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


Re: Where is Word?

2005-06-14 Thread Guy Lateur
Thank you very much; I'll check that out shortly.

g




Tim Golden [EMAIL PROTECTED] schreef in bericht 
news:[EMAIL PROTECTED]
OK, a slightly more intelligent idea in place of my previous
one. You can use win32api.ShellExecute (from the pywin32 extensions)
which is like a beefed-up os.startfile. In particular, it allows
you to pass parameters to the command. So...

code
import win32api
win32api.ShellExecute (
  0, # hwnd
  open, # action; could be print etc.
  winword.exe, # application
  c:/temp/temp.txt, #params
  ., # working directory
  1 # show/don't show
)
/code

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
 


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


Re: Where is Word?

2005-06-14 Thread Guy Lateur
My original post is called Start application  continue after app exits. 
Is there a better way to refer to past posts, btw?

I want to make a temporary file (directory listing), open it in Word to let 
the user edit, layout and print it, and then delete the temp file 
afterwards. I don't think we'll be able to fully automate it, though. The 
user should be able to set her own fonts and stuff.

g



Peter Hansen [EMAIL PROTECTED] schreef in bericht 
news:[EMAIL PROTECTED]
 Guy Lateur wrote:
 I need a way to get the path where MS Word/Office has been installed. I 
 need to start Word from a script (see earlier post),

 (Asking us to refer to some earlier post that may or may not even be 
 available on our news servers isn't the best way to get us the info.  A 
 sentence or two summarizing would work best, I think.)

 Can you describe what the user is going to do after Word pops open with 
 this file in it?  Maybe there are simpler ways to do what you are trying 
 to accomplish, aside from the specific issue of how to open Word itself.

 For example, maybe the work you plan to have the user accomplish can be 
 done automatically by controlling Word with COM.

 -Peter 


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


Re: Where is Word?

2005-06-14 Thread guy lateur

 No, the subject is a good way to refer to past posts.  I just meant
 forcing us to dig back, when the post may no longer even be on our 
 servers, is not helpful.

I agree, my bad.


 (Perhaps I should ask why anyone would want to waste time putting 
 arbitrary fonts and colours and such around a simple directory listing, 
 but I won't. wink)

Please don't.. ;)

g


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


Re: Where is Word?

2005-06-14 Thread guy lateur
Thanks for all the feedback, everyone. What a helpfull community this is! 
It's actually kinda hard keeping up with y'all..

Cheers,
g


Guy Lateur [EMAIL PROTECTED] schreef in bericht 
news:[EMAIL PROTECTED]
 Hi all,

 I need a way to get the path where MS Word/Office has been installed. I 
 need to start Word from a script (see earlier post), but it doesn't work 
 if I don't know its path. So os.system(winword.exe %s % fileName) 
 doesn't always work; I need to say os.system(C:\Program Files\Microsoft 
 Office\Office10\winword.exe %s % fileName).

 Any ideas?

 TIA,
 g
 


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


Re: Start application continue after app exits

2005-06-10 Thread Guy Lateur
This may be getting somewhat OT, but I'd like to dig a little deeper into 
this.

First of all, security (as in some other proces reading/disclosing the data) 
is not an issue in this case. The thing is, though, a user could run the 
script twice, not having closed Word after the first time. So I guess I need 
unique filenames. Am I right in assuming tmpFile = 
tempfile.NamedTemporaryFile() does that automatically?

More generally speaking, I'm not sure it's a question of windows vs linux. I 
often have files open in UltraEdit, which I can then change in some other 
proces. When I reactivate UEdit, it updates (or closes) the file. So maybe 
it loads the file in memory and then closes it, and then opens it again for 
writing. Or something..

To be honest, I don't really understand what it means to have the same file 
open for writing by several processes. You don't want to modify data which 
is already being modified by someone else, do you? I mean, how do you 
determine what changes to apply first, and to what version? Or is the file 
just constantly being overwritten on a first-come-first-served basis?

I may well be completely braindead, here..


g



 All this without having the file is in use errors, because well... only 
 windows has those :-)

 Oh, and btw: you'll notice that gVim is smart enough to notice that the 
 file is no longer there, or that it is there but is more recent than his 
 working copy (if you re-edited with gedit, for example).

 -- 
 Renato
 
 Usi Fedora? Fai un salto da noi:
 http://www.fedoraitalia.org 


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


Re: how to retrieve info about print jobs

2005-06-10 Thread guy lateur
Perhaps I should mention this: we have printers from HP, and they come with 
a tool called JetDirect. This allows you to browse to it and check it's 
status/stats. Maybe I should write something that automatically gathers the 
info from the printer homepage. Would that be a good/easy way to go about 
it?

Alternatively, I could send the info about a user's print jobs from their 
individual pc to a central 'database', and then get it from there.

Just brainstorming out loud, here..


Guy Lateur [EMAIL PROTECTED] schreef in bericht 
news:[EMAIL PROTECTED]
 Hmm, this only seems to work for jobs that originate on the machine 
 running the script. I really need something that actually gathers the info 
 from the printers (net-based). Would that be possible at all?



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


Re: how to retrieve info about print jobs

2005-06-09 Thread Guy Lateur
Hmm, this only seems to work for jobs that originate on the machine running 
the script. I really need something that actually gathers the info from the 
printers (net-based). Would that be possible at all?



Simon Brunning [EMAIL PROTECTED] schreef in bericht 
news:[EMAIL PROTECTED]
On 6/2/05, Guy Lateur [EMAIL PROTECTED] wrote:
 We have several printers in our company network. I would like to know if 
 it
 is possible to check the current print jobs/queues for each of them. That
 way, if a user wants to print something (big), I could give her a hint as 
 to
 which printer would get the job done first. We're using win2k and xp, btw.

You can probably do this with WMI. Ah yes, see
http://www.c-sharpcorner.com/Code/2002/May/IntPrinterQWMI.asp.

You can drive WMI from Python with Tim Golden's WMI module -
http://tgolden.sc.sabren.com/python/wmi.html.

Do let us know what you come up with!

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/ 


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


Start application continue after app exits

2005-06-09 Thread Guy Lateur
Hi all,

I was wondering if it would be possible to launch an application, block 
until the app exits, and do some cleanup afterwards.

Maybe an example will be clearer: I would like to make a temperary (text) 
file, open it with MS Word for the user to edit/layout/print, and then 
delete the temp file after the user shuts down Word. Is this feasible?

Thanks,
g 


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


Re: Start application continue after app exits

2005-06-09 Thread guy lateur
Also note that this method of creating tempfiles is technically unsafe,
as it is theoretically possible that another process would create a file
of the same name in the same directory and then try to use it, resulting
in a race condition between the two processes. This is practically
unlikely, however, and I'm a pragmatist.

I see what you mean, but wouldn't a call to open(fn, 'w') on a filename 
that's in use (for reading or writing) result in an error condition or 
something? I'm a noob, btw.


Thanks for the info, guys, much appreciated. I'll try it soon (on XP) - I'm 
a pragmatist, too, you see.. 


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


how to retrieve info about print jobs

2005-06-02 Thread Guy Lateur
Hi all,

We have several printers in our company network. I would like to know if it
is possible to check the current print jobs/queues for each of them. That
way, if a user wants to print something (big), I could give her a hint as to
which printer would get the job done first. We're using win2k and xp, btw.

Any ideas? I'm pretty new to python, I'm afraid..

TIA,
g


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