- update TODO Entropy/EquoInterface/ServerInterface: - they are now singleton, which is a big leap ahead in terms of ease of use Entropy/Equo/Server: - text_query, server_query: adapt code to better with singleton EquoInterface/ServerInterface instances Entropy/Spritz: - EquoInterface is now singleton, no need to load a global variable Entropy/urlFetcher: - add thread_stop_func, speed_limit, OutputInterface parameters to ease behaviour customization - rename __setup_proxy (private) to _setup_proxy - add set_id method, useful for thread identification when running multiple instances of urlFetcher - close() is now a private method - added thread_stop_func handling, used to stop fetches from other threads - commit() is now a private method - add handle_statistics method, if reimplemented, it's handy for controlling dataflow from other threads Entropy/entropy.py: - remove some unused functions imported from outputTools Entropy/EntropyCacher: - EntropyCacher is now singleton too Entropy/MultipleUrlFetcher: - base class that mimics the behaviour of urlFetcher adding the support for multiple simultaneous downloads Entropy/entropyTools: - improve xml_from_dict_extended and dict_from_xml_extended functions (add support for None types) Entropy/entropy.sh: - pre-declare public functions (pkg_*) git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@3078 cd1c1023-2f26-0410-ae45-c471fc1f0318
103 lines
3.6 KiB
Python
103 lines
3.6 KiB
Python
#!/usr/bin/python
|
|
'''
|
|
# DESCRIPTION:
|
|
# server tools for querying database
|
|
|
|
Copyright (C) 2007-2008 Fabio Erculiani
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
'''
|
|
|
|
from outputTools import *
|
|
from entropyConstants import *
|
|
import text_query
|
|
from entropy import ServerInterface
|
|
from entropy_i18n import _
|
|
|
|
def query(myopts):
|
|
|
|
if not myopts:
|
|
return 10
|
|
cmd = myopts[0]
|
|
myopts = myopts[1:]
|
|
if not myopts and cmd not in ["list","sets"]:
|
|
return 10
|
|
|
|
rc = 0
|
|
Entropy = ServerInterface()
|
|
dbconn = Entropy.openServerDatabase(just_reading = True)
|
|
|
|
if cmd == "search":
|
|
|
|
# open read only
|
|
count = 0
|
|
for mykeyword in myopts:
|
|
results = dbconn.searchPackages(mykeyword)
|
|
for result in results:
|
|
count += 1
|
|
text_query.printPackageInfo( result[1],
|
|
dbconn,
|
|
clientSearch = True,
|
|
extended = True,
|
|
Equo = Entropy
|
|
)
|
|
|
|
if not count:
|
|
print_warning(red(" * ")+red("%s." % (_("Nothing found"),) ))
|
|
rc = 0
|
|
|
|
elif cmd == "tags":
|
|
searchTaggedPackages(myopts, dbconn, Entropy)
|
|
elif cmd == "sets":
|
|
text_query.searchPackageSets(myopts, Equo = Entropy)
|
|
elif cmd == "files":
|
|
text_query.searchFiles(myopts, dbconn = dbconn, Equo = Entropy)
|
|
elif cmd == "belongs":
|
|
text_query.searchBelongs(myopts, dbconn = dbconn, Equo = Entropy)
|
|
elif cmd == "description":
|
|
text_query.searchDescriptions(myopts, dbconn = dbconn, Equo = Entropy)
|
|
elif cmd == "needed":
|
|
text_query.searchNeeded(myopts, dbconn = dbconn, Equo = Entropy)
|
|
elif cmd == "depends":
|
|
text_query.searchDepends(myopts, dbconn = dbconn, Equo = Entropy)
|
|
elif cmd == "eclass":
|
|
text_query.searchEclass(myopts, dbconn = dbconn, Equo = Entropy)
|
|
elif cmd == "list":
|
|
text_query.searchInstalled(dbconn = dbconn, Equo = Entropy)
|
|
elif cmd == "changelog":
|
|
text_query.searchChangeLog(myopts, dbconn = dbconn, Equo = Entropy)
|
|
|
|
del Entropy
|
|
return rc
|
|
|
|
|
|
def searchTaggedPackages(tags, dbconn, entropy):
|
|
|
|
if not etpUi['quiet']:
|
|
print_info(darkred(" @@ ")+darkgreen("%s..." % (_("Tag Search"),) ))
|
|
print_info(blue(" # ")+bold(entropy.default_repository))
|
|
|
|
for tag in tags:
|
|
results = dbconn.searchTaggedPackages(tag, atoms = True)
|
|
for result in results:
|
|
if etpUi['quiet']:
|
|
print dbconn.retrieveAtom(result[1])
|
|
else:
|
|
text_query.printPackageInfo(result[1], dbconn, Equo = entropy)
|
|
if not etpUi['quiet']:
|
|
print_info(blue(" %s: " % (_("Keyword"),) )+bold("\t"+tag))
|
|
print_info(blue(" %s: " % (_("Found"),) )+bold("\t"+str(len(results)))+red(" %s" % (_("entries"),) ))
|
|
|
|
return 0 |