Beispiel #1
0
def init(cm, args):
    # Fix Python 2.x.
    global input
    try:
        input = raw_input
    except NameError:
        pass

    xdg_config_home = os.environ.get('XDG_CONFIG_HOME') or \
                      os.path.join(os.path.expanduser('~'), '.config')
    config_file = os.path.join(xdg_config_home, 'fusesoc', 'fusesoc.conf')


    if os.path.exists(config_file):
        logger.warning("'{}' already exists. Aborting".format(config_file))
        exit(1)
        #TODO. Prepend cores_root to file if it doesn't exist
        f = open(config_file, 'w+')
    else:
        logger.info("Writing configuration file to '{}'".format(config_file))
        if not os.path.exists(os.path.dirname(config_file)):
            os.makedirs(os.path.dirname(config_file))
        f = open(config_file,'w+')

    config = Config(file=f)

    xdg_data_home = os.environ.get('XDG_DATA_HOME') or \
             os.path.join(os.path.expanduser('~'), '.local/share')
    library_root = os.path.join(xdg_data_home, 'fusesoc')
    _repo_paths = []
    for repo in REPOS:
        name = repo[0]
        library = {
                'sync-uri': repo[1],
                'sync-type': 'git'
                }

        default_dir = os.path.join(library_root, name)
        prompt = 'Directory to use for {} ({}) [{}] : '
        if args.y:
            location = None
        else:
            location = input(prompt.format(repo[0], repo[2], default_dir))
        if location:
            library['location'] = location
        else:
            location = default_dir
        if os.path.exists(location):
            logger.warning("'{}' already exists. This library will not be added to fusesoc.conf".format(location))
            #TODO: Prompt for overwrite
        else:
            logger.info("Initializing {}".format(name))
            try:
                config.add_library(name, library)
            except RuntimeError as e:
                logger.error("Init failed: " + str(e))
                exit(1)
    logger.info("FuseSoC is ready to use!")
Beispiel #2
0
def init(cm, args):
    warnings.warn(
        "The 'init' subcommand is deprecated and will be removed in the next "
        "release. It was intended to fetch the FuseSoC standard library. This can be done with 'fusesoc library add fusesoc_cores https://github.com/fusesoc/fusesoc-cores' instead.",
        FutureWarning,
    )
    # Fix Python 2.x.
    global input
    try:
        input = raw_input
    except NameError:
        pass

    xdg_config_home = os.environ.get("XDG_CONFIG_HOME") or os.path.join(
        os.path.expanduser("~"), ".config")
    config_file = os.path.join(xdg_config_home, "fusesoc", "fusesoc.conf")

    if os.path.exists(config_file):
        logger.warning(f"'{config_file}' already exists. Aborting")
        exit(1)
        # TODO. Prepend cores_root to file if it doesn't exist
        f = open(config_file, "w+")
    else:
        logger.info(f"Writing configuration file to '{config_file}'")
        if not os.path.exists(os.path.dirname(config_file)):
            os.makedirs(os.path.dirname(config_file))
        f = open(config_file, "w+")

    config = Config(file=f)

    _repo_paths = []
    for repo in REPOS:
        name = repo[0]
        uri = repo[1]
        default_dir = os.path.join(cm._lm.library_root, name)
        prompt = "Directory to use for {} ({}) [{}] : "
        if args.y:
            location = None
        else:
            location = input(prompt.format(repo[0], repo[2], default_dir))
        if not location:
            location = default_dir
        if os.path.exists(location):
            logger.warning(
                "'{}' already exists. This library will not be added to fusesoc.conf"
                .format(location))
            # TODO: Prompt for overwrite
        else:
            logger.info(f"Initializing {name}")
            try:
                library = Library(name, location, "git", uri, True)
                config.add_library(library)
            except RuntimeError as e:
                logger.error("Init failed: " + str(e))
                exit(1)
    logger.info("FuseSoC is ready to use!")
Beispiel #3
0
def init(cm, args):
    # Fix Python 2.x.
    global input
    try:
        input = raw_input
    except NameError:
        pass

    xdg_config_home = os.environ.get("XDG_CONFIG_HOME") or os.path.join(
        os.path.expanduser("~"), ".config"
    )
    config_file = os.path.join(xdg_config_home, "fusesoc", "fusesoc.conf")

    if os.path.exists(config_file):
        logger.warning("'{}' already exists. Aborting".format(config_file))
        exit(1)
        # TODO. Prepend cores_root to file if it doesn't exist
        f = open(config_file, "w+")
    else:
        logger.info("Writing configuration file to '{}'".format(config_file))
        if not os.path.exists(os.path.dirname(config_file)):
            os.makedirs(os.path.dirname(config_file))
        f = open(config_file, "w+")

    config = Config(file=f)

    _repo_paths = []
    for repo in REPOS:
        name = repo[0]
        uri = repo[1]
        default_dir = os.path.join(cm._lm.library_root, name)
        prompt = "Directory to use for {} ({}) [{}] : "
        if args.y:
            location = None
        else:
            location = input(prompt.format(repo[0], repo[2], default_dir))
        if not location:
            location = default_dir
        if os.path.exists(location):
            logger.warning(
                "'{}' already exists. This library will not be added to fusesoc.conf".format(
                    location
                )
            )
            # TODO: Prompt for overwrite
        else:
            logger.info("Initializing {}".format(name))
            try:
                library = Library(name, location, "git", uri, True)
                config.add_library(library)
            except RuntimeError as e:
                logger.error("Init failed: " + str(e))
                exit(1)
    logger.info("FuseSoC is ready to use!")
