hackNite @ dgplug

Standard

hacknite @ dgplug from 12am to 4.30am with Kushal DasSayan ChowdhuryGaurav KumarBiraj KarmakarAshish MishraSubhendu GhoshZubin TewariApoorv Ashutosh,Saurabh MandalBiswajit Malakar was finally a success!!!

We implemented the basic structure of a remote C compiler. The thought was that systems without a gcc compiler can make a request and remotely compile their C codes via a server. The server would receive the codes to compile in the form of a queue using retask and compile them. I wrote the code that would compile the program on the server side. Although its not fully functional yet, I mean the code is not yet designed to sent the output back to the client who sent the compile request. We look forward to getting on and finishing off the tasks as required.

It was real fun working with the group overnight. The team comprised of all sorts of code geeks, starting from newbies to experts. We all had a hell of an experience, although my first kind, am eagerly waiting for more of this.

This was my piece of code.

#!/usr/bin/python
import tempfile
import os
import subprocess
import sys
from retask.queue import Queue, Job
def file_read(file_name):
    f=open(file_name)
    content=f.read()
    f.close()
    return content,file_name
def main():
    queue = Queue('test')
    queue.connect()
    while True:
        task = queue.wait()
        name = task.data['filename']
        print "Received", name
        content = task.data['text']
        destdir = writesource(name, content)
        temp_path = os.path.join(destdir, name)
        x = os.path.join(destdir, 'test')
        out, err = system('gcc ' + temp_path + ' -o ' + x)
        if err:
            queue.send(task, err, 120)
        else:
            out1, err1 = system(x)
            if err1:
                queue.send(task, err1, 120)
            else:
                queue.send(task, out1, 120)

        #print system(x)

def system(cmd):
    """
    Invoke a shell command. Primary replacement for os.system calls.
    """
    ret = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
    stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
    out, err = ret.communicate()
    return out, err
def writesource(name, content):
    destdir = tempfile.mkdtemp(suffix='.' + str(os.getpid()), dir=None)
    temp_path=os.path.join(destdir,name)
    f=open(temp_path,'w')
    f.write(content)
    f.close()
    return destdir

if __name__== '__main__':
    main()
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s