Exemple #1
0
def build_component(bcomponent,install):
    paths = WS.find_component_src(bcomponent)
    if not paths:
        print("No such component exists")
        return False
    path = paths[0]
    srcpath = WS.find_workspace(path) + '/src'
    
    #ignore other components
    ignored_comps=[]
    for component in os.listdir(srcpath):
        if bcomponent == component or os.path.isdir(os.path.join(srcpath, component))==False or os.path.exists(os.path.join(srcpath,component,'IGNORE_COMP'))  :
            continue
        ignored_comps.append(component)
        os.system("touch " + os.path.join(srcpath,component,'IGNORE_COMP') )
    
    #build
    os.chdir(srcpath)
    os.chdir("../build")
    if install != 'notgiven' and install:
        os.system("cmake ../src -DRC_COMPONENT_INSTALL_PATH='"+str(os.path.abspath(install)) + "'")
    else:
        os.system('cmake ../src')

    if install == 'notgiven':
        os.system('make')
    elif install == None:
        os.system("sudo make install")
    else:
        os.system("make install ")
    
    #unignore other components
    for comp in ignored_comps:
        os.system("rm -f " + os.path.join(srcpath,comp,'IGNORE_COMP'))
Exemple #2
0
def find_script(action, component):
    paths = WS.find_component_exec(component)
    pathsrc = WS.find_component_src(component)
    pathsrc = [os.path.join(x, 'bin') for x in pathsrc]
    pathsrc.append(paths)
    for path in pathsrc:
        for file in os.listdir(path):
            if file[-3:] == '.sh' or file[-5:] == '.bash':
                if string.lower(file[:len(action)]) == string.lower(action):
                    return os.path.join(path, file)
    return False
Exemple #3
0
def find_script(action,component):
    paths = WS.find_component_exec(component)
    pathsrc = WS.find_component_src(component)
    pathsrc = [ os.path.join(x,'bin') for x in pathsrc]
    pathsrc.append(paths)
    for path in pathsrc:
        for file in os.listdir(path):
            if file[-3:] == '.sh' or file[-5:] == '.bash':
                if string.lower(file[:len(action)])==string.lower(action):
                    return os.path.join(path,file)
    return False
Exemple #4
0
def build_docs(component,install=False,installpath='/opt/robocomp'):
    paths = WS.find_component_src(component)
    if not paths:
        print("No such component exists")
        return False
    path = paths[0]
    os.chdir(path)
    if install == True:
        try:
            os.system('mkdir -p '+installpath+'/doc')
            os.system(' sudo cp -R doc/html '+installpath+'/doc/'+string.lower(component))
        except Exception, e:
            raise RuntimeError("couldnt install doc files {0}".format(e))
Exemple #5
0
def build_docs(component, install=False, installpath='/opt/robocomp'):
    paths = WS.find_component_src(component)
    if not paths:
        print("No such component exists")
        return False
    path = paths[0]
    os.chdir(path)
    if install == True:
        try:
            os.system('mkdir -p ' + installpath + '/doc')
            os.system(' sudo cp -R doc/html ' + installpath + '/doc/' +
                      string.lower(component))
        except Exception, e:
            raise RuntimeError("couldnt install doc files {0}".format(e))
Exemple #6
0
def build_component(bcomponent, install):
    paths = WS.find_component_src(bcomponent)
    if not paths:
        print("No such component exists")
        return False
    path = paths[0]
    srcpath = WS.find_workspace(path) + '/src'

    #ignore other components
    ignored_comps = []
    for component in os.listdir(srcpath):
        if bcomponent == component or os.path.isdir(
                os.path.join(srcpath, component)) == False or os.path.exists(
                    os.path.join(srcpath, component, 'IGNORE_COMP')):
            continue
        ignored_comps.append(component)
        os.system("touch " + os.path.join(srcpath, component, 'IGNORE_COMP'))

    #build
    os.chdir(srcpath)
    os.chdir("../build")
    if install != 'notgiven' and install:
        os.system("cmake ../src -DRC_COMPONENT_INSTALL_PATH='" +
                  str(os.path.abspath(install)) + "'")
    else:
        os.system('cmake ../src')

    if install == 'notgiven':
        os.system('make')
    elif install == None:
        os.system("sudo make install")
    else:
        os.system("make install ")

    #unignore other components
    for comp in ignored_comps:
        os.system("rm -f " + os.path.join(srcpath, comp, 'IGNORE_COMP'))
