freebsd-ports/audio/mma/files/mma_g.py.in
Nicola Vitale 02f4720d39 - Update to 14.07
- Take maintainership
- Add LICENSE (GPLv2)
- Add audio/alsa-utils and audio/timidity++ to run dependencies
- Add support for stage-dir
- Remove files/patch-mma.py
- Add files/mma_g.py.in
- Fixx WWW field in pkg-descr
2014-07-14 22:37:59 +00:00

59 lines
1 KiB
Python

#!%%PYTHON_CMD%%
#
# -*- encoding: utf-8 -*-
import os
import pickle
import stat
def traverse(path):
for directory, dirnames, filenames in os.walk(path):
if '.mmaDB' in filenames:
mmaDB = os.path.join(directory, '.mmaDB')
mmaDB = os.path.normpath(mmaDB)
fixMMAdb(mmaDB)
def changePath(path):
path_components = path.split('/')
try:
index = path_components.index('lib') + 1
except ValueError:
return path
path_components[0:index] = []
p = '/'.join(path_components)
p = os.path.join('%%DATADIR%%/lib', p)
return p
def fixMMAdb(fn):
orig_filemode = os.stat(fn).st_mode
os.chmod(fn, orig_filemode | stat.S_IWUSR)
mmaDB = open(fn, 'r+b')
mmaDB.readline() # skip header
p = pickle.load(mmaDB)
p = dict((changePath(k), v) for k, v in p.items())
mmaDB.seek(0)
# write header
mmaDB.write(b'### mmaDB ... AUTOGENERATED BINARY DATA. DO NOT EDIT!!!\n')
pickle.dump(p, mmaDB, pickle.HIGHEST_PROTOCOL)
mmaDB.close()
os.chmod(fn, orig_filemode)
if __name__ == '__main__':
traverse('.')