Is this doable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • fkallgren

    Is this doable

    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
  • Mike Driscoll

    #2
    Re: Is this doable

    On Mar 21, 6:48 am, fkallgren <fkallg...@gmai l.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.Pope n('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

    Comment

    • MRAB

      #3
      Re: Is this doable

      On Mar 21, 11:48 am, fkallgren <fkallg...@gmai l.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(m y_path), "new_script.py" )

      if os.path.getmtim e(my_path) < os.path.getmtim e(update_path):
      # Update the script.
      shutil.copy2(up date_path, my_path)
      # Re-start the script.
      os.startfile(my _path)
      sys.exit()

      # The rest of the script...

      Comment

      • Gabriel Genellina

        #4
        Re: Is this doable

        On 21 mar, 15:11, MRAB <goo...@mrabarn ett.plus.comwro te:
        On Mar 21, 11:48 am, fkallgren <fkallg...@gmai l.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(m y_path), "new_script.py" )
        >
        if os.path.getmtim e(my_path) < os.path.getmtim e(update_path):
            # Update the script.
            shutil.copy2(up date_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

        Comment

        • Jonathan Gardner

          #5
          Re: Is this doable

          On Mar 21, 4:48 am, fkallgren <fkallg...@gmai l.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.

          Comment

          • fkallgren

            #6
            Re: Is this doable

            On Mar 21, 12:48 pm, fkallgren <fkallg...@gmai l.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

            Comment

            • Lie

              #7
              Re: Is this doable

              On Mar 22, 1:11 am, MRAB <goo...@mrabarn ett.plus.comwro te:
              On Mar 21, 11:48 am, fkallgren <fkallg...@gmai l.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():
              callupdatescrip t()
              terminateself() # possibly saving state, etc

              Comment

              • Tobiah

                #8
                Re: Is this doable

                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

                Comment

                Working...