Exemple #7
0
def main():
    parser = argparse.ArgumentParser(
        description="Locate and run a robocomp component")
    group = parser.add_mutually_exclusive_group(required=True)
    cgroup = parser.add_mutually_exclusive_group()
    parser.add_argument('component',
                        help='component name').completer = complete_components
    group.add_argument('-s',
                       '--start',
                       action='store_true',
                       help="start component")
    group.add_argument('-st',
                       '--stop',
                       action='store_true',
                       help="stop component")
    group.add_argument('-fst',
                       '--fstop',
                       action='store_true',
                       help=" force stop component")
    cgroup.add_argument('-d',
                        '--debug',
                        action='store_true',
                        help="start a component in debug mode")
    cgroup.add_argument('-cf',
                        '--cfile',
                        nargs=1,
                        help="use custom ice config file (absolute path)")
    cgroup.add_argument(
        '-c',
        '--config',
        nargs=1,
        help="ice config file to choose from default config directory"
    ).completer = complete_scripts
    parser.add_argument('-is',
                        '--ignore_scripts',
                        action='store_true',
                        help="ignore all the script files if found")

    argcomplete.autocomplete(parser)
    args = parser.parse_args()

    component = args.component

    #if stop command no need for searching and all
    if args.stop:
        if not WS.find_component_exec(component):
            args.error(
                "couldnt find the component %s in any of the workspaces" %
                (args.stop[0]))
            return
        stpath = find_script("stop", component)
        if stpath and not args.ignore_scripts:
            #print("using script {0}".format(stpath))
            command = stpath
        else:
            command = "killall " + str(component)
        os.system(command)
        return
    elif args.fstop:
        if not WS.find_component_exec(component):
            parser.error(
                "couldnt find the component %s in any of the workspaces" %
                (args.fstop[0]))
            return
        sfpath = find_script("forcestop", component)
        if sfpath and not args.ignore_scripts:
            #print("using script {0}".format(sfpath))
            command = sfpath
        else:
            command = "killall -9 " + str(component)
        os.system(command)
        return

    #search for the component
    componentPath = WS.find_component_exec(component)

    if not componentPath:
        if not WS.find_component_src(component):
            print("couldnt find the component %s in any of the workspaces" %
                  (component))
        else:
            print(
                "couldnt find the target please build it first using rcbuild %s "
                % (component))
        return

    componentPathetc = componentPath[:-4]

    #find the config file
    '''
        if only one file is present in the etc directory then it will be used
        else if it has file named config the it will be used 
        if it has file named generic_config it will be used
        else we will use a random file
        user defined config file will override all the above
    '''
    configFiles = []
    configPath = componentPathetc + '/etc'
    ice_config = ""
    for root, dirs, files in os.walk(configPath):
        configFiles = files
    if len(configFiles) == 0:
        parser.error(
            "couldnt find any config file in the etc directory, please specify a custom config file\n"
        )
    else:
        if args.debug:
            for file in configFiles:
                if file.endswith('.debug'):
                    ice_config = configPath + "/" + file
            if len(ice_config) < 9:
                parser.error(
                    "couldnt find any debug config file in the etc directory, please specify a custom config file\n"
                )
        else:
            if len(configFiles) == 1:
                ice_config = configPath + "/" + configFiles[0]
            else:
                if "config" in configFiles:
                    ice_config = configPath + "/config"
                elif 'generic_config' in configFiles:
                    ice_config = configPath + "/generic_config"
                else:
                    ice_config = configPath + "/" + configFiles[0]

    if args.config:
        if args.config[0] in configFiles:
            ice_config = configPath + "/" + args.config[0]
        else:
            parser.error(
                "couldnt find config file '{0}' in the etc directory".format(
                    args.config[0]))
    elif args.cfile:
        ice_config = args.config[0]

    #execute the command
    spath = find_script("start", component)
    sdpath = find_script("startdebug", component)

    if args.start:
        if spath and not (args.config or args.cfile
                          or args.debug) and not args.ignore_scripts:
            command = spath
        elif sdpath and args.debug and not args.ignore_scripts:
            command = sdpath
        else:
            command = componentPath + "/" + string.lower(
                component) + " --Ice.Config=" + ice_config
    else:
        if spath and not (args.config or args.cfile
                          or args.debug) and not args.ignore_scripts:
            command = spath
        elif sdpath and args.debug and not args.ignore_scripts:
            command = sdpath
        else:
            command = componentPath + "/" + string.lower(
                component) + " --Ice.Config=" + ice_config

    print("executing : " + command)
    os.system(command)
