github.com/olivere/camlistore@v0.0.0-20140121221811-1b7ac2da0199/lib/python/fusepy/low-level/setup.py (about) 1 #!/usr/bin/env python 2 ''' 3 $Id: setup.py 53 2010-02-22 01:48:45Z nikratio $ 4 5 Copyright (c) 2010, Nikolaus Rath <Nikolaus@rath.org> 6 All rights reserved. 7 8 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 9 10 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 11 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 12 * Neither the name of the main author nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 ''' 16 17 from __future__ import division, print_function 18 19 from distutils.core import setup, Command 20 import distutils.command.build 21 import sys 22 import os 23 import tempfile 24 import subprocess 25 import re 26 import logging 27 import ctypes.util 28 29 # These are the definitions that we need 30 fuse_export_regex = ['^FUSE_SET_.*', '^XATTR_.*', 'fuse_reply_.*' ] 31 fuse_export_symbols = ['fuse_mount', 'fuse_lowlevel_new', 'fuse_add_direntry', 32 'fuse_set_signal_handlers', 'fuse_session_add_chan', 33 'fuse_session_loop_mt', 'fuse_session_remove_chan', 34 'fuse_remove_signal_handlers', 'fuse_session_destroy', 35 'fuse_unmount', 'fuse_req_ctx', 'fuse_lowlevel_ops', 36 'fuse_session_loop', 'ENOATTR', 'ENOTSUP', 37 'fuse_version' ] 38 39 class build_ctypes(Command): 40 41 description = "Build ctypes interfaces" 42 user_options = [] 43 boolean_options = [] 44 45 def initialize_options(self): 46 pass 47 48 def finalize_options(self): 49 pass 50 51 def run(self): 52 '''Create ctypes API to local FUSE headers''' 53 54 # Import ctypeslib 55 basedir = os.path.abspath(os.path.dirname(sys.argv[0])) 56 sys.path.insert(0, os.path.join(basedir, 'ctypeslib.zip')) 57 from ctypeslib import h2xml, xml2py 58 from ctypeslib.codegen import codegenerator as ctypeslib 59 60 print('Creating ctypes API from local fuse headers...') 61 62 cflags = self.get_cflags() 63 print('Using cflags: %s' % ' '.join(cflags)) 64 65 fuse_path = 'fuse' 66 if not ctypes.util.find_library(fuse_path): 67 print('Could not find fuse library', file=sys.stderr) 68 sys.exit(1) 69 70 71 # Create temporary XML file 72 tmp_fh = tempfile.NamedTemporaryFile() 73 tmp_name = tmp_fh.name 74 75 print('Calling h2xml...') 76 argv = [ 'h2xml.py', '-o', tmp_name, '-c', '-q', '-I', basedir, 'fuse_ctypes.h' ] 77 argv += cflags 78 ctypeslib.ASSUME_STRINGS = False 79 ctypeslib.CDLL_SET_ERRNO = False 80 ctypeslib.PREFIX = ('# Code autogenerated by ctypeslib. Any changes will be lost!\n\n' 81 '#pylint: disable-all\n' 82 '#@PydevCodeAnalysisIgnore\n\n') 83 h2xml.main(argv) 84 85 print('Calling xml2py...') 86 api_file = os.path.join(basedir, 'llfuse', 'ctypes_api.py') 87 argv = [ 'xml2py.py', tmp_name, '-o', api_file, '-l', fuse_path ] 88 for el in fuse_export_regex: 89 argv.append('-r') 90 argv.append(el) 91 for el in fuse_export_symbols: 92 argv.append('-s') 93 argv.append(el) 94 xml2py.main(argv) 95 96 # Delete temporary XML file 97 tmp_fh.close() 98 99 print('Code generation complete.') 100 101 def get_cflags(self): 102 '''Get cflags required to compile with fuse library''' 103 104 proc = subprocess.Popen(['pkg-config', 'fuse', '--cflags'], stdout=subprocess.PIPE) 105 cflags = proc.stdout.readline().rstrip() 106 proc.stdout.close() 107 if proc.wait() != 0: 108 sys.stderr.write('Failed to execute pkg-config. Exit code: %d.\n' 109 % proc.returncode) 110 sys.stderr.write('Check that the FUSE development package been installed properly.\n') 111 sys.exit(1) 112 return cflags.split() 113 114 115 # Add as subcommand of build 116 distutils.command.build.build.sub_commands.insert(0, ('build_ctypes', None)) 117 118 119 setup(name='llfuse_example', 120 version='1.0', 121 author='Nikolaus Rath', 122 author_email='Nikolaus@rath.org', 123 url='http://code.google.com/p/fusepy/', 124 packages=[ 'llfuse' ], 125 provides=['llfuse'], 126 cmdclass={ 'build_ctypes': build_ctypes} 127 )