do not bias toward images with symlinks

Signed-off-by: Mattias Andrée <maandree@operamail.com>
This commit is contained in:
Mattias Andrée 2013-08-18 12:43:03 +02:00
parent b2eeeff049
commit 456a11aa54
2 changed files with 14 additions and 6 deletions

View file

@ -2586,7 +2586,7 @@ comment field. Leading line breaks in the comment field is ignored.
@cindex pony quote infrastructure @cindex pony quote infrastructure
@cindex quote infrastructure @cindex quote infrastructure
When compiling, two indices for the pony quotes are built. These indices When compiling, three indices for the pony quotes are built. These indices
are dbm databases; if you have gdbm, which you probably have, python will are dbm databases; if you have gdbm, which you probably have, python will
using gdbm. If you later uninstall gdbm, you will have to reinstall ponysay using gdbm. If you later uninstall gdbm, you will have to reinstall ponysay
so it is built without, gdbm. so it is built without, gdbm.
@ -2616,6 +2616,8 @@ installed files. This just happened to be solved at the same time.
Pinkie Pie had so many images that the resolution quote files' names Pinkie Pie had so many images that the resolution quote files' names
were to long and quotes had to be duplicated. And Pinkie Pie became were to long and quotes had to be duplicated. And Pinkie Pie became
even more likely to be randomly selected. even more likely to be randomly selected.
@item
Random selection algorithm with biased towards images with symlink alternatives.
@end itemize @end itemize

View file

@ -522,7 +522,7 @@ class Setup():
if filein is not None: filein .close() if filein is not None: filein .close()
if conf['ponyquotes'] is not None: if conf['ponyquotes'] is not None:
Setup.makeQuotesDatabase('ponies', 'ponyquotes', 'share/by-master', 'share/by-file', Setup.validateFreedom if self.free else None) Setup.makeQuotesDatabase('ponies', 'ponyquotes', 'share/by-master', 'share/by-image', 'share/by-file', Setup.validateFreedom if self.free else None)
for (sharedir, hasponies) in [(sharedir[0], sharedir[3]) for sharedir in sharedirs]: for (sharedir, hasponies) in [(sharedir[0], sharedir[3]) for sharedir in sharedirs]:
if hasponies and os.path.isdir(sharedir): if hasponies and os.path.isdir(sharedir):
@ -626,7 +626,7 @@ class Setup():
if conf[file[0]] is not None: if conf[file[0]] is not None:
self.cp(False, 'share/' + file[1], [ponyshare + file[0]], Setup.validateFreedom if self.free else None) self.cp(False, 'share/' + file[1], [ponyshare + file[0]], Setup.validateFreedom if self.free else None)
if conf['ponyquotes'] is not None: if conf['ponyquotes'] is not None:
for file in ('by-file', 'by-master'): for file in ('by-file', 'by-image', 'by-master'):
self.cp(False, 'share/' + file, [ponyshare + file], Setup.validateFreedom if self.free else None) self.cp(False, 'share/' + file, [ponyshare + file], Setup.validateFreedom if self.free else None)
for file in miscfiles: for file in miscfiles:
self.cp(False, file[0], [conf[file[0]]], Setup.validateFreedom if self.free else None) self.cp(False, file[0], [conf[file[0]]], Setup.validateFreedom if self.free else None)
@ -678,6 +678,7 @@ class Setup():
if conf[file[0]] is not None: if conf[file[0]] is not None:
files.append(ponyshare + file[0]) files.append(ponyshare + file[0])
files.append(ponyshare + 'by-file') files.append(ponyshare + 'by-file')
files.append(ponyshare + 'by-image')
files.append(ponyshare + 'by-master') files.append(ponyshare + 'by-master')
for file in miscfiles: for file in miscfiles:
files.append(conf[file[0]]) files.append(conf[file[0]])
@ -717,7 +718,7 @@ class Setup():
def clean(self): def clean(self):
print('\033[1;34m::\033[39mCleaning...\033[21m') print('\033[1;34m::\033[39mCleaning...\033[21m')
files = ['ponysay.info', 'ponysay.info.gz', 'ponysay.info.xz', 'ponysay.pdf.gz', 'ponysay.pdf.xz', 'ponysay.install', 'share/by-file', 'share/by-master'] files = ['ponysay.info', 'ponysay.info.gz', 'ponysay.info.xz', 'ponysay.pdf.gz', 'ponysay.pdf.xz', 'ponysay.install', 'share/by-file', 'share/by-image', 'share/by-master']
files += ['src/%s.install' % file for file in ponysaysrc] files += ['src/%s.install' % file for file in ponysaysrc]
dirs = [] dirs = []
for comp in ['install', 'gz', 'xz']: for comp in ['install', 'gz', 'xz']:
@ -759,7 +760,7 @@ class Setup():
Generate quotes database Generate quotes database
''' '''
@staticmethod @staticmethod
def makeQuotesDatabase(ponydir, quotedir, masterdb, filedb, validatehook): def makeQuotesDatabase(ponydir, quotedir, masterdb, imagedb, filedb, validatehook):
allponies = {} allponies = {}
ponies = os.listdir(quotedir,) ponies = os.listdir(quotedir,)
for pony in ponies: for pony in ponies:
@ -817,7 +818,7 @@ class Setup():
continue continue
count = allponies[master] count = allponies[master]
by_master[master] = [count] + ponies by_master[master] = [count] + filter(lambda p : not os.path.islink('%s/%s.pony' % (ponydir, p)), ponies)
for pony in ponies: for pony in ponies:
if pony not in by_file: if pony not in by_file:
by_file[pony] = [] by_file[pony] = []
@ -828,6 +829,11 @@ class Setup():
db[key] = ' '.join(by_master[key]) db[key] = ' '.join(by_master[key])
db.close() db.close()
db = dbm.open(imagedb, 'n')
for key in filter(lambda p : not os.path.islink('%s/%s.pony' % (ponydir, p)), by_file.keys()):
db[key] = ' '.join(by_file[key])
db.close()
db = dbm.open(filedb, 'n') db = dbm.open(filedb, 'n')
for key in by_file: for key in by_file:
db[key] = ' '.join(by_file[key]) db[key] = ' '.join(by_file[key])