<commit_before>"""Edit the given profile

Copyright (c) 2015 <NAME>
MIT Licence
"""

import os
import subprocess as sp
import sys

import dodocs.config as dconf
import dodocs.logger as dlog
from dodocs import utils


def edit(args):
    """Edit the configuration file(s)

    Parameters
    ----------
    args : namespace
        parsed command line arguments
    """
    if not utils.dodocs_directory.exists():
        log = dlog.getLogger()
        log.error("No dodocs directory found. Create it first with the command"
                  " 'dodoc profile create [profilename]'")
        return

    for profile in args.name:
        dlog.set_profile(profile)
        log = dlog.getLogger()

        log.debug("opening configuration file for profile {} for"
                  " editing".format(args.name))

        profile_dir = utils.profile_dir(profile)

        if not profile_dir.exists():
            log.warn("Profile does not exist. Bye")
            return

        config_file = str(profile_dir / dconf.CONF_FILE)

        # this part is taken without shame from the web
        if os.name == 'posix':
            if "EDITOR" in os.environ:
                sp.call([os.environ["EDITOR"], config_file])
            else:
                sp.call(["xdg-open", config_file])
        elif sys.platform.startswith('darwin'):
            sp.call(["open", config_file])
        elif os.name == 'nt':
            os.startfile(config_file)<commit_msg>Missing home dir is a critical error<commit_after>"""Edit the given profile

Copyright (c) 2015 <NAME>
MIT Licence
"""

import os
import subprocess as sp
import sys

import dodocs.config as dconf
import dodocs.logger as dlog
from dodocs import utils


def edit(args):
    """Edit the configuration file(s)

    Parameters
    ----------
    args : namespace
        parsed command line arguments
    """
    if not utils.dodocs_directory.exists():
        log = dlog.getLogger()
        log.critical("No dodocs directory found. Create it first with the"
                     " command 'dodoc profile create [profilename]'")
        return

    for profile in args.name:
        dlog.set_profile(profile)
        log = dlog.getLogger()

        log.debug("opening configuration file for profile {} for"
                  " editing".format(args.name))

        profile_dir = utils.profile_dir(profile)

        if not profile_dir.exists():
            log.warn("Profile does not exist. Bye")
            return

        config_file = str(profile_dir / dconf.CONF_FILE)

        # this part is taken without shame from the web
        if os.name == 'posix':
            if "EDITOR" in os.environ:
                sp.call([os.environ["EDITOR"], config_file])
            else:
                sp.call(["xdg-open", config_file])
        elif sys.platform.startswith('darwin'):
            sp.call(["open", config_file])
        elif os.name == 'nt':
            os.startfile(config_file)
{'fraction_non_alphanumeric': 0.10562180579216354, 'fraction_numerical': 0.00272572402044293, 'mean_word_length': 2.1167728237791934, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3478961', 'n_tokens_mistral': 852, 'n_tokens_neox': 815, 'n_words': 245}