Beispiel #4
0
def add_library(cm, args):
    sync_uri = vars(args)["sync-uri"]

    if args.location:
        location = args.location
    elif vars(args).get("global", False):
        location = os.path.join(cm._lm.library_root, args.name)
    else:
        location = os.path.join("fusesoc_libraries", args.name)

    if "sync-type" in vars(args):
        sync_type = vars(args)["sync-type"]
    else:
        sync_type = None

    # Check if it's a dir. Otherwise fall back to git repo
    if not sync_type:
        if os.path.isdir(sync_uri):
            sync_type = "local"
        else:
            sync_type = "git"

    if sync_type == "local":
        logger.info(
            "Interpreting sync-uri '{}' as location for local provider.".format(
                sync_uri
            )
        )
        location = os.path.abspath(sync_uri)

    auto_sync = not args.no_auto_sync
    library = Library(args.name, location, sync_type, sync_uri, auto_sync)

    if args.config:
        config = Config(file=args.config)
    elif vars(args)["global"]:
        xdg_config_home = os.environ.get("XDG_CONFIG_HOME") or os.path.join(
            os.path.expanduser("~"), ".config"
        )
        config_file = os.path.join(xdg_config_home, "fusesoc", "fusesoc.conf")
        config = Config(path=config_file)
    else:
        config = Config(path="fusesoc.conf")

    try:
        config.add_library(library)
    except RuntimeError as e:
        logger.error("`add library` failed: " + str(e))
        exit(1)
Beispiel #5
0
def add_library(cm, args):
    library = {}
    name = args.name
    sync_uri = vars(args)['sync-uri']
    if 'sync-type' in vars(args):
        provider = vars(args)['sync-type']
        library['sync-type'] = provider
    elif os.path.isdir(sync_uri):
        provider = 'local'
        library['sync-type'] = provider
    else:
        provider = 'git'

    if provider == 'local' and not args.location:
        logger.info(
            "Interpreting sync-uri '{}' as location for local provider.".
            format(sync_uri))
        library['location'] = os.path.abspath(sync_uri)
        library['sync-type'] = 'local'
    elif provider == 'local' and os.path.abspath(
            args.location) != os.path.abspath(sync_uri):
        logger.error(
            "Location '{}' does not match sync-uri '{}' for local provider. Consider specifying only sync-uri."
            .format(args.location, sync_uri))
        exit(1)
    else:
        library['sync-uri'] = sync_uri
        #Only remote git libraries supported for now
        library['sync-type'] = 'git'
        if args.location:
            library['location'] = os.path.abspath(args.location)
    if args.no_auto_sync:
        library['auto-sync'] = False

    if args.config:
        config = Config(file=args.config)
    elif vars(args)['global']:
        xdg_config_home = os.environ.get('XDG_CONFIG_HOME') or \
                          os.path.join(os.path.expanduser('~'), '.config')
        config_file = os.path.join(xdg_config_home, 'fusesoc', 'fusesoc.conf')
        config = Config(path=config_file)
    else:
        config = Config(path="fusesoc.conf")

    try:
        config.add_library(name, library)
    except RuntimeError as e:
        logger.error("`add library` failed: " + str(e))
        exit(1)
Beispiel #6
0
def add_library(cm, args):
    library = {}
    name = args.name
    library['sync-uri'] = vars(args)['sync-uri']
    if args.location:
        library['location'] = args.location
    if args.no_auto_sync:
        library['auto-sync'] = False

    if args.config:
        config = Config(file=args.config)
    else:
        config = Config()

    config.add_library(name, library)
Beispiel #7
0
def add_library(cm, args):
    sync_uri = vars(args)['sync-uri']

    if args.location:
        location = args.location
    elif vars(args).get('global', False):
        location = os.path.join(cm._lm.library_root, args.name)
    else:
        location = os.path.join('fusesoc_libraries', args.name)

    if 'sync-type' in vars(args):
        sync_type = vars(args)['sync-type']
    else:
        sync_type = None

    #Check if it's a dir. Otherwise fall back to git repo
    if not sync_type:
        if os.path.isdir(sync_uri):
            sync_type = 'local'
        else:
            sync_type = 'git'

    if sync_type == 'local':
        logger.info(
            "Interpreting sync-uri '{}' as location for local provider.".
            format(sync_uri))
        location = os.path.abspath(sync_uri)

    auto_sync = not args.no_auto_sync
    library = Library(args.name, location, sync_type, sync_uri, auto_sync)

    if args.config:
        config = Config(file=args.config)
    elif vars(args)['global']:
        xdg_config_home = os.environ.get('XDG_CONFIG_HOME') or \
                          os.path.join(os.path.expanduser('~'), '.config')
        config_file = os.path.join(xdg_config_home, 'fusesoc', 'fusesoc.conf')
        config = Config(path=config_file)
    else:
        config = Config(path="fusesoc.conf")

    try:
        config.add_library(library)
    except RuntimeError as e:
        logger.error("`add library` failed: " + str(e))
        exit(1)