コード例 #1
0
ファイル: FaqCommand.py プロジェクト: ArildF/rogie
    def listFaqs( self, sock, words ):
        """lists all faqs currently in database"""

        if not Config.getConfig().getInt( "faq", "allowlistinroom" ):
            if not self.isPm:
                raise Command.CommandError( "faq -list is only allowed in PM" )
        if ( len( words ) > 0 ):
            ownerArg = words[ 0 ]
        files = os.listdir( self.faqDir )

        outString = "Faqs currently in database: "
        outList = []
        for file in files:
            if file[ -4: ] == self.faqExt:
                # get faq info
                faqname = file[:-4]
                faq = Faq.loadFaq( faqname )
                owner = faq.getAuthor()
                #if no owner arg list all faqs
                if ( len( words ) > 0 ):
                    if(owner == ownerArg):
                        outList.append( file[ :-4 ] )
                else:
                    outList.append( file[ :-4 ] )
        outList.sort()

        outString = outString + string.join( outList, ", " )

        self.sendMessage( sock, outString )
コード例 #2
0
ファイル: FaqCommand.py プロジェクト: ArildF/rogie
    def faqStats( self, sock, words ):
        """counts the number of faqs in database per owner"""
        files = os.listdir( self.faqDir )
        # dictionary for owner count
        ownerCount = {}

        # read each faq file & get the pertinant fields for the faq
        for filename in files:
            if filename[ -4: ] == self.faqExt:
                #get rid of .faq in filename to get faq name
                faqname = filename[:-4]
                try:
                    
                    contents = Faq.loadFaq( faqname )
                    owner = contents.getAuthor()
                    if ownerCount.has_key(owner):
                       ownerCount[owner] = ownerCount[owner] + 1
                    else:
                        ownerCount[owner] = 1
                except:
                    pass
        #in responst to rats complaints about being dinged by this command                    
        ratscount = ownerCount["couldnt_give_a_rats_ass"]
        del ownerCount["couldnt_give_a_rats_ass"]
        ownerCount["cou1dnt give a rats ass"] = ratscount

        # move to list of count/name tuples so can sort on count
        items = [(v, k) for k, v in ownerCount.items()]
        items.sort()
        items.reverse()    # so largest is first
         
        # convert to name/count list of strings so join can me used to make the string
        # (join won't work woth a list of tuples)
        nameCountList = []
        for countName in items:        
            nameCountList.append(countName[1]+ ":" + repr(countName[0]))
         
        # make the final string
        outString = "owner stats: " + string.join( nameCountList, ", ")
        self.sendMessage( sock, outString )
コード例 #3
0
ファイル: SqliteImport.py プロジェクト: ArildF/rogie
from SqliteFaqStore import SqliteFaqStore, FaqStoreError
import os, glob, sys
import Faq

def Usage():
    print >> sys.stderr, "Usage: %s DBFILE FAQDIR" % sys.argv[0]    

if len( sys.argv ) != 3:
    Usage()
    sys.exit( 1 )
    
dbfile = sys.argv[1]
faqdir = sys.argv[2]

Faq.setFaqDir( faqdir )
Faq.setFaqExt( ".faq" )
store = SqliteFaqStore( dbfile )

files = glob.glob( os.path.join( faqdir, "*.faq" ) )
proxies = {}
for file in files:
    faqname = os.path.splitext( os.path.split( file )[1] )[0]
    print "Doing %s" % faqname
    faq = Faq.loadFaq( faqname )
    if faq.isProxy():
        proxies[faqname] =  faq
    else:
        store.newFaq( faqname, contents = faq.getFaq(), author = faq.getAuthor() )

for proxy in proxies.keys():
    target = proxies[proxy].getTarget()