##// END OF EJS Templates
Fix upload files
jespinoza -
r10:ac38b2ff3424
parent child
Show More
@@ -1,3 +1,4
1 1 MADROOT=/madrigal
2 EXP_DIR=/usr/local/experiments
3 MAD_PORT=8080
2 EXP_DIR=/data/madrigal/experiments
3 META_DIR=/data/madrigal/metadata
4 MAD_PORT=80
@@ -1,27 +1,28
1 1 version: '3'
2 2
3 3 services:
4 4 web:
5 5 container_name: 'madrigal'
6 6 build: .
7 7 restart: always
8 8 image: madrigal
9 9 working_dir: /madrigal/source/madpy/djangoMad
10 command: gunicorn djangoMad.wsgi --bind 0.0.0.0:8000
10 command: gunicorn djangoMad.wsgi --timeout 600 --bind 0.0.0.0:8000
11 11 env_file: .env
12 12 volumes:
13 13 - '${EXP_DIR}:/madrigal/experiments'
14 - '${META_DIR}:/madrigal/metadata'
14 15 - './source/madpy/djangoMad:/madrigal/source/madpy/djangoMad'
15 16
16 17 nginx:
17 18 container_name: 'madrigal-nginx'
18 19 image: nginx:1.15-alpine
19 20 volumes:
20 21 - ./source/madpy/djangoMad/static_files:/static
21 22 - ./nginx:/etc/nginx/conf.d
22 23 ports:
23 24 - "${MAD_PORT}:8080"
24 25 depends_on:
25 26 - web
26 27 command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
27 28
@@ -1,22 +1,26
1 1 # configuration
2 2
3 3 upstream djangomad {
4 4 server web:8000;
5 5 }
6 6
7 7 server {
8 8 listen 8080;
9 client_max_body_size 50M;
9 client_max_body_size 100M;
10 10
11 11 location /madrigal {
12 12 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
13 13 proxy_set_header Host $host;
14 14 proxy_redirect off;
15 15 proxy_set_header X-Script-Name /madrigal;
16 16 proxy_pass http://djangomad;
17 17 }
18 18
19 19 location /madrigal/static/ {
20 20 alias /static/;
21 21 }
22 proxy_connect_timeout 600;
23 proxy_send_timeout 600;
24 proxy_read_timeout 600;
25 send_timeout 600;
22 26 }
@@ -1,115 +1,115
1 1
2 2 from django.contrib.auth.decorators import login_required
3 3 from django.shortcuts import render
4 4 from apps.updata.forms import UpdataForm, ExpForm
5 5 from django.core.files.storage import FileSystemStorage
6 6 from django.contrib import messages
7 7
8 8 import os
9 9
10 10 # madrigal imports
11 11 import madrigal.metadata
12 12 import madrigal.ui.web
13 13 import madrigal.admin
14 14
15 15 @login_required(login_url='/madrigal/accounts/login/')
16 16 def index(request):
17 17 '''
18 18 Uploading experiments data view. Allows user to upload experiment files
19 19
20 20 '''
21 21 dbAdminObj = madrigal.admin.MadrigalDBAdmin()
22 22 madDB = madrigal.metadata.MadrigalDB()
23 23 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
24 24 siteName, siteList = madWebObj.getSiteInfo()
25 25 err = False
26 26 if request.method == 'POST':
27 27 form = UpdataForm(request.POST, request.FILES)
28 28 files = request.FILES.getlist('file')
29 files.sort()
29 #files.sort()
30 30 filenames = []
31 31
32 32 choose = request.POST.get('choose')
33 33 if choose == 'new':
34 34 instCode = int(request.POST.get('inst'))
35 35 expTitle = request.POST.get('exp')
36 36 else:
37 37 instCode = int(request.POST.get('instruments'))
38 38 expId = request.POST.get('experiments')
39 39 madExp = madrigal.metadata.MadrigalExperiment()
40 40 expTitle = madExp.getExpNameByExpId(expId)
41 41
42 42 description = request.POST.get('description')
43 43 perm = int(request.POST.get('permission'))
44 44 optchar = request.POST.get('optchar').strip()
45 45 first = True
46 46 for f in files:
47 47 fs = FileSystemStorage(location='/tmp')
48 48 fs.save(f.name, f)
49 49 filename = os.path.join('/tmp', f.name)
50 50 ext = filename.split('.')[-1]
51 51 if ext not in ('hdf5', 'h5'):
52 52 convert = True
53 53 else:
54 54 convert = False
55 55
56 56 if first:
57 57 first = False
58 58 try:
59 59 expDir = dbAdminObj.createMadrigalExperiment(filename, expTitle, perm, description,
60 60 instCode, optChar=optchar, updateToMad3=convert)
61 61 except Exception as e:
62 62 err = True
63 63 messages.error(request,
64 64 'An error occur creating the experiment {}: {}'.format(expTitle, e)
65 65 )
66 66 break
67 67 else:
68 68 try:
69 69 dbAdminObj.addMadrigalFile(expDir, filename, perm, description, updateToMad3=convert)
70 70 except Exception as e:
71 71 err = True
72 72 messages.error(request,
73 73 'An error occur adding file {}: {}'.format(filename.split('/')[-1], e)
74 74 )
75 75
76 76 filenames.append(filename.split('/')[-1])
77 77 os.remove(filename)
78 78
79 79 if not err:
80 80 messages.success(request,
81 81 'Experiment {} created succesfully with files: {}'.format(expTitle, filenames)
82 82 )
83 83
84 84 madInstParams = madrigal.metadata.MadrigalInstrumentParameters()
85 85 madInstKindats = madrigal.metadata.MadrigalInstrumentKindats()
86 86
87 87 print('*** Updating local metadata ***')
88 88 dbAdminObj.__updateLocalMetadata__()
89 89 print('*** Rebuilding instParmTab.txt ***')
90 90 madInstParams.rebuildInstParmTable()
91 91 print('*** Rebuilding instKindatTab.txt ***')
92 92 madInstKindats.rebuildInstKindatTable()
93 93
94 94 form = UpdataForm()
95 95
96 96 else:
97 97 form = UpdataForm()
98 98
99 99 return render(request, 'updata/index.html', {
100 100 'form': form,
101 101 'site_name': siteName,
102 102 'site_list': siteList,
103 103 })
104 104
105 105
106 106 def get_experiments(request):
107 107 """get_experiments is a Ajax call that returns the experiments select html to support the
108 108 updata UI. Called when a user modifies the intruments select field.
109 109
110 110 Inputs:
111 111 request
112 112 """
113 113 form = ExpForm(request.GET)
114 114
115 115 return render(request, 'updata/experiments.html', {'form': form})
General Comments 0
You need to be logged in to leave comments. Login now