Ejemplo n.º 1
0
def load_profile(name):
    """
    Load a profile by name.

    Joins the dfm state directory with 'profiles' and name to
    determine where the profile is.
    """
    path = os.path.join(dfm_dir(), 'profiles', name)
    return Profile(path)
Ejemplo n.º 2
0
def load_profile(name):
    """
    Load a profile by name.

    Joins the dfm state directory with 'profiles' and name to
    determine where the profile is.
    """
    path = os.path.join(dfm_dir(), 'profiles', name)
    return Profile(path)
Ejemplo n.º 3
0
def run(args):
    """Run the remove subcommand."""
    profile_p = os.path.join(dfm_dir(), 'profiles', args['<profile>'])
    if not os.path.isdir(profile_p):
        print('no profile with that name exists')
        sys.exit(1)

    ans = input('Remove {}? [Y/n]:'.format(profile_p))
    if ans.lower().startswith('n'):
        return

    shutil.rmtree(profile_p)
Ejemplo n.º 4
0
def run(args):
    """Run the clone command."""
    name = args.get('--name', get_name(args['<url>']))
    path = os.path.join(dfm_dir(), 'profiles', name)
    subprocess.call(['git', 'clone', args['<url>'], path])
    if args['--link']:
        args = {
            '<profile>': name,
            '--overwrite': args['--overwrite'],
            '--dry-run': False,
        }

        run_link(args)
Ejemplo n.º 5
0
def current_profile():
    """
    Load the current profile as indicated in the state file.

    Exits with a helpfule error message if state file is not found or
    current_profile is not set.
    """
    try:
        with open(state_file_p()) as state_file:
            state = json.load(state_file)
    except FileNotFoundError:
        state = {}

    profile_name = state.get('current_profile')
    if not profile_name:
        print('no profile active, run dfm link to make one active')
        sys.exit(1)

    return os.path.join(dfm_dir(), 'profiles', profile_name)
Ejemplo n.º 6
0
def current_profile():
    """
    Load the current profile as indicated in the state file.

    Exits with a helpfule error message if state file is not found or
    current_profile is not set.
    """
    try:
        with open(state_file_p()) as state_file:
            state = json.load(state_file)
    except FileNotFoundError:
        state = {}

    profile_name = state.get('current_profile')
    if not profile_name:
        print('no profile active, run dfm link to make one active')
        sys.exit(1)

    return os.path.join(dfm_dir(), 'profiles', profile_name)
Ejemplo n.º 7
0
def run(_args):
    """List all available profiles on this system."""
    for profile in os.listdir(os.path.join(dfm_dir(), 'profiles')):
        if not profile.startswith('.'):
            print(profile)
Ejemplo n.º 8
0
def state_file_p():
    """Return the path to the dfm state file."""
    return os.path.join(dfm_dir(), 'state.json')
Ejemplo n.º 9
0
def state_file_p():
    """Return the path to the dfm state file."""
    return os.path.join(dfm_dir(), 'state.json')