Re: Is this doable

2008-03-24 Thread Tobiah
> I have a little problem. I have a script that is in the scheduler
> (win32). But every now and then I update this script and I dont want
> to go to every computer and update it.

Can't you just put the script on a network share?

Tobiah

-- 
Posted via a free Usenet account from http://www.teranews.com

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


Re: Is this doable

2008-03-23 Thread Lie
On Mar 22, 1:11 am, MRAB <[EMAIL PROTECTED]> wrote:
> On Mar 21, 11:48 am, fkallgren <[EMAIL PROTECTED]> wrote:> Hi.
>
> > I have a little problem. I have a script that is in the scheduler
> > (win32). But every now and then I update this script and I dont want
> > to go to every computer and update it. So now I want the program to 1)
> > check for new version of the script, 2) if there is a new version,
> > copy that verision from server to local drive, 3) shutdown the program
> > and start it up again as the new version.
>
> > The problem is that I can't run this script directly from server so it
> > have to run it locally.
>
> > Anyone having any bright ideas??
>
> The script could just check to see if the version on the server is
> more recent and if it is then copy it over the local one, start the
> local one, and then quit.
>
> Python compiles the script to bytecode and then interprets the
> bytecode, so when the script is being run the .py or .pyw source
> itself isn't being used and can be overwritten. I've tried the
> following on Windows XP and it works:
>
> (snip)

Even if the .py and .pyw is being locked, you could always use a
helper script that calls the main program if there is no update. This
way, the main program is never called directly, only by the updater
script. Such implementation is trivial.

# updater script
# when you're running your program, you
# call this script instead of the real
# main program
if needupdate():
update()
else:
callmainprogram()

# main program
# this script should never be called
# directly, only by the updater program
# (well, except perhaps on development stage)
def checkupdate():
if needupate():
callupdatescript()
terminateself() # possibly saving state, etc
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this doable

2008-03-22 Thread fkallgren
On Mar 21, 12:48 pm, fkallgren <[EMAIL PROTECTED]> wrote:
> Hi.
>
> I have a little problem. I have a script that is in the scheduler
> (win32). But every now and then I update this script and I dont want
> to go to every computer and update it. So now I want the program to 1)
> check for new version of the script, 2) if there is a new version,
> copy that verision from server to local drive, 3) shutdown the program
> and start it up again as the new version.
>
> The problem is that I can't run this script directly from server so it
> have to run it locally.
>
> Anyone having any bright ideas??
>
> /fkallgren

Thanks everyone. I now have several attack angles to solve this
problem.



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


Re: Is this doable

2008-03-21 Thread Jonathan Gardner
On Mar 21, 4:48 am, fkallgren <[EMAIL PROTECTED]> wrote:
> Hi.
>
> I have a little problem. I have a script that is in the scheduler
> (win32). But every now and then I update this script and I dont want
> to go to every computer and update it. So now I want the program to 1)
> check for new version of the script, 2) if there is a new version,
> copy that verision from server to local drive, 3) shutdown the program
> and start it up again as the new version.
>
> The problem is that I can't run this script directly from server so it
> have to run it locally.
>
> Anyone having any bright ideas??
>

Allow me to differ with all of the previous posts...

Why don't you setup an SVN repository (or Git or DARCS, etc...) that
has the current version you want to run? Then, execute the script in
two steps:

1) Update the local copy from the repository
2) Run the script

The only hard part is writing the script to do the above two things.
Of course, that can be done with a python script (but if you were in
the Unix world, I would suggest a shell script.)

Or you can separate out the two steps. Update the SVN version once a
day, or once and hour, or something like that.

In general, my gut says to avoid writing new code when you can get
away with it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this doable

