[430] | 1 | #!/usr/bin/python |
---|
| 2 | |
---|
| 3 | import socket |
---|
| 4 | |
---|
| 5 | import shutil |
---|
| 6 | import re |
---|
| 7 | import os |
---|
| 8 | import sys |
---|
| 9 | |
---|
| 10 | HOST = '' # Symbolic name meaning all available interfaces |
---|
| 11 | PORT = 7070 # Arbitrary non-privileged port |
---|
| 12 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
---|
| 13 | s.bind((HOST, PORT)) |
---|
| 14 | s.listen(1) |
---|
| 15 | while True: |
---|
| 16 | os.chdir('C:\\') # return to C: root directory |
---|
| 17 | print('Now accepting connections ...') |
---|
| 18 | conn, addr = s.accept() |
---|
| 19 | print 'Connected by', addr |
---|
| 20 | if True: # do the following only once ... => could remove the test altogether |
---|
| 21 | data = conn.recv(1024) |
---|
| 22 | if not data: break |
---|
| 23 | |
---|
| 24 | pattern = re.compile(r'([\w\d\-\_]+) asks: Compile MAD for Windows!') |
---|
| 25 | m = pattern.match(data) |
---|
| 26 | if m: |
---|
| 27 | # copy contents of /user/nougaret/MAD-X-WINDOWS/madX into C:/madXCompilationSandbox, after cleaning the later |
---|
| 28 | currentDir = os.getcwd() |
---|
| 29 | print("now in "+currentDir) |
---|
| 30 | try: |
---|
| 31 | shutil.rmtree('C:\\madXCompilationSandbox') |
---|
| 32 | except: |
---|
| 33 | print("no compilation sandbox had to be deleted") |
---|
| 34 | shutil.copytree('Y:\\MAD-X-WINDOWS\\madX','C:\\madXCompilationSandbox') |
---|
| 35 | |
---|
| 36 | # invoke the compilation |
---|
| 37 | print("remote invocation of MAD-X compilation on Windows") |
---|
| 38 | os.chdir('C:\madXCompilationSandbox') |
---|
| 39 | currentDir = os.getcwd() |
---|
| 40 | print("now in "+currentDir) |
---|
| 41 | os.system('MakefileIntel.bat') |
---|
| 42 | # copy executable to NFS for subsequent transfer to AFS web folder |
---|
| 43 | shutil.copy('C:\\madXCompilationSandbox\madx.exe',\ |
---|
| 44 | 'Y:\\MAD-X-WINDOWS\\madX\madx.exe') |
---|
| 45 | clientHost = m.group(1) |
---|
| 46 | # send acknowldegement to the client |
---|
| 47 | # jluc rajoute a l-instant the following |
---|
| 48 | conn.send('Compilation completed\n') |
---|
| 49 | conn.close() |
---|
| 50 | |
---|
| 51 | # clientPort = 7071 # agreed-upon with the server |
---|
| 52 | # sAcknowledge = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
---|
| 53 | # sAcknowledge.connect((clientHost, clientPort)) |
---|
| 54 | # sAcknowledge.send('Compilation completed\n') |
---|
| 55 | # data = sAcknowledge.recv(1024) |
---|
| 56 | # sAcknowledge.close() |
---|
| 57 | # print 'Received', repr(data) |
---|
| 58 | # now should leave this inner loop and wait for a new connection ... |
---|
| 59 | else: |
---|
| 60 | print('unexpected data packet received.') |
---|
| 61 | |
---|
| 62 | # conn.send(data) |
---|
| 63 | |
---|
| 64 | conn.close() |
---|
| 65 | |
---|