Exemple #8
0
def main():
    parser = argparse.ArgumentParser(description="Locate and run a robocomp component")
    group = parser.add_mutually_exclusive_group(required = True)
    cgroup = parser.add_mutually_exclusive_group()
    parser.add_argument('component', help='component name').completer = complete_components
    group.add_argument('-s', '--start', action = 'store_true' , help="start component")
    group.add_argument('-st', '--stop', action = 'store_true' , help="stop component")
    group.add_argument('-fst', '--fstop', action = 'store_true' , help=" force stop component")
    cgroup.add_argument('-d', '--debug', action = 'store_true' , help="start a component in debug mode")
    cgroup.add_argument('-cf', '--cfile', nargs = 1 , help="use custom ice config file (absolute path)")
    cgroup.add_argument('-c', '--config', nargs = 1 , help="ice config file to choose from default config directory").completer = complete_scripts
    parser.add_argument('-is','--ignore_scripts', action='store_true',help="ignore all the script files if found")
    
    argcomplete.autocomplete(parser)
    args = parser.parse_args()

    component = args.component
    
    #if stop command no need for searching and all
    if args.stop:
        if not WS.find_component_exec(component):
            args.error("couldnt find the component %s in any of the workspaces" % (args.stop[0]))
            return
        stpath = find_script("stop",component);
        if stpath and not args.ignore_scripts:
            #print("using script {0}".format(stpath))
            command = stpath
        else:
            command = "killall " + str(component)
        os.system(command)
        return
    elif args.fstop:
        if not WS.find_component_exec(component):
            parser.error("couldnt find the component %s in any of the workspaces" % (args.fstop[0]))
            return
        sfpath = find_script("forcestop",component);
        if sfpath and not args.ignore_scripts:
            #print("using script {0}".format(sfpath))
            command = sfpath
        else:
            command = "killall -9 " + str(component)
        os.system(command)
        return
    
    
    #search for the component
    componentPath = WS.find_component_exec(component)
    
    if not componentPath:
        if not WS.find_component_src(component):
            print("couldnt find the component %s in any of the workspaces" % (component))
        else:
            print("couldnt find the target please build it first using rcbuild %s " % (component))
        return

    componentPathetc = componentPath[:-4]

    #find the config file
    '''
        if only one file is present in the etc directory then it will be used
        else if it has file named config the it will be used 
        if it has file named generic_config it will be used
        else we will use a random file
        user defined config file will override all the above
    '''
    configFiles = []
    configPath = componentPathetc + '/etc'
    ice_config = ""
    for root, dirs, files in os.walk(configPath): configFiles = files
    if len(configFiles)==0:
        parser.error("couldnt find any config file in the etc directory, please specify a custom config file\n")
    else:
        if args.debug:
            for file in configFiles:
                if file.endswith('.debug'): ice_config = configPath + "/" + file    
            if len(ice_config) < 9:
                parser.error("couldnt find any debug config file in the etc directory, please specify a custom config file\n")  
        else:
            if len(configFiles)==1 :
                ice_config = configPath + "/" + configFiles[0]
            else:
                if "config" in configFiles:
                    ice_config = configPath + "/config"
                elif 'generic_config' in  configFiles:
                    ice_config = configPath + "/generic_config"
                else:
                    ice_config = configPath + "/" + configFiles[0]
    
    if args.config:
        if args.config[0] in configFiles:
            ice_config = configPath + "/" + args.config[0]
        else:
            parser.error("couldnt find config file '{0}' in the etc directory".format(args.config[0]))
    elif args.cfile:
        ice_config = args.config[0]

    #execute the command
    spath = find_script("start",component);
    sdpath = find_script("startdebug",component);
    
    if args.start:
        if spath and not (args.config or args.cfile or args.debug) and not args.ignore_scripts:
            command = spath
        elif sdpath and args.debug  and not args.ignore_scripts:
            command = sdpath
        else:
            command = componentPath + "/" + string.lower(component) + " --Ice.Config=" + ice_config
    else:
        if spath and not (args.config or args.cfile or args.debug) and not args.ignore_scripts:
            command = spath
        elif sdpath and args.debug and not args.ignore_scripts:
            command = sdpath
        else:
            command = componentPath + "/" + string.lower(component) + " --Ice.Config=" + ice_config
    
    print("executing : "+command)
    os.system(command)