euscanwww: scan_upstream imports euscan.scan
scan_upstream command imports euscan.scan and simply calls a function, it doesn't call a subprocess Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
parent
e8718748b4
commit
47ec539e1d
@ -1,14 +1,16 @@
|
||||
import subprocess
|
||||
import portage
|
||||
import sys
|
||||
import re
|
||||
from StringIO import StringIO
|
||||
|
||||
from optparse import make_option
|
||||
|
||||
from django.utils import timezone
|
||||
from django.db.transaction import commit_on_success
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from euscan import CONFIG, output
|
||||
from euscan.scan import scan_upstream
|
||||
|
||||
from djeuscan.models import Package, Version, EuscanResult, VersionLog
|
||||
|
||||
|
||||
@ -17,13 +19,23 @@ class ScanUpstream(object):
|
||||
self.quiet = quiet
|
||||
|
||||
def scan(self, package):
|
||||
cmd = ['euscan', package]
|
||||
CONFIG["format"] = "dict"
|
||||
output.set_query(package)
|
||||
scan_upstream(package)
|
||||
out = output.get_formatted_output()
|
||||
out_json = output.get_formatted_output("json")
|
||||
|
||||
fp = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
output = StringIO(fp.communicate()[0])
|
||||
try:
|
||||
cp = out["metadata"]["cp"]
|
||||
except KeyError:
|
||||
return {}
|
||||
|
||||
self.parse_output(output)
|
||||
for out in out["result"]:
|
||||
self.store_version(cp, out["version"], " ".join(out["urls"]))
|
||||
|
||||
self.store_result(cp, out_json)
|
||||
|
||||
return out
|
||||
|
||||
def store_result(self, package, log):
|
||||
# Remove previous logs
|
||||
|
@ -67,4 +67,4 @@ ROBOTS_TXT_BLACKLIST_DOMAINS = [
|
||||
]
|
||||
|
||||
from out import EuscanOutput
|
||||
output = out.EuscanOutput(CONFIG)
|
||||
output = EuscanOutput(CONFIG)
|
||||
|
@ -95,7 +95,7 @@ class EuscanOutput(object):
|
||||
"metadata": {},
|
||||
}
|
||||
|
||||
def get_formatted_output(self):
|
||||
def get_formatted_output(self, format_=None):
|
||||
data = {}
|
||||
|
||||
for query in self.queries:
|
||||
@ -105,8 +105,11 @@ class EuscanOutput(object):
|
||||
"messages": self.queries[query]["output"].getvalue(),
|
||||
}
|
||||
|
||||
if self.config["format"].lower() == "json":
|
||||
format_ = format_ or self.config["format"]
|
||||
if format_.lower() == "json":
|
||||
return json.dumps(data, indent=self.config["indent"])
|
||||
elif format_.lower() == "dict":
|
||||
return data
|
||||
else:
|
||||
raise TypeError("Invalid output format")
|
||||
|
||||
@ -133,7 +136,7 @@ class EuscanOutput(object):
|
||||
print "%s: %s" % (key.capitalize(), value)
|
||||
|
||||
def __getattr__(self, key):
|
||||
if not self.config["quiet"]:
|
||||
if not self.config["quiet"] and self.current_query is not None:
|
||||
output = self.queries[self.current_query]["output"]
|
||||
return getattr(output, key)
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user