source: PSPA/madxPSPA/testing/MadWindowsCompileServer.py @ 430

Last change on this file since 430 was 430, checked in by touze, 11 years ago

import madx-5.01.00

File size: 2.4 KB
Line 
1#!/usr/bin/python
2
3import socket
4
5import shutil
6import re
7import os
8import sys
9
10HOST = ''                 # Symbolic name meaning all available interfaces
11PORT = 7070              # Arbitrary non-privileged port
12s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
13s.bind((HOST, PORT))
14s.listen(1)
15while 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
Note: See TracBrowser for help on using the repository browser.