Is this doable

F

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
 
M

Mike Driscoll

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:

<code>

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

</code>

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
 
M

MRAB

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...
 
G

Gabriel Genellina

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.
 
J

Jonathan Gardner

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.
 
F

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

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



/fkallgren
 
L

Lie

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
 
T

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top