def madgraph(steeringtempl, outputLHE, outputdiagramdir, param, proc, nevents = 1000, workdir = None):
  if not workdir:
    workdir = os.getcwd()
    
  if not os.path.exists(workdir):
    os.makedirs(workdir)

  madgraphwork = '{}/madgraphrun'.format(workdir)
  steeringfile = '{}/mg5.cmd'.format(workdir)
  render(steeringtempl,steeringfile, PARAM = param, PROC = proc, NEVENTS = nevents, WORKDIR =  madgraphwork)
  try:
    with open('{}/mg5.log'.format(workdir),'w') as mg5log:
      subprocess.check_call(['mg5','-f',steeringfile], stdout = mg5log)
    subprocess.check_call(['gunzip','-c','{}/Events/output/unweighted_events.lhe.gz'.format(madgraphwork)],
                          stdout = open(outputLHE,'w'))
    log.info('..')
  except subprocess.CalledProcessError:
    os.remote(outputLHE)

  psfiles = glob.glob('{}/SubProcesses/*/matrix*.ps'.format(madgraphwork))

  print psfiles
  
  if not os.path.exists(outputdiagramdir):
      os.makedirs(outputdiagramdir)

  for file in psfiles:
      basename = file.replace(madgraphwork+'/','').replace('/','_').rstrip('.ps')
      pdffile = '{}/{}'.format(outputdiagramdir,basename+'.pdf')
      pngfile = '{}/{}'.format(outputdiagramdir,basename+'.png')

      subprocess.call(['ps2pdf',file,pdffile])
      subprocess.check_call(['convert','-trim','-density','92',pdffile,pngfile])
Exemplo n.º 2
0
 def destroy(self):
     if not os.path.exists(self.path):
         return
     if os.path.isdir(self.path):
         shutil.rmtree(self.path)
     elif os.path.isfile(self.path):
         os.remote(self.path)
     else:
         raise Exception("Test only deletes files and directories: %s" % self.path)
     try:
         os.rmdir(PATH)
     except OSError:
         pass
Exemplo n.º 3
0
Arquivo: helper.py Projeto: baiqj/ops
 def destroy(self):
     if not os.path.exists(self.path):
         return
     if os.path.isdir(self.path):
         shutil.rmtree(self.path)
     elif os.path.isfile(self.path):
         os.remote(self.path)
     else:
         raise Exception('Test only deletes files and directories: %s' %
                         self.path)
     try:
         os.rmdir(PATH)
     except OSError:
         pass
Exemplo n.º 4
0
    def write(self, filename):
        """
        Write the file data to a pickled gzip file.

        :param filename:  The data file name
        :return: Nothing
        """
        # Remove any old data...
        try:
            os.remote(filename)
        except:
            pass

        # Zip up the pickle
        with gzip.open(filename, 'wb') as file:
            pickle.dump(self.malware, file)
Exemplo n.º 5
0
def create_cdrom(vm_name, orig_iso, target_dev):
    """
    :param vm_name : vm_name
    :param source_iso : disk's source backing file.
    """
    try:
        _file = open(orig_iso, 'wb')
        _file.seek((1024 * 1024) - 1)
        _file.write(str(0))
        _file.close()
    except IOError:
        raise error.TestFail("Create orig_iso failed!")
    try:
        virsh.attach_disk(vm_name, orig_iso, target_dev,
                          "--type cdrom --sourcetype=file --config")
    except:
        os.remote(orig_iso)
        raise error.TestFail("Failed to attach")
Exemplo n.º 6
0
def create_cdrom(vm_name, orig_iso, target_dev):
    """
    :param vm_name : vm_name
    :param source_iso : disk's source backing file.
    """
    try:
        _file = open(orig_iso, 'wb')
        _file.seek((1024 * 1024) - 1)
        _file.write(str(0))
        _file.close()
    except IOError:
        raise error.TestFail("Create orig_iso failed!")
    try:
        virsh.attach_disk(vm_name, orig_iso, target_dev,
                          "--type cdrom --sourcetype=file --config")
    except:
        os.remote(orig_iso)
        raise error.TestFail("Failed to attach")
Exemplo n.º 7
0
    def _create_file(self, contents=None):
        if not contents:
            contents = LOREM_IPSUM

        # always want to ensure the files added to the repo are unique no
        # matter which branch they are added to, as otherwise there may
        # be conflicts caused by replaying local changes and performing
        # merges
        while True:
            tmpfile = tempfile.NamedTemporaryFile(dir=self.repo.working_dir,
                                                  delete=False)
            if tmpfile.name not in self._file_list:
                self._file_list.add(tmpfile.name)
                break
            tmpfile.close()
            os.remote(tmpfile.name)
        tmpfile.write(contents)
        tmpfile.close()
        return tmpfile.name
Exemplo n.º 8
0
    def delete_plugin(self, name):
        '''
        Removes the plugin from the server.
        '''
        plug = self.get_plugin(name)

        # We are setting these here as I'm lazy and we will be using these a
        # lot in this function.
        pjoin = os.path.join
        exists = os.path.exists

        if exists(pjoin(self.plugin_path, plug['jar'])):
            os.remove(pjoin(self.plugin_path, plug['jar']))
        if exists(pjoin(self.plugin_path, plug['jar'][:-4])):
            shutil.rmtree(pjoin(self.plugin_path, plug['jar'][:-4]))
        if exists(pjoin('%s_diabled' % self.plugin_path, plug['jar'])):
            os.remote(pjoin('%s_diabled' % self.plugin_path, plug['jar']))
        conf = ConfigParser()
        conf.read(config.get_config_file())
        conf.remove_section('Plugin: %s' % name.lower())
        with open(config.get_config_file(), 'w') as cfile:
            conf.write(cfile)
        print 'Plugin %s removed and (hopefully) all associated data.' % plug['name']