Recipe Collect Data Files

Nat Picker edited this page Sep 21, 2015 · 2 revisions

Put the following snippet into your .spec file:

def Datafiles(*filenames, **kw):
    import os

    def datafile(path, strip_path=True):
        parts = path.split('/')
        path = name = os.path.join(*parts)
        if strip_path:
            name = os.path.basename(path)
        return name, path, 'DATA'

    strip_path = kw.get('strip_path', True)
    return TOC(
        datafile(filename, strip_path=strip_path)
        for filename in filenames
        if os.path.isfile(filename))

Now collect your datafiles ...

docfiles = Datafiles('LICENSE-GPLv3.txt', 'doc/pdfposter.html')
dbfile = Datafiles('db/countries.db', strip_path=False) # keep the path of this file

... and add the collected files to the COLLECT() call:

coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               docfiles,
               dbfile,
               name=os.path.join('dist', 'pdfposter'))