Changeset 5866

Show
Ignore:
Timestamp:
08/31/10 12:36:38 (3 years ago)
Author:
ganja
Message:

Intial structure with dependency checks

Location:
packet-manipulator/branches/BTSniffer_ganja
Files:
4 added
1 modified
1 copied

Legend:

Unmodified
Added
Removed
  • packet-manipulator/branches/BTSniffer_ganja/BTSniffer/btcompile.py

    r5858 r5866  
    77import shutil 
    88import re 
     9import subprocess 
    910 
    10 # build and setup commands 
    11 CMD_BUILD               = 'python setup.py build' 
     11class btcompile(): 
    1212 
    13 PATH_PM             = '../' 
    14 PATH_BUILD                      = 'build/' 
    15 WANTED_FILE_EXTS        = ['py','so'] 
    16 PATH_BT_BACKEND         = PATH_PM + 'umit/pm/backend/bt_sniffer/' 
    17 PATH_BT_PINCRACK        = PATH_PM + 'btpincrack-v0.3' 
    18 PATH_LIB_PREFIX         = '%slib.linux' % PATH_BUILD 
     13    def __init__(self): 
     14        # build and setup commands 
     15        self.CMD_BUILD          = 'python setup.py build' 
    1916 
    20 def _cpfunc(arg, dirname, flist): 
    21         if PATH_LIB_PREFIX in dirname: 
    22                 for f in flist: 
    23                         if f[f.rfind('.') + 1:] in WANTED_FILE_EXTS: 
    24                                 srcfile = os.path.join(dirname, f) 
    25                                 shutil.copy2(srcfile, PATH_BT_BACKEND) 
     17        self.PATH_PM            = '../' 
     18        self.PATH_BUILD                 = 'build/' 
     19        self.WANTED_FILE_EXTS   = ['py','so'] 
     20        self.PATH_BT_BACKEND    = self.PATH_PM + 'umit/pm/backend/bt_sniffer/' 
     21        self.PATH_BT_PINCRACK   = self.PATH_PM + 'btpincrack-v0.3' 
     22        self.PATH_LIB_PREFIX    = '%slib.linux' % self.PATH_BUILD 
     23        self.dependency         = 'dep_check' 
     24        self.python_dev_file         = self.dependency + '/' + 'python-dev.c' 
     25        self.bluetooth_dev_file      = self.dependency + '/' + 'bluetooth-dev.c' 
    2626 
    27 # Only runs on Linux 
    28 if sys.platform == 'linux2': 
     27        self.blue_deps = [ 'Bluez :- The Linux Bluetooth Stack', 
     28                            'Bluetooth', 
     29                            'Libbluetooth-dev' 
     30                           ] 
     31        self.python_deps = ['python-dev : Header files and a static library for Python'] 
    2932 
    30     #Compile and copy the C files for BTSniffer to PATH_BT_BACKEND 
    31     os.system(CMD_BUILD) 
    32     if os.path.exists(PATH_BT_BACKEND): 
    33             shutil.rmtree(PATH_BT_BACKEND)         
    34     os.makedirs(PATH_BT_BACKEND) 
    35     os.path.walk(PATH_BUILD, _cpfunc, None) 
     33    def _cpfunc(self,arg, dirname, flist): 
     34            if self.PATH_LIB_PREFIX in dirname: 
     35                    for f in flist: 
     36                            if f[f.rfind('.') + 1:] in self.WANTED_FILE_EXTS: 
     37                                    srcfile = os.path.join(dirname, f) 
     38                                    shutil.copy2(srcfile, self.PATH_BT_BACKEND) 
    3639 
    37     #Delete old btpincrack in PM, copy it again 
    38     if os.path.exists(PATH_BT_PINCRACK): 
    39         shutil.rmtree(PATH_BT_PINCRACK) 
    40     shutil.copytree('btpincrack-v0.3',PATH_BT_PINCRACK) 
     40     
     41    def gcc(self):#check if gcc is present 
     42        return True 
    4143 
    42          
    43 else: 
    44         print   'Many apologies. This is not possible at this stage.'\ 
    45                         'Devt of BTSniffer is still limited to Linux. Thank ' \ 
    46                         'you for trying nonetheless.' 
     44    def python_dev(self): 
     45        proc = subprocess.Popen('gcc ' + self.python_dev_file, 
     46                                    shell=True, 
     47                                    stderr=subprocess.PIPE 
     48                                   ) 
     49        # Need to pass -I/usr/include/python2.6 as compile time argument, find better way 
     50        for dep in self.python_deps: 
     51            print dep 
     52        return False 
    4753 
     54    def blue_dev(self): 
     55        proc = subprocess.Popen('gcc ' + self.bluetooth_dev_file, 
     56                                    shell=True, 
     57                                    stderr=subprocess.PIPE 
     58                                   ) 
     59        #No errors if strlength is 0 
     60        if len(proc.communicate()[1])==0: 
     61            return True 
     62         
     63        for dep in self.blue_deps: 
     64            print dep 
     65        return False 
    4866 
     67    def make(self): 
     68        if self.gcc(): 
     69            blue_check=self.blue_dev() 
     70            python_check=self.python_dev() 
     71         
     72            if blue_check or python_check: 
     73                return False 
    4974 
     75            #Compile and copy the C files for BTSniffer to PATH_BT_BACKEND 
     76            os.system(self.CMD_BUILD) 
     77            if os.path.exists(self.PATH_BT_BACKEND): 
     78                shutil.rmtree(self.PATH_BT_BACKEND)         
     79            os.makedirs(self.PATH_BT_BACKEND) 
     80            os.path.walk(self.PATH_BUILD, self._cpfunc, None) 
    5081 
     82            #Delete old btpincrack in PM, copy it again 
     83            if os.path.exists(self.PATH_BT_PINCRACK): 
     84                shutil.rmtree(self.PATH_BT_PINCRACK) 
     85            shutil.copytree('btpincrack-v0.3',self.PATH_BT_PINCRACK) 
    5186 
     87        else: 
     88            return False 
    5289 
     90#btcompile().make() 
  • packet-manipulator/branches/BTSniffer_ganja/setup.py

    r5449 r5866  
    3131from distutils.command.build import build 
    3232from umit.pm.core.const import PM_VERSION, PM_SITE 
     33from BTSniffer.btcompile import btcompile as btcompile 
    3334 
    3435ROOT_DIR = os.path.abspath(os.path.dirname(__file__)) 
     
    3637                             'PacketManipulator-%s' % PM_VERSION) 
    3738DOCS_DIR = os.path.join(ROOT_DIR, 'generated-doc', 'html') 
     39PACKAGES = ['umit', 
     40           'umit.pm', 
     41           'umit.pm.backend', 
     42           'umit.pm.backend.abstract', 
     43           'umit.pm.backend.abstract.basecontext', 
     44           'umit.pm.backend.abstract.context', 
     45           'umit.pm.backend.scapy', 
     46           'umit.pm.backend.scapy.context', 
     47           'umit.pm.backend.umpa', 
     48           'umit.pm.backend.umpa.context', 
     49           'umit.pm.manager', 
     50           'umit.pm.core', 
     51           'umit.pm.gui', 
     52           'umit.pm.gui.core', 
     53           'umit.pm.gui.tabs', 
     54           'umit.pm.gui.pages', 
     55           'umit.pm.gui.sessions', 
     56           'umit.pm.gui.dialogs', 
     57           'umit.pm.gui.widgets', 
     58           'umit.pm.gui.plugins', 
     59           'umit.pm.higwidgets' 
     60           ] 
     61PACKAGE_DATA = {} 
     62#conditional append in both of these 
    3863 
    3964def getoutput(cmd): 
     
    176201        print "#" * 80 
    177202        print 
     203         
     204        #If linux, default is install btsniffer and pm 
     205        if sys.platform == 'linux2': 
     206            os.chdir('BTSniffer') 
     207 
     208            if btcompile().make(): 
     209 
     210                PACKAGES.append('umit.pm.backend.bt_sniffer') 
     211                PACKAGE_DATA['umit.pm.backend.bt_sniffer'] = ['*.so'] 
     212 
     213                of.chdir('../') 
     214 
     215            else: 
     216                print "\nInstall above listed libraries or run with --no-btsniffer argument\n" 
     217                print 
     218                print "#" * 80 
     219                print "# Installation Halted" 
     220                print "#" * 80 
     221                print 
     222                return False 
     223                 
    178224 
    179225        install.run(self) 
     
    288334      requires     = ['gtk'], 
    289335      platforms    = ['Platform Independent'], 
    290       packages     = ['umit', 
    291                       'umit.pm', 
    292                       'umit.pm.backend', 
    293                       'umit.pm.backend.abstract', 
    294                       'umit.pm.backend.abstract.basecontext', 
    295                       'umit.pm.backend.abstract.context', 
    296                       'umit.pm.backend.scapy', 
    297                       'umit.pm.backend.scapy.context', 
    298                       'umit.pm.backend.umpa', 
    299                       'umit.pm.backend.umpa.context', 
    300                       'umit.pm.manager', 
    301                       'umit.pm.core', 
    302                       'umit.pm.gui', 
    303                       'umit.pm.gui.core', 
    304                       'umit.pm.gui.tabs', 
    305                       'umit.pm.gui.pages', 
    306                       'umit.pm.gui.sessions', 
    307                       'umit.pm.gui.dialogs', 
    308                       'umit.pm.gui.widgets', 
    309                       'umit.pm.gui.plugins', 
    310                       'umit.pm.higwidgets' 
    311                      ], 
     336      packages     = PACKAGES, 
     337      package_data = PACKAGE_DATA, 
    312338      package_dir  = {'umit' : os.path.join(ROOT_DIR, 'umit')}, 
    313339      data_files   = [