diff --git a/.gitignore b/.gitignore index 1dacb630..60a24304 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ /*ponies/heights /*ponies/onlyheights /*ponies/widths +/*ponies/metadata ## Texinfo manual stuff diff --git a/manuals/ponysay.texinfo b/manuals/ponysay.texinfo index c690c57b..9bc54494 100644 --- a/manuals/ponysay.texinfo +++ b/manuals/ponysay.texinfo @@ -1367,6 +1367,10 @@ ponies will pass the @option{--restrict} option when ponies are randomly selecte A metadata colletion file's content a list, of pony files with and their corresponding metadata as a map from tag name to tag value set, serialised with Python's cPickle module. +Running @command{ponysay-tool --metadata PONY-DIR} will generate the file @file{metadata} +with the serialised information. For use by the installer, the files to include can be +explicity declared appending their basename to the command. + @node Dimension files @section Dimension files @@ -1381,7 +1385,9 @@ and may be randomly selected. Running @command{ponysay-tool --dimensions PONY-DIR} will generate three files @file{widths}, @file{heights} and @file{onlyheights} to the directory @file{PONY-DIR}, the contain optimised information about the widths, heigths and heights with printed -without the balloon, respectively, for each pony the the directory. +without the balloon, respectively, for each pony the the directory. For use by the +installer, the files to include can be explicity declared appending their basename to +the command. @node Pony browsing diff --git a/setup.py b/setup.py index 7a04f61e..a39b4105 100755 --- a/setup.py +++ b/setup.py @@ -553,15 +553,21 @@ class Setup(): for sharedir in [sharedir[0] for sharedir in sharedirs]: # TODO make this an opt-out option if os.path.isdir(sharedir): - for sharefile in os.listdir(sharedir): - if sharefile.endswith('.pony') and (sharefile != '.pony'): - sharefile = sharedir + '/' + sharefile - if self.free and not Setup.validateFreedom(sharefile): - print('Skipping metadata correction for %s, did not pass validation process made by setup settings' % sharefile) - continue - for toolcommand in ('--dimensions', '--metadata'): - print('%s, %s, %s' % ('./ponysay-tool.py', toolcommand, sharefile)) - Popen(['./ponysay-tool.py', toolcommand, sharefile], stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate() + if not self.free: + for toolcommand in ('--dimensions', '--metadata'): + print('%s, %s, %s' % ('./src/ponysay-tool.py', toolcommand, sharedir)) + Popen(['./src/ponysay-tool.py', toolcommand, sharedir], stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate() + else: + params = ['./src/ponysay-tool.py', toolcommand, sharedir, '--'] + for sharefile in os.listdir(): + if sharefile.endswith('.pony') and (sharefile != '.pony'): + if not Setup.validateFreedom(sharedir + '/' + sharefile): + print('Skipping metadata correction for %s/%s, did not pass validation process made by setup settings' % (sharedir, sharefile)) + else: + params.append(sharefile) + for toolcommand in ('--dimensions', '--metadata'): + print('%s, %s, %s (with files)' % ('./src/ponysay-tool.py', toolcommand, sharedir)) + Popen(params, stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate() print() diff --git a/src/ponysay-tool.py b/src/ponysay-tool.py index 6c6212b2..18f3bb71 100755 --- a/src/ponysay-tool.py +++ b/src/ponysay-tool.py @@ -78,10 +78,10 @@ class PonysayTool(): self.generateKMS() elif (opts['--dimensions'] is not None) and (len(opts['--dimensions']) == 1): - self.generateDimensions(opts['--dimensions'][0]) + self.generateDimensions(opts['--dimensions'][0], args.files) elif (opts['--metadata'] is not None) and (len(opts['--metadata']) == 1): - self.generateMetadata(opts['--metadata'][0]) + self.generateMetadata(opts['--metadata'][0], args.files) elif (opts['-b'] is not None) and (len(opts['-b']) == 1): try: @@ -475,11 +475,15 @@ class PonysayTool(): ''' Generate pony dimension file for a directory - @param ponydir The directory + @param ponydir:str The directory + @param ponies:itr? Ponies to which to limit ''' - def generateDimensions(self, ponydir): + def generateDimensions(self, ponydir, ponies = None): dimensions = [] + ponyset = None if (ponies is None) or (len(ponies) == 0) else set(ponies) for ponyfile in os.listdir(ponydir): + if (ponyset is not None) and (ponyfile not in ponyset): + continue if ponyfile.endswith('.pony') and (ponyfile != '.pony'): class PhonyArgParser(): def __init__(self, balloon): @@ -557,9 +561,10 @@ class PonysayTool(): ''' Generate pony metadata collection file for a directory - @param ponydir The directory + @param ponydir:str The directory + @param ponies:itr? Ponies to which to limit ''' - def generateMetadata(self, ponydir): + def generateMetadata(self, ponydir, ponies = None): if not ponydir.endswith('/'): ponydir += '/' def makeset(value): @@ -597,7 +602,10 @@ class PonysayTool(): rc.add(buf) return rc everything = [] + ponyset = None if (ponies is None) or (len(ponies) == 0) else set(ponies) for ponyfile in os.listdir(ponydir): + if (ponyset is not None) and (ponyfile not in ponyset): + continue if ponyfile.endswith('.pony') and (ponyfile != '.pony'): with open(ponydir + ponyfile, 'rb') as file: data = file.read().decode('utf8', 'replace') @@ -621,7 +629,7 @@ class PonysayTool(): data.append((key, makeset(value.replace(' ', '')))) everything.append((ponyfile[:-5], data)) import cPickle - with open(ponydir + 'metadata', 'wb') as file: + with open((ponydir + '/metadata').replace('//', '/'), 'wb') as file: cPickle.dump(everything, file, -1) file.flush()