Esempio n. 1
0
    def file_details_view(self, request, extra_context=None):
        # import pdb; pdb.set_trace();
        object_id = request.META['PATH_INFO'].strip('/').split('/')[-2]
        try:
            file = self.model.objects.get(pk=object_id)
            docs = []
            docs_path = ''
            docs_location = file.docs_location

            if docs_location:
                docs_path = 'case_files/' + docs_location
            else:
                docs_path = 'case_files/%s/' % case.case_no

            directory = settings.MEDIA_ROOT + "/" + docs_path

            if not os.path.exists(directory):
                os.makedirs(directory)
                fd = os.fopen(directory)
                os.fchown(fd, 1000, 1000)

            for doc in os.listdir(directory):
                if not os.path.isdir(doc):
                    docs.append(docs_path + "/" + doc)

            context = {
                'opts': self.model._meta,
                'case_file': file,
                'docs': docs
            }

        except ValueError:
            return HttpResponseRedirect(request.META['HTTP_REFERER'])

        return render(request, 'admin/file_details_view.html', context)
Esempio n. 2
0
def Launch(cmd, no_stdout, env):
    global fds
    global c
    c = c + 1
    #cmd = ["/usr/bin/timeout", "-k", "1", "3"]+cmd
    #print cmd
    if cmd[-1][0:2] == "< ":
        filename = cmd[-1].replace("< ", "")

        #try:
        #  close(3)
        #except OSError:
        #  print "OsError!"
        #  pass

        for fd in fds:
            #print fd,
            try:
                close(fd)
                #print "closed!"
            except OSError:
                #print "failed close!"
                pass

        fds = []

        desc = fopen(filename, O_RDONLY)
        fds.append(desc)
        dup2(desc, stdin.fileno())
        fds.append(desc)
        #close(desc)

        cmd = cmd[:-1]

    #print "c:", c
    #print "self pid", getpid()

    r = createChild(cmd, no_stdout, env)

    #print "new pid", r
    #print "self pid", getpid()
    #print "Done!"

    return r
Esempio n. 3
0
File: Run.py Progetto: rancb/ocean
def Launch(cmd, no_stdout, env):
  global fds
  global c
  c = c + 1
  #cmd = ["/usr/bin/timeout", "-k", "1", "3"]+cmd
  #print cmd
  if cmd[-1][0:2] == "< ":
    filename = cmd[-1].replace("< ", "")

    #try:
    #  close(3)
    #except OSError:
    #  print "OsError!"
    #  pass

    for fd in fds:
      #print fd,
      try:
        close(fd)
        #print "closed!"
      except OSError:
        #print "failed close!"
        pass

    fds = []

    desc = fopen(filename,O_RDONLY)
    fds.append(desc)
    dup2(desc, stdin.fileno())
    fds.append(desc)
    #close(desc)

    cmd = cmd[:-1]

  #print "c:", c
  #print "self pid", getpid()

  r = createChild(cmd, no_stdout, env)

  #print "new pid", r
  #print "self pid", getpid()
  #print "Done!"

  return r
Esempio n. 4
0
pth_source_fid = os.open(path_to_pth, 'r')
null = pth_source_fid.readline()
num_time_steps = int(pth_source_fid.readline())

for i in range(1, num_time_steps + 1):
    time_step = pth_source_fid.howeveryoureadonenumber
    parts = pth_source_fid.howeveryoureadonenumber

    # Preallocate space for array of particles
    parts_array[3 * parts]
    for j in range(1, parts):
        parts_array(j) = pth_source_fid.readline()

    file_name = 'particle_%i' % time_step
    output_fid = os.fopen(file_name, 'w')

for day in range(1, num_days + 1):
    # 8 should be a varible for days in run + 1?
    run_length = num_days + 1 - day
    path = '7-%d-2010_%d_f' % (day, run_length)
    os.chdir(path)
    os.system(
        'tail -n 5000 particle.bp | awk \'$5 >= 0\' > above_free_surface.dat')
    os.system('tail -n 5000 particle.bp | awk \'$5 < 0\' > new_particle.tmp')
    os.system('head -n 7 particle.bp > new_head.tmp')
    os.system('cat new_head.tmp new_particle.tmp > particle.bp.new')
    # If python is ever updated I can used the non-deprecated version
    #proc = subprocess.Popen('awk \'END{print NR}\' above_free_surface.dat', shell=True, stdout=subprocess.PIPE, )
    #num_afs = proc.communicate()[0]
    num_afs = int(