Browse Source

i have no idea what happened here

david 8 years ago
parent
commit
71ddcea6ed
5 changed files with 51 additions and 9 deletions
  1. 2 2
      front/index.html
  2. 12 4
      front/js/app.js
  3. 6 0
      qmanager.py
  4. 6 1
      unzipper.py
  5. 25 2
      web.py

+ 2 - 2
front/index.html

@@ -40,7 +40,7 @@
 								</tr>
 							</thead>
 							<tbody>
-								<tr ng-repeat="l in list | filter:{TYPE:'SEARCH'} track by l.ID" ng-class="{'expanded':limit!=undefined}">
+								<tr ng-repeat="l in searchlist | filter:{TYPE:'SEARCH'} track by l.ID" ng-class="{'expanded':limit!=undefined}">
 									<td><a ng-click="showMore(l)">{{limit[l.ID] ? '&#9650;' : '&#9660;'}}</a></td>
 									<td> <span>{{l.QUERY}}</span> </td>
 									<td> <label class="{{l.STATUS}}">{{l.STATUS}}</label> </td>
@@ -69,7 +69,7 @@
 								</tr>
 							</thead>
 							<tbody>
-								<tr ng-repeat="l in list | filter:{TYPE:'BOOK'} track by l.ID" class="expanded">
+								<tr ng-repeat="l in results| filter:{TYPE:'BOOK'} track by l.ID" class="expanded">
 									<td> <span>{{l.QUERY}}<span> </td>
 									<td> <label class="{{l.STATUS}}">{{l.STATUS}}</label> </td>
 									<td>

+ 12 - 4
front/js/app.js

@@ -2,13 +2,14 @@ app=angular.module('app', []);
 
 app.controller('main', function($scope,$http,$interval) {
 	var ROOT_PATH="/backend/";
-	$scope.list=[];
+	$scope.searchlist=[]
+	$scope.results = [];
 	$scope.book="";
 	$scope.extension="";
 
 	$scope.activeTab = 'SEARCH';
 	$scope.getList = function() {
-		$http.get(ROOT_PATH).then(
+		$http.get(ROOT_PATH+$scope.activeTab).then(
 		function(data) {
 			/*
 			data.data=data.data.map(function(el) {
@@ -17,7 +18,10 @@ app.controller('main', function($scope,$http,$interval) {
 				return el;
 			});
 			*/
-			$scope.list=data.data;
+			if($scope.activeTab === "SEARCH")
+				$scope.searchlist=data.data;
+			else
+				$scope.results=data.data;
 		},
 		function(data){
 			console.log("error");
@@ -64,7 +68,11 @@ app.controller('main', function($scope,$http,$interval) {
 	$scope.showMore = function(l){
 		$scope.limit[l.ID] = $scope.limit[l.ID] ? undefined : l.OUT.length;
 	}
-	$interval($scope.getList, 3500);
+
+	var promise =  $interval($scope.getList, 3500);
+	$scope.$on('destroy', function() {
+		$interval.cancel(promise);
+	});
 });
 
 app.directive('progressBar', function(){

+ 6 - 0
qmanager.py

@@ -45,6 +45,12 @@ class qManager:
         self.last_id += 1
         self.tasks.append(nt)
 
+    def search_status(self):
+        return [ t for t in self.task_status() if t["TYPE"]=='SEARCH' ]
+
+    def books_status(self):
+        return [ t for t in self.task_status() if t["TYPE"]=='BOOK' ]
+
     def task_status(self):
         """ Return a dict with the status of each 'task' """
         ret = []

+ 6 - 1
unzipper.py

@@ -9,6 +9,7 @@ USE_UNRAR = True
 def unar(source, dest_dir):
     """Split input into zip or rar and parse accordingly.
     Return source if it's not a zip or rar"""
+    print("uncompressing %s to %s" % (source, dest_dir))
     if source.lower().endswith("zip"):
         return unzip(source, dest_dir)
     if source.lower().endswith("rar"):
@@ -21,6 +22,7 @@ def unar(source, dest_dir):
 
 def unzip(source_filename, dest_dir):
     """Unzip source_filename to dest_dir"""
+    print("Unzipping %s to %s" % (source_filename, dest_dir))
     out = []
     with zipfile.ZipFile(source_filename) as zfile:
         for member in zfile.infolist():
@@ -34,13 +36,16 @@ def unzip(source_filename, dest_dir):
                 if word in (os.curdir, os.pardir, ''):
                     continue
                 path = os.path.join(path, word)
-            out.append(os.path.join(path, member.filename.split('/')[-1]))
+            target = os.path.join(path, member.filename.split('/')[-1])
+            out.append(target)
+            print("Extracted %s" % target)
             zfile.extract(member, path)
     return out
 
 
 def unrar(source, dest_dir):
     """Unzip source to dest_dir. Might use unar or unrar
+    print("Unraring %s to %s" % (source, dest_dir))
     based on the flag USE_UNRAR"""
     out = []
     list_files = []

+ 25 - 2
web.py

@@ -4,6 +4,7 @@ import json
 from http.server import BaseHTTPRequestHandler, HTTPServer
 from qmanager import qManager
 import urllib
+#import urllib.parse
 
 # Port on which server will run.
 PORT = 8080
@@ -15,8 +16,31 @@ class HTTPRequestHandler(BaseHTTPRequestHandler):
     q = qManager()
 
     def do_GET(self):
+        if self.path==BASE_PATH+"SEARCH":
+            self.send_200()
+            out=json.dumps(self.q.search_status())
+            self.wfile.write(bytes(out,"utf-8")) #fileHandle.read().encode()
+            return
+        if self.path==BASE_PATH+"list":
+            self.send_response(200)
+            mime="text/html"
+            self.send_header('Content-type', mime)
+            self.end_headers()
+            out = []
+            for book in self.q.books_status():
+                if 'OUT' not in book:
+                    continue
+                if len(book['OUT']) == 0:
+                    continue
+                out.append("<li><a href='%s'>%s</a>" % (urllib.parse.quote(book['OUT'][0]), book['QUERY']))
+            self.wfile.write(bytes("".join(out),"utf-8")) #fileHandle.read().encode()
+            return
+        if self.path==BASE_PATH+"RESULTS":
+            self.send_200()
+            out=json.dumps(self.q.books_status())
+            self.wfile.write(bytes(out,"utf-8")) #fileHandle.read().encode()
+            return
         if self.path==BASE_PATH:
-        #self.wfile.write(bytes()) #fileHandle.read().encode()
             self.send_200()
             out=json.dumps(self.q.task_status())
             self.wfile.write(bytes(out,"utf-8")) #fileHandle.read().encode()
@@ -24,7 +48,6 @@ class HTTPRequestHandler(BaseHTTPRequestHandler):
 
         p=urllib.parse.unquote(self.path.replace(BASE_PATH,""))
         path=FILE_PATH+p
-        print(path)
         #mime=mimetypes.guess_type(path) #fails on mobi, epub
         mime=""
         if p.endswith("mobi"):