By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,551 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,551 IT Pros & Developers. It's quick & easy.

Is this doable

P: n/a
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
Mar 21 '08 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On Mar 21, 6:48 am, fkallgren <fkallg...@gmail.comwrote:
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
Mar 21 '08 #2

P: n/a
On Mar 21, 11:48 am, fkallgren <fkallg...@gmail.comwrote:
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...
Mar 21 '08 #3

P: n/a
On 21 mar, 15:11, MRAB <goo...@mrabarnett.plus.comwrote:
On Mar 21, 11:48 am, fkallgren <fkallg...@gmail.comwrote: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
Mar 21 '08 #4

P: n/a
On Mar 21, 4:48*am, fkallgren <fkallg...@gmail.comwrote:
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.
Mar 21 '08 #5

P: n/a
On Mar 21, 12:48 pm, fkallgren <fkallg...@gmail.comwrote:
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
Mar 22 '08 #6

P: n/a
Lie
On Mar 22, 1:11*am, MRAB <goo...@mrabarnett.plus.comwrote:
On Mar 21, 11:48 am, fkallgren <fkallg...@gmail.comwrote: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
Mar 23 '08 #7

P: n/a
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

Mar 24 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.