summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsand <daniel@spatof.org>2013-05-13 17:32:01 (GMT)
committer sand <daniel@spatof.org>2013-05-13 17:32:01 (GMT)
commit256aafb1f04e1f50f243e94f3f440f71b4860f92 (patch)
tree9b091404dee1bb3810cd86c352b3b6ac8a661e3a
parent7f427aa3ccb6f6cad7df6ed73179d477c0431d00 (diff)
Pulizia vecchio codice
-rw-r--r--.gitignore9
-rw-r--r--pinolo/plugins/_google_old.py (renamed from plugins.old/cerca.py)0
-rw-r--r--plugins.old/cerca.yapsy-plugin8
-rw-r--r--plugins.old/prcd.py202
-rw-r--r--plugins.old/prcd.yapsy-plugin8
-rw-r--r--plugins.old/quotedb.py160
-rw-r--r--plugins.old/quotedb.yapsy-plugin8
-rw-r--r--plugins.old/xapiansearch.py128
-rw-r--r--plugins.old/xapiansearch.yapsy-plugin8
9 files changed, 2 insertions, 529 deletions
diff --git a/.gitignore b/.gitignore
index 9ab1a3e..a4bfbc5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,14 +1,9 @@
*.pyc
scripts/fortune/fortune.*
pinolo.cfg
-megahal.brn
-megahal.dic
-megahal.log
-megahal.trn
-megahal.txt
-prcd/*.txt
-xapian/
db.sqlite
pinolo.egg-info
*.swp
pinolo/data/prcd/prcd_*
+*~
+datadir/
diff --git a/plugins.old/cerca.py b/pinolo/plugins/_google_old.py
index ea38fbd..ea38fbd 100644
--- a/plugins.old/cerca.py
+++ b/pinolo/plugins/_google_old.py
diff --git a/plugins.old/cerca.yapsy-plugin b/plugins.old/cerca.yapsy-plugin
deleted file mode 100644
index 7f9a118..0000000
--- a/plugins.old/cerca.yapsy-plugin
+++ /dev/null
@@ -1,8 +0,0 @@
-[Core]
-Name = Google Search
-Module = cerca
-
-[Documentation]
-Description = Google Search
-Author = sand
-Version = 0.1
diff --git a/plugins.old/prcd.py b/plugins.old/prcd.py
deleted file mode 100644
index c1a78eb..0000000
--- a/plugins.old/prcd.py
+++ /dev/null
@@ -1,202 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-"""
-PRCD plugin
-
-"""
-
-import os
-import random
-import subprocess
-from pprint import pprint
-
-from pkg_resources import resource_string
-from twisted.python import log
-
-from pinolo.main import CommandPlugin, PluginActivationError
-from pinolo import MyOptionParser, OptionParserError
-
-
-# Only these prcd files contains one line sentences.
-PRCD_FILES = [
- 'prcd_cri.txt',
- 'prcd_dio.txt',
- 'prcd_ges.txt',
- 'prcd_mad.txt',
- 'prcd_mtc.txt',
- 'prcd_pap.txt',
- 'prcd_vsf.txt',
-]
-
-COWSAY_SHAPES = [
- 'apt', 'bong', 'bud-frogs', 'bunny',
- 'cock', 'cower', 'default', 'duck',
- 'flaming-sheep', 'head-in', 'hellokitty',
- 'koala', 'moose', 'mutilated', 'satanic',
- 'sheep', 'small', 'sodomized', 'sodomized-sheep',
- 'suse', 'three-eyes', 'tux', 'udder',
- 'vader',
-]
-
-
-def find_cowsay():
- """Find a cowsay binary in common system paths."""
-
- cowsay = None
-
- for f in [
- '/usr/games/cowsay',
- '/usr/bin/cowsay',
- '/usr/local/bin/cowsay',
- '/opt/bin/cowsay',
- '/opt/local/bin/cowsay',
- ]:
- if os.access(f, os.R_OK | os.X_OK):
- return f
-
- return None
-
-def populate_shapes(exe):
- cmdline = [exe, '-l']
-
- p = subprocess.Popen(cmdline, shell=False, stdout=subprocess.PIPE)
- (ano, oro) = p.communicate()
- ano = ano.split("\n")
- ano = ano[1:]
-
- shapes = []
-
- for line in ano:
- shapes.extend([x for x in line.split(" ") if x != ""])
-
- return shapes
-
-def setup_prcd_database():
- """Read all the prcd files and build the database"""
-
- prcd_db = {}
-
- def extract_category(name):
- """Extract the category name from filename: prcd_(CATEGORY).txt"""
-
- u = name.index('_')
- e = name.index('.')
-
- return name[u+1:e]
-
- for f in PRCD_FILES:
- path = os.path.join('data', 'prcd', f)
- content = resource_string('pinolo', path)
- content = [line.strip() for line in content.split("\n")]
- content = [line for line in content if line != '']
-
- category = extract_category(f)
- prcd_db[category] = content
-
- return prcd_db
-
-
-class Prcd(CommandPlugin):
- """This is the PRCD plugin"""
-
- prcd_opt = MyOptionParser(usage="!prcd [options]")
- cowsay_opt = MyOptionParser(usage="!PRCD [options]")
-
- def activate(self, config=None):
- super(Prcd, self).activate()
-
- self.prcd_db = setup_prcd_database()
- self.cowsay_bin = find_cowsay()
- # Popola le shape usando "cowsay -l"
- COWSAY_SHAPES = populate_shapes(self.cowsay_bin)
-
- def handle(self, request):
- if request.command in [ 'prcd' ]:
- try:
- (options, args) = self.prcd_opt.parse_args(request.arguments)
- except OptionParserError, e:
- request.reply(str(e))
- else:
- self.simple_prcd(request, options, args)
-
- elif request.command in [ 'PRCD' ]:
- try:
- (options, args) = self.cowsay_opt.parse_args(request.arguments)
- except OptionParserError, e:
- request.reply(str(e))
- else:
- self.cowsay(request, options, args)
-
-
- def simple_prcd(self, request, options, args):
- moccolo = None
-
- if options.category:
- if not options.category in self.prcd_db:
- request.reply("Categoria non trovata :(")
- return
-
- moccolo = random.choice(self.prcd_db[options.category])
-
- else:
- category = random.choice(self.prcd_db.keys())
- moccolo = random.choice(self.prcd_db[category])
- moccolo = "%s, %s" % (category, moccolo)
-
- request.reply(moccolo)
-
-
- def cowsay(self, request, options, args):
- shape = None
- moccolo = None
-
- if not self.cowsay_bin:
- request.reply("Non posseggo il binario... BINAAAARIOOOOOOOO... "
- "TRISTE E SOLITARIOOOOOOOOOO...")
- return
-
- if options.shape:
- if not options.shape in COWSAY_SHAPES:
- request.reply("Quella forma non la posseggo")
- return
-
- shape = options.shape
- else:
- shape = random.choice(COWSAY_SHAPES)
-
- if options.category:
- if not options.category in self.prcd_db:
- request.reply("Categoria non trovata PER GIOVE!")
- return
-
- moccolo = random.choice(self.prcd_db[options.category])
-
- else:
- category = random.choice(self.prcd_db.keys())
- moccolo = random.choice(self.prcd_db[category])
-
- cmdline = [self.cowsay_bin, '-f', shape]
- pope = subprocess.Popen(cmdline, shell=False,
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
-
- # <_ale> se moccolo son piu' di 4k riempi il pipe buffer e si inchioda tutto
- # (bocca, culo) = (pope.stdin, pope.stdout)
- # bocca.write(moccolo)
- # bocca.close()
- # formina = culo.read()
-
- (parole, vomito) = pope.communicate(moccolo)
- for riga in parole.split("\n"):
- if riga == "":
- continue
- request.reply(riga, prefix=False)
-
-
-Prcd.prcd_opt.add_option('-c', '--category', dest='category',
- help='Seleziona il moccolo da una categoria')
-Prcd.cowsay_opt.add_option('-c', '--category', dest='category',
- help='Seleziona il moccolo da una categoria')
-Prcd.cowsay_opt.add_option('-s', '--shape', dest='shape',
- help='Seleziona una delle shape disponibili')
diff --git a/plugins.old/prcd.yapsy-plugin b/plugins.old/prcd.yapsy-plugin
deleted file mode 100644
index de173bb..0000000
--- a/plugins.old/prcd.yapsy-plugin
+++ /dev/null
@@ -1,8 +0,0 @@
-[Core]
-Name = PRCD Support
-Module = prcd
-
-[Documentation]
-Description = PRCD with cowsay
-Author = sand
-Version = 0.1
diff --git a/plugins.old/quotedb.py b/plugins.old/quotedb.py
deleted file mode 100644
index 35a2973..0000000
--- a/plugins.old/quotedb.py
+++ /dev/null
@@ -1,160 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-"""
-Quotes plugin
-
-This is the first attempt to write pinolo features as pure python plugins.
-Implementing the basic commands for getting quotes from the database and
-creating new ones.
-
-This requires SQLAlchemy.
-"""
-
-import os
-import re
-from datetime import datetime
-from pprint import pprint
-# from optparse import OptionParser
-
-from twisted.python import log
-
-from sqlalchemy import Column, Integer, DateTime, Unicode
-from sqlalchemy import create_engine
-from sqlalchemy.orm import sessionmaker
-from sqlalchemy.ext.declarative import declarative_base
-from sqlalchemy import func
-
-from pubsub import Publisher as pubsub
-
-from pinolo.main import CommandPlugin, PluginActivationError
-from pinolo import MyOptionParser, OptionParserError
-
-DATABASE = os.path.abspath('./quotes.db')
-
-Base = declarative_base()
-metadata = Base.metadata
-
-
-class Quote(Base):
- """
- Quote database description.
- """
-
- __tablename__ = 'quotes'
-
- id = Column(Integer, primary_key=True)
- quote = Column(Unicode(10000))
- author = Column(Unicode(1000))
- creation_date = Column(DateTime)
- karma = Column(Integer)
-
- def __init__(self, quote, author, creation_date=None, karma=0):
- self.quote = quote
- self.author = author
- if creation_date is None:
- self.creation_date = datetime.now()
- else:
- self.creation_date = creation_date
- self.karma = karma
-
- def __repr__(self):
- return u"<Quote('%s', '%s', '%s', '%i')>" % (self.author,
- self.quote,
- self.creation_date,
- self.karma)
-
-class QuotesDb(CommandPlugin):
- """This is a test plugin implementing Quotes"""
-
- quote_opt = MyOptionParser(usage="!quote [options] [id]")
- addq_opt = MyOptionParser(usage="!addquote <quote da aggiungere>")
-
- def activate(self, config):
- super(QuotesDb, self).activate()
-
- self.db_file = 'sqlite:///' + config.quotes_db
- self.engine = None
- self.session = None
-
- try:
- self.engine = create_engine(self.db_file, echo=False)
- Session = sessionmaker(bind=self.engine)
- self.session = Session()
- except Exception, e:
- raise PluginActivationError(e)
-
-
- def handle(self, request):
- # def handle(self, client, command, arguments, irc_user, channel, reply_to):
- """Generic IRC command handler"""
-
- if request.command in [ 'q', 'quote' ]:
- try:
- (options, args) = self.quote_opt.parse_args(request.arguments)
- except OptionParserError, e:
- request.reply(str(e))
- else:
- self.get_quote(request, options, args)
-
- elif request.command in [ 'addq', 'addquote', 'add' ]:
- try:
- (options, args) = self.addq_opt.parse_args(request.arguments)
- except OptionParserError, e:
- # request.reply("Calcola non c'ho capito un cazzo")
- request.reply(str(e))
- else:
- self.add_quote(request, options, args)
-
- elif request.command in [ 'porcodio' ]:
- request.reply("Non ce l'ho, me deve arriva'")
-
- def get_quote(self, request, options, arguments):
- query = self.session.query(Quote)
-
- if arguments:
- id = arguments.pop(0)
-
- if re.match(r'\d+$', id):
- query = query.filter_by(id=id)
- else:
- request.reply("Invalid ID")
- return
-
- else:
- query = query.order_by(func.random())
-
- if options.contains:
- # SA vuole parametri 'unicode' per colonne 'unicode' ;)
- filter_str = unicode(options.contains, 'utf-8', 'replace')
- query = query.filter(Quote.quote.contains(filter_str))
-
- result = query.first()
- if result is None:
- request.reply("Not found")
- else:
- request.reply("%i, %s" % (result.id, result.quote))
- pubsub.sendMessage('get_quote', data=result)
-
-
- def add_quote(self, request, options, arguments):
- if not arguments:
- request.reply("Errore, te pare zi'?")
- return
-
- author = request.author.nickname
- author = unicode(author, 'utf-8', 'replace')
-
- text = ' '.join(arguments)
- text = unicode(text, 'utf-8', 'replace')
-
- quote = Quote(quote=text, author=author)
- self.session.add(quote)
- self.session.commit()
-
- request.reply("Ho stipato la %i!" % quote.id)
- pubsub.sendMessage('add_quote', data=quote)
-
-
-QuotesDb.quote_opt.add_option("-c", "--contains", dest="contains",
- help="Prende un Quote che contiene TESTO",
- metavar="TESTO")
diff --git a/plugins.old/quotedb.yapsy-plugin b/plugins.old/quotedb.yapsy-plugin
deleted file mode 100644
index 553332b..0000000
--- a/plugins.old/quotedb.yapsy-plugin
+++ /dev/null
@@ -1,8 +0,0 @@
-[Core]
-Name = Quote Database
-Module = quotedb
-
-[Documentation]
-Description = The mighty Quotes Database
-Author = sand
-Version = 0.2
diff --git a/plugins.old/xapiansearch.py b/plugins.old/xapiansearch.py
deleted file mode 100644
index 44f04b8..0000000
--- a/plugins.old/xapiansearch.py
+++ /dev/null
@@ -1,128 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-import sys
-import os
-import re
-import unicodedata
-from datetime import datetime
-
-import xapian
-from twisted.python import log
-from pubsub import Publisher as pubsub
-
-from pinolo.main import CommandPlugin, PluginActivationError
-
-# costanti per Xapian
-xapian_author = 0
-xapian_date = 1
-xapian_quote_id = 2
-
-
-class XapianSearch(CommandPlugin):
- def activate(self, config):
- super(XapianSearch, self).activate()
-
- # PROVA
- pubsub.subscribe(self.fai, 'get_quote')
- pubsub.subscribe(self.add_quote_signal, 'add_quote')
-
- self.database = xapian.WritableDatabase(config.xapian_db,
- xapian.DB_CREATE_OR_OPEN)
- self.indexer = xapian.TermGenerator()
- self.stemmer = xapian.Stem('italian')
- self.indexer.set_stemmer(self.stemmer)
- self.enquire = xapian.Enquire(self.database)
-
- self.qp = xapian.QueryParser()
- self.qp.set_stemmer(self.stemmer)
- self.qp.set_database(self.database)
- self.qp.set_stemming_strategy(xapian.QueryParser.STEM_SOME)
-
- def search(self, query_string, start=0, stop=5):
-
- query = self.qp.parse_query(query_string)
- self.enquire.set_query(query)
- matches = self.enquire.get_mset(start, stop)
- return matches
-
- def add_quote_signal(self, event):
- log.msg("Adding a quote from a signal")
- self.add_quote(event.data)
-
- def add_quote(self, quote):
- author = unicodedata.normalize('NFKC', quote.author)
- text = unicodedata.normalize('NFKC', quote.quote)
-
- doc = xapian.Document()
- doc.set_data(text)
- doc.add_value(xapian_author, author)
- doc.add_value(xapian_date, quote.creation_date.strftime('%Y%m%d%H%M%S'))
- doc.add_value(xapian_quote_id, str(quote.id))
-
- self.indexer.set_document(doc)
- self.indexer.index_text(text)
-
- self.database.add_document(doc)
-
- def handle(self, request):
- if request.command in [ 'search', 's' ]:
- if not request.arguments:
- request.reply("Cioe' bho io non lo so")
- return
-
- matches = self.search(' '.join(request.arguments))
- num_results = matches.get_matches_estimated()
-
- if not num_results:
- request.reply("Non abbiamo trovato un cazzo! (cit.)")
- return
-
- request.reply("%i results found" % num_results)
-
- for match in matches:
- text = unicode(match.document.get_data(), 'utf-8', 'replace')
- id = match.document.get_value(xapian_quote_id)
- id = int(id)
- request.reply("%i: %i%% %i, %s" % (match.rank + 1, match.percent,
- id, text))
-
- def fai(self, event):
- log.msg("Hanno chiesto get_quote di %i" % event.data.id)
-
-
-if __name__ == '__main__':
- # This should ONLY be used to populate a NEW xapian database with an
- # existing Quotes database.
-
- # This will read all quotes from the database specified on the command line
- # and write the Xapian database.
-
- # Usage: python plugins/xapiansearch.py <quotes.db> <xapian_db_dir>
-
- from quotedb import Quote
- from sqlalchemy import create_engine
- from sqlalchemy.orm import sessionmaker
-
- class FakeConfig(object):
- def __init__(self, xapian_db):
- self.xapian_db = xapian_db
-
- if len(sys.argv) > 2:
- db_file = 'sqlite:///' + sys.argv[1]
- xapian_db = sys.argv[2]
- cfg = FakeConfig(xapian_db)
-
- x = XapianSearch()
- x.activate(cfg)
-
- engine = create_engine(db_file, echo=False)
- Session = sessionmaker(bind=engine)
- session = Session()
-
- print "Adding quotes: ",
-
- for quote in session.query(Quote).all():
- x.add_quote(quote)
- print ".",
- sys.stdout.flush()
diff --git a/plugins.old/xapiansearch.yapsy-plugin b/plugins.old/xapiansearch.yapsy-plugin
deleted file mode 100644
index 55e9287..0000000
--- a/plugins.old/xapiansearch.yapsy-plugin
+++ /dev/null
@@ -1,8 +0,0 @@
-[Core]
-Name = Xapian Support
-Module = xapiansearch
-
-[Documentation]
-Description = Xapian search and database support
-Author = sand
-Version = 0.1