Is this doable

Lie Lie.1296 at gmail.com
Sun Mar 23 18:43:59 CET 2008


On Mar 22, 1:11 am, MRAB <goo... at mrabarnett.plus.com> wrote:
> On Mar 21, 11:48 am, fkallgren <fkallg... at gmail.com> 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



More information about the Python-list mailing list