From 456a11aa54c23a06a6d7f2ee1fa4755531f3a83c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Andr=C3=A9e?= Date: Sun, 18 Aug 2013 12:43:03 +0200 Subject: [PATCH] do not bias toward images with symlinks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- manuals/ponysay.texinfo | 4 +++- setup.py | 16 +++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/manuals/ponysay.texinfo b/manuals/ponysay.texinfo index ee3618b8..bce33b4e 100644 --- a/manuals/ponysay.texinfo +++ b/manuals/ponysay.texinfo @@ -2586,7 +2586,7 @@ comment field. Leading line breaks in the comment field is ignored. @cindex pony 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 using gdbm. If you later uninstall gdbm, you will have to reinstall ponysay 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 were to long and quotes had to be duplicated. And Pinkie Pie became even more likely to be randomly selected. +@item +Random selection algorithm with biased towards images with symlink alternatives. @end itemize diff --git a/setup.py b/setup.py index 2658687f..edc67a97 100755 --- a/setup.py +++ b/setup.py @@ -522,7 +522,7 @@ class Setup(): if filein is not None: filein .close() 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]: if hasponies and os.path.isdir(sharedir): @@ -626,7 +626,7 @@ class Setup(): if conf[file[0]] is not None: self.cp(False, 'share/' + file[1], [ponyshare + file[0]], Setup.validateFreedom if self.free else 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) for file in miscfiles: 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: files.append(ponyshare + file[0]) files.append(ponyshare + 'by-file') + files.append(ponyshare + 'by-image') files.append(ponyshare + 'by-master') for file in miscfiles: files.append(conf[file[0]]) @@ -717,7 +718,7 @@ class Setup(): def clean(self): 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] dirs = [] for comp in ['install', 'gz', 'xz']: @@ -759,7 +760,7 @@ class Setup(): Generate quotes database ''' @staticmethod - def makeQuotesDatabase(ponydir, quotedir, masterdb, filedb, validatehook): + def makeQuotesDatabase(ponydir, quotedir, masterdb, imagedb, filedb, validatehook): allponies = {} ponies = os.listdir(quotedir,) for pony in ponies: @@ -817,7 +818,7 @@ class Setup(): continue 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: if pony not in by_file: by_file[pony] = [] @@ -828,6 +829,11 @@ class Setup(): db[key] = ' '.join(by_master[key]) 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') for key in by_file: db[key] = ' '.join(by_file[key])