mirror of
https://github.com/erkin/ponysay.git
synced 2024-11-22 04:27:58 +01:00
setup fixes
Signed-off-by: Mattias Andrée <maandree@operamail.com>
This commit is contained in:
parent
64b7b6a2ec
commit
f0f5a81d24
4 changed files with 38 additions and 17 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -31,6 +31,7 @@
|
|||
/*ponies/heights
|
||||
/*ponies/onlyheights
|
||||
/*ponies/widths
|
||||
/*ponies/metadata
|
||||
|
||||
|
||||
## Texinfo manual stuff
|
||||
|
|
|
@ -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
|
||||
|
|
22
setup.py
22
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
|
||||
if not self.free:
|
||||
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()
|
||||
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()
|
||||
|
||||
|
|
|
@ -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<str>? 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<str>? 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()
|
||||
|
||||
|
|
Loading…
Reference in a new issue