Example #1
0
    def _check_ndk(self):
        ndk_arg = False
        ndk_path = os.path.join(os.environ['HOME'], 'android/ndk')

        argc = len(sys.argv)
        for i in range(1, argc):
            arg = sys.argv[i]
            if arg == "--NDK" and i < argc - 1:
                ndk_path = sys.argv[i + 1]
                ndk_arg = True
                break

            elif arg.startswith("--NDK="):
                arg, val = arg.split("=")
                ndk_path = val.strip()
                ndk_arg = True
                break

        if not ndk_arg:
            Log.w(
                "WARNING: No --NDK argument detected, using default NDK path ( ~/android/ndk )."
            )

        if not os.path.isdir(ndk_path):
            Log.w( ( "WARNING: You don't have the NDK installed on '%s', either install it or make sure "  % ndk_path ) + \
                   "to override the environment variables ANDROID_* in your Makefile before compiling." )

        return ndk_path
Example #2
0
    def do_create(self, path):
        shutil.copytree(self.mypath, path)

        Log.d("  Creating project '.fido' file ...")

        with open(os.path.join(path, '.fido'), 'w+t') as fd:
            fd.write(
                "# Do not remove this file, check out FIDO at https://github.com/evilsocket/fido\n"
            )
            fd.write(self.get_name())

        self.vars["#PROJECT_NAME#"] = os.path.basename(path)

        if self.get_name() == "rospkg":
            include_dir = os.path.join(path, 'include')
            project_dir = os.path.join(include_dir,
                                       self.vars["#PROJECT_NAME#"])
            os.makedirs(project_dir)
            # add a place holder for the header file
            with open(os.path.join(project_dir, 'main.hpp'), 'w+t') as fh:
                fh.write("// header file. ")

        for root, dirnames, filenames in os.walk(path):
            for fname in filenames:
                filename = os.path.join(root, fname)
                self._update_template_data(filename)
Example #3
0
    def _check_ndk(self):
        ndk_arg  = False
        ndk_path = os.path.join( os.environ['HOME'], 'android/ndk' )

        argc = len(sys.argv)
        for i in range(1,argc):
            arg = sys.argv[i]
            if arg == "--NDK" and i < argc - 1:
                ndk_path = sys.argv[i + 1]
                ndk_arg = True
                break

            elif arg.startswith("--NDK="):
                arg, val = arg.split("=")
                ndk_path = val.strip()
                ndk_arg = True
                break

        if not ndk_arg:
            Log.w( "WARNING: No --NDK argument detected, using default NDK path ( ~/android/ndk )." )

        if not os.path.isdir(ndk_path):
            Log.w( ( "WARNING: You don't have the NDK installed on '%s', either install it or make sure "  % ndk_path ) + \
                   "to override the environment variables ANDROID_* in your Makefile before compiling." )

        return ndk_path
Example #4
0
    def _update_template_data(self, filename):
        self.vars["#BASE_NAME#"] = os.path.basename(filename)
        self.vars["#FILE_SLUG#"] = re.sub( r'[^a-z0-9]+', '_', self.vars["#BASE_NAME#"] ).upper()

        with open(filename, 'rt') as fd:
            data = fd.read()

        for token, value in self.vars.iteritems():
            if token in data:
                Log.d( "  Updating variable '%s' in %s ..." % ( token, filename ) )
                data = data.replace( token, value )

        with open(filename, 'wt') as fd:
            fd.write(data)
Example #5
0
    def do_create(self, path):
        shutil.copytree( self.mypath, path )

        Log.d( "  Creating project '.fido' file ..." )

        with open( os.path.join( path, '.fido' ), 'w+t' ) as fd:
            fd.write( "# Do not remove this file, check out FIDO at https://github.com/evilsocket/fido\n" )
            fd.write( self.get_name() )

        self.vars["#PROJECT_NAME#"] = os.path.basename(path)

        for root, dirnames, filenames in os.walk( path ):
            for fname in filenames:
                filename = os.path.join( root, fname )
                self._update_template_data(filename)
Example #6
0
    def do_add(self):
        if len(sys.argv) < 3:
            Log.fatal(
                "Usage: fido add <filename>( <filename> <filename> ... )")

        for i in range(2, len(sys.argv)):
            filename = sys.argv[i]
            name, ext = os.path.splitext(filename)
            ext = ext.lower()

            if ext in ('.h', '.hpp'):
                destination = 'include'

            elif ext in ('.c', '.cpp'):
                destination = 'src'

            else:
                destination = '.'

            filename = os.path.join(destination, filename)
            dirname = os.path.dirname(filename)

            if os.path.isfile(filename):
                Log.fatal("File '%s' already exists." % filename)

            Log.i("Creating '%s' ..." % filename)

            # make sure every folder is created
            if not os.path.isdir(dirname):
                os.makedirs(dirname)

            tpl_name = os.path.join(os.path.expanduser('~'),
                                    ".fido/template%s" % ext)

            # check if a user template is available
            if os.path.isfile(tpl_name):
                Log.i("Using user template '%s' ..." % tpl_name)
                shutil.copy(tpl_name, filename)

                self.vars["#PROJECT_NAME#"] = os.path.basename(os.getcwd())

                self._update_template_data(filename)

            else:
                # 'touch' it
                # add #ifdefs by default to headers
                target = open(filename, 'a')
                if ext in ('.h', '.hpp'):
                    target.write("#ifndef " + name.upper() + "_" +
                                 ext.upper()[1:] + "\n")
                    target.write("#define " + name.upper() + "_" +
                                 ext.upper()[1:] + "\n")
                    target.write("\n")
                    target.write("#endif")
                target.close()
Example #7
0
    def do_add(self):
        if len(sys.argv) < 3:
            Log.fatal( "Usage: fido add <filename>( <filename> <filename> ... )" )

        for i in range(2, len(sys.argv)):
            filename  = sys.argv[i]
            name, ext = os.path.splitext( filename )
            ext = ext.lower()

            if ext in ( '.h', '.hpp' ):
                destination = 'include'

            elif ext in ( '.c', '.cpp' ):
                destination = 'src'

            else:
                destination = '.'

            filename = os.path.join( destination, filename )
            dirname  = os.path.dirname( filename )

            if os.path.isfile(filename):
                Log.fatal( "File '%s' already exists." % filename )

            Log.i( "Creating '%s' ..." % filename )

            # make sure every folder is created
            if not os.path.isdir(dirname):
                os.makedirs( dirname )

            tpl_name = os.path.join( os.path.expanduser('~'), ".fido/template%s" % ext )

            # check if a user template is available
            if os.path.isfile( tpl_name ):
                Log.i( "Using user template '%s' ..." % tpl_name )
                shutil.copy( tpl_name, filename )

                self.vars["#PROJECT_NAME#"] = os.path.basename( os.getcwd() )

                self._update_template_data(filename)

            else:
                # 'touch' it
                # add #ifdefs by default to headers
                target = open( filename, 'a')
                if ext in ( '.h', '.hpp' ):
                  target.write("#ifndef " + name.upper() + "_" + ext.upper()[1:] + "\n")
                  target.write("#define " + name.upper() + "_" + ext.upper()[1:] + "\n")
                  target.write("\n")
                  target.write("#endif")
                target.close()
Example #8
0
 def do_reset(self):
     Log.w( "Action not implemented for this template." )