예제 #1
0
def main():
   global isSub
   while True:
      l = FileLock(LOCK)
      try:
         l.acquire()
      except OSError as exception:
         if exception.errno != errno.EEXIST:
            raise
         else:
            time.sleep(SLEEP_TIME)
            continue
      try:
         try:
            machines = availableMachines()
         except:
            machines = []
         machineIndex = 0
         files = list(os.listdir(DIR))
         for f in files:
            if not re.match('\d+.task', f):
               continue
            fileName = os.path.join(DIR, f)
            file = open(fileName, 'r+')
            remaining = ''
            for cmd in file:
               if machineIndex >= len(machines):
                  remaining += cmd
               else:
                  idx = cmd.index('\t')
                  run(machines[machineIndex], cmd[0:idx], cmd[idx+1:].strip())
                  machineIndex += 1
            if remaining:
               file.seek(0)
               file.write(remaining)
               file.truncate()
               file.close()
            else:
               file.close()
               os.remove(fileName)
      finally:
         if not isSub:
            l.release()
      time.sleep(SLEEP_TIME)
예제 #2
0
def main():
    global isSub
    while True:
        l = FileLock(LOCK)
        try:
            l.acquire()
        except OSError as exception:
            if exception.errno != errno.EEXIST:
                raise
            else:
                time.sleep(SLEEP_TIME)
                continue
        try:
            try:
                machines = availableMachines()
            except:
                machines = []
            machineIndex = 0
            files = list(os.listdir(DIR))
            for f in files:
                if not re.match('\d+.task', f):
                    continue
                fileName = os.path.join(DIR, f)
                file = open(fileName, 'r+')
                remaining = ''
                for cmd in file:
                    if machineIndex >= len(machines):
                        remaining += cmd
                    else:
                        idx = cmd.index('\t')
                        run(machines[machineIndex], cmd[0:idx],
                            cmd[idx + 1:].strip())
                        machineIndex += 1
                if remaining:
                    file.seek(0)
                    file.write(remaining)
                    file.truncate()
                    file.close()
                else:
                    file.close()
                    os.remove(fileName)
        finally:
            if not isSub:
                l.release()
        time.sleep(SLEEP_TIME)
예제 #3
0
      return False
   return True

def srcDirLoc(c):
   return constants['statePath'] + '/src/' + c

srcDir = uniqueDir(srcDirLoc)
copyDirFiltered(os.path.expanduser(sys.argv[1]), srcDir, cpFilter)

def fileName(c):
   return DIR + '/' + c + '.task'

def execName(c):
   return constants['statePath'] + '/execs/' + c + '.exec'

l = FileLock(LOCK)
l.acquire()
try:
   fd = uniqueFile(fileName)
   if len(sys.argv) > 2:
      addToView = sys.argv[2]
   else:
      addToView = ""
   for cmd in sys.stdin.readlines():
      execDir = uniqueDir(execName)
      srcLocFile = open(execDir + '/srcLoc', 'w')
      srcLocFile.write(srcDir)
      srcLocFile.close()
      if addToView:
         addToViewFile = open(execDir + '/addToView', 'w')
         addToViewFile.write(addToView)