Wang Dingwei avatar Wang Dingwei committed 9696891

misc fixes

Comments (0)

Files changed (7)

production_settings.py

 
 class ProdConfig(DefaultConfig):
     DEBUG = False
-    
     SQLALCHEMY_DATABASE_URI = 'mysql://root:ndk800@localhost/runindatabase'
     SQLALCHEMY_ECHO = False
     
     PDLINES = ['FA1', 'FA2', 'FA3', 'FA5', 'FA7', 'EA3', 'EA4', 'EA5']
     TIMEOUT = timedelta(0, 3600 * 4)
-    MAXAGE = 3600 * 8
+    MAXAGE = 3600 * 5
     RUNIN_STAGES = ['TS', 'TT', 'TW', 'TO', 'TV']
     
     SECRET_KEY = 'development'
-
     SOAP_CLIENT = Client('http://172.30.60.152/Basic.WebService/WebService.asmx?WSDL')
     USE_WSDL = True
-
     MAIL_SERVER = 'wksmail.wistron.com'
     MAIL_USERNAME = ''
     MAIL_PASSWORD = ''
 
+class DebugConfig(ProdConfig):
+    DEBUG = True
+
+debug_settings = DebugConfig()
 production_settings = ProdConfig()

rqs/templates/layout.html

             <li><a href="{{ url_for('checkout.check_out')}}" target="_blank">Check out</a></li>
             <li><a href="{{ url_for('checkin.check_in')}}" target="_blank">Check in</a></li>
             <li><a href="{{ url_for('change_rack.update_rack') }}" target="_blank">Update Rack</a></li>
-            <li><a href="{{ url_for('export.export_csv' }}">Export Data</a></li>
+            <li><a href="{{ url_for('export.export_csv') }}">Export Data</a></li>
           </ul>
           <h3>Query</h3>
           <dl>
 from flask import current_app
 from threading import Thread
+import time
 
 runin_stages = ['TS', 'TT', 'TW', 'TO', 'TV']
 
         self.client = client
 
     def run(self):
+        counter = 0
+        while not hasattr(self, 'stage'):
+            counter += 1
+            try:
+                self.stage = self.client.service.GetNextStage(self.svctag, 'AO', 'AO').split()[0]
+                break
+            except Exception, e:
+                if counter > 3:
+                    raise
+                else:
+                    time.sleep(.1)
 
-        self.stage = self.client.service.GetNextStage(self.svctag, 'AO', 'AO').split()[0]
+                
 
 
 def outsiders(units, client):
     return out_units
 
 	
+def getstages(units, client):
+    result = []
+    stage_result = []
+    for u in units:
+        w = WsdlThread(u.ServiceTag, client)
+        result.append(w)
+        w.start()
+    for w in result:
+        w.join()
+		
+    for u in units:
+        for th in result:
+            if u.ServiceTag == th.svctag:
+                u.stage = th.stage
+                stage_result.append(u)
+	
+    return stage_result
+
+	
 def delta2sec(delta):
     """Converting timedelta to seconds. """
     return delta.days * 86400 + delta.seconds
+
+def sec2hhmm(sec):
+    h, remainder = divmod(sec, 3600)
+    m = remainder / 60
+    return "%s:%s" % (h, m)

rqs/views/__init__.py

 from .checkout import checkout
 from .checkin import checkin
 from .change_rack import change_rack
+from .export import export

rqs/views/export.py

 from flask import current_app as app
 
 from rqs.model import db, Unit
-from rqs.util import outsiders
+from rqs.util import getstages, sec2hhmm
 
 import csv
 from cStringIO import StringIO
 
-line = Module(__name__)
+export = Module(__name__)
 
-@line.route('/')
+@export.route('/')
 def export_csv():
-    result = Unit.query.all()
+    result = Unit.query.all()[:3]
     if app.config['USE_WSDL']:
-        pushed_out = outsiders(result, app.config['SOAP_CLIENT'])
-        for u in pushed_out:
-            result.remove(u)
-            db.session.delete(u)
-        db.session.commit()
+        result = getstages(result, app.config['SOAP_CLIENT'])
 
     csvlog = StringIO()
-    logwriter = csv.writer(csvlog)
+    logwriter = csv.writer(csvlog, dialect='excel')
     logwriter.writerow([
         'ServiceTag',
         'Model',
         'Rack',
         'Input_Time',
         'Age',
+        'Stage',
         ])
     for u in result:
         u.getage(timeout=g.timeout)
             u.ServiceTag,
             u.Model,
             u.RuninLine,
-            u.rack,
+            'R' + u.Rack,
             u.InputTime,
-            u.age,
+            sec2hhmm(u.age),
+            u.stage,
             ])
     
     csvlog.seek(0)

rqs/views/line.py

 from flask import Module, session, request, redirect, url_for, \
-        render_template, g, flash
+        render_template, g, flash, abort
 
 from flask import current_app as app
 
-from production_settings import production_settings
+from production_settings import production_settings, debug_settings
 from rqs import create_app
 
-app = create_app(production_settings)
+app = create_app(debug_settings)
 
 app.run()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.