2008-03-21 Thread Gabriel Genellina
On 21 mar, 15:11, MRAB <[EMAIL PROTECTED]> wrote:
> On Mar 21, 11:48 am, fkallgren <[EMAIL PROTECTED]> wrote:> Hi.
>
> > I have a little problem. I have a script that is in the scheduler
> > (win32). But every now and then I update this script and I dont want
> > to go to every computer and update it. So now I want the program to 1)
> > check for new version of the script, 2) if there is a new version,
> > copy that verision from server to local drive, 3) shutdown the program
> > and start it up again as the new version.
>
> > The problem is that I can't run this script directly from server so it
> > have to run it locally.
>
> > Anyone having any bright ideas??
>
> import os
> import sys
> import shutil
>
> # Is there a newer version?
> my_path = sys.argv[0]
> update_path = os.path.join(os.path.dirname(my_path), "new_script.py")
>
> if os.path.getmtime(my_path) < os.path.getmtime(update_path):
>     # Update the script.
>     shutil.copy2(update_path, my_path)
>     # Re-start the script.
>     os.startfile(my_path)
>     sys.exit()
>
> # The rest of the script...

I do mostly the same, except that instead of os.startfile I use:

  args = [sys.executable]
  args.extend(sys.argv)
  os.spawnl(os.P_NOWAIT, sys.executable, *args)

to re-start the current script with the same arguments it was invoked
before.

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


Re: Is this doable

2008-03-21 Thread MRAB
On Mar 21, 11:48 am, fkallgren <[EMAIL PROTECTED]> wrote:
> Hi.
>
> I have a little problem. I have a script that is in the scheduler
> (win32). But every now and then I update this script and I dont want
> to go to every computer and update it. So now I want the program to 1)
> check for new version of the script, 2) if there is a new version,
> copy that verision from server to local drive, 3) shutdown the program
> and start it up again as the new version.
>
> The problem is that I can't run this script directly from server so it
> have to run it locally.
>
> Anyone having any bright ideas??
>
The script could just check to see if the version on the server is
more recent and if it is then copy it over the local one, start the
local one, and then quit.

Python compiles the script to bytecode and then interprets the
bytecode, so when the script is being run the .py or .pyw source
itself isn't being used and can be overwritten. I've tried the
following on Windows XP and it works:

import os
import sys
import shutil

# Is there a newer version?
my_path = sys.argv[0]
update_path = os.path.join(os.path.dirname(my_path), "new_script.py")

if os.path.getmtime(my_path) < os.path.getmtime(update_path):
# Update the script.
shutil.copy2(update_path, my_path)
# Re-start the script.
os.startfile(my_path)
sys.exit()

# The rest of the script...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this doable

2008-03-21 Thread Mike Driscoll
On Mar 21, 6:48 am, fkallgren <[EMAIL PROTECTED]> wrote:
> Hi.
>
> I have a little problem. I have a script that is in the scheduler
> (win32). But every now and then I update this script and I dont want
> to go to every computer and update it. So now I want the program to 1)
> check for new version of the script, 2) if there is a new version,
> copy that verision from server to local drive, 3) shutdown the program
> and start it up again as the new version.
>
> The problem is that I can't run this script directly from server so it
> have to run it locally.
>
> Anyone having any bright ideas??
>
> /fkallgren

You could create an update script that compares the md5 (or some
other) hash of the files for differences, kill the program if there is
a difference and do the copy. I don't understand why you can do it
from the server. I basically do the same thing from my workstation
when I update one of my programs.

To kill the process on a remote PC, I do the following:



import subprocess
subprocess.Popen('taskkill /s %s /im processName' % computer_name)



I actually don't restart mine since it will be started when the user
logs on. So I'll leave that to you. Of course, my program is made into
an executable, but it should work the same.

Maybe that will give you some ideas anyway.

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


Is this doable

2008-03-21 Thread fkallgren
Hi.

I have a little problem. I have a script that is in the scheduler
(win32). But every now and then I update this script and I dont want
to go to every computer and update it. So now I want the program to 1)
check for new version of the script, 2) if there is a new version,
copy that verision from server to local drive, 3) shutdown the program
and start it up again as the new version.

The problem is that I can't run this script directly from server so it
have to run it locally.

Anyone having any bright ideas??


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