<commit_before>#! /usr/bin/env python

"""
#----------------------------------------------------------------
Author: <NAME> <jasonDOTgorsATgmail>
Creation Date: 07-30-2013
Purpose: this does the actual managing of the packages. 
#----------------------------------------------------------------
"""

import argparse
import os
from os.path import join
import sys 
import imp
import Bep.core.usage as usage 
from Bep.core.release_info import __version__, name
import package
import utils


def create_pkg_inst(lang_arg, pkg_type, install_dirs, packages_file=None):
    ''' install_dirs is a dict with the installed_pkgs_dir and the install_logs_dir '''

    # for future pkg_types, just add them to this dict
    supported_pkg_types = dict(github=package.Github, bitbucket=package.Bitbucket,
                               gitorious=package.Gitorious, local_repo=package.Local_Repo)

    def make_inst(pkg_type_cls):
        return pkg_type_cls(lang_arg, pkg_type, install_dirs)
    
    try:
        return make_inst(supported_pkg_types[pkg_type])
    except KeyError:
        if packages_file:  # installs from the pkgs file are the only thing that get this argument 
            not_pkg_type = '\nError: {0} in your {1} is an unrecognized package type.\n'.format(pkg_type, packages_file)
            raise SystemExit(not_pkg_type)
        else:
            not_pkg_type = '\nError: {0} is an unrecognized package type.\n'.format(pkg_type)
            raise SystemExit(not_pkg_type)



usr_home_dir = os.path.expanduser('~')  # specifies the user's home dir  

#top_level_dir = join(options['top_level_dir'], '.{}'.format(name))
top_level_dir = join(usr_home_dir, '.{}'.format(name))

installed_pkgs_dir = join(top_level_dir, 'installed_pkgs') 
install_logs_dir = join(top_level_dir, '.install_logs') 
install_dirs = dict(installed_pkgs_dir=installed_pkgs_dir, install_logs_dir=install_logs_dir)

#installation_db = 'installation_db.json'
#installation_db_path = join(top_level_dir, installation_db)

packages_file = '.{}_packages'.format(name)
packages_file_path = join(usr_home_dir, packages_file)



def main(): # needs to be done as a main func for setuptools to work correctly in creating an executable
    
    parser = argparse.ArgumentParser(description=name.upper(),
                            formatter_class=argparse.RawDescriptionHelpFormatter, 
                            #formatter_class=argparse.RawTextHelpFormatter, 
                            epilog=usage.epilog_use)

    parser.add_argument('--version', action='version', version='%(prog)s {0}'.format(__version__))
    parser.add_argument('-l', '--language', nargs='?', default='python', help=usage.lang_use)


    group = parser.add_mutually_exclusive_group()
    group.add_argument("-v", "--verbose", action="store_true", help=usage.verbose_use)
    group.add_argument("-q", "--quiet", action="store_true", help=usage.quiet_use)


    subparsers = parser.add_subparsers(title='Commands', 
                                       description='[ These are the commands that can be passed to %(prog)s ]',
                                       #help=usage.subparser_use)
                                       help='[ Command specific help info ]')


    ### create parser for the "list" command
    # maybe make is so that it can list all branches installed for a specific pkg,
    parser_list = subparsers.add_parser('list', help=usage.list_use)
    parser_list.add_argument('list_arg', action="store_true", help=usage.list_sub_use) #metavar="arg") 

    # nargs options:
    # (default): by not specifying nargs at all, you just get a string of 1 item
    # = N   where N is some specified number of args
    # = '?' makes a string of one item, and if no args are given, then default is used.
    # = '*' makes a list of all args passed after command and if no args given, then default is used.
    # = '+' makes list of all args passed after command, but requires at least one arg



    ### install command
    parser_install = subparsers.add_parser('install', help=usage.install_use.format(packages_file),
                                            formatter_class=argparse.RawTextHelpFormatter)
    parser_install.add_argument('install_arg', help=usage.install_sub_use.format(packages_file)) #metavar="arg")

    
    # NOTE this seems like a better way to go in the future:
    # parser_install.set_defaults(func=run_install)
    # then run_install would be defined to run the install process (rather than having the conditionals below)
    # def run_install(args):
    #   install_arg = args.install_arg  # would be a list of pkgs or a string of the packages file
    #   ...process the install_arg to decide what to install
    #   ...then do the install 




    ### remove command
    parser_remove = subparsers.add_parser('remove', help=usage.remove_use, 
                                            formatter_class=argparse.RawTextHelpFormatter)
    parser_remove.add_argument('remove_arg', help=usage.remove_sub_use.format(name=name))

    ### update command
    parser_update = subparsers.add_parser('update', help=usage.update_use,
                                            formatter_class=argparse.RawTextHelpFormatter)
    parser_update.add_argument('update_arg', help=usage.update_sub_use.format(name=name))
    

    ### turn_off command
    parser_turn_off = subparsers.add_parser('turn_off', help=usage.turn_off_use, 
                                            formatter_class=argparse.RawTextHelpFormatter)
    parser_turn_off.add_argument('turn_off_arg', help=usage.turn_off_sub_use.format(name=name))


    ### turn_on command
    parser_turn_on = subparsers.add_parser('turn_on', help=usage.turn_on_use, 
                                            formatter_class=argparse.RawTextHelpFormatter)
    parser_turn_on.add_argument('turn_on_arg', help=usage.turn_on_sub_use)#, metavar='arg')


    args = parser.parse_args()

    ##########################################################
    ###########  this section handles cmds passed  ###########

    #def parse_command_args(cmd, cmdline_arg):
        #pkg_type_with_pkg_to_process = []   # this will be a list of tuples 
        #for pkg_type_and_pkg_to_process in cmdline_arg:
            #pkg_type_andor_pkg_to_process = pkg_type_and_pkg_to_process.split('=') 
            #if len(pkg_type_andor_pkg_to_process) != 2:
                #print("\nError: with argument {}.".format(pkg_type_andor_pkg_to_process[0]))
                #print("{} argument needs to be specified like so:".format(cmd))
                #print("\t`pkg_type=repo_type+pkg_name[^branch_name]`")
                #print("\t(eg. `{0} {1} github=git+ipython/ipython[^optional_branch]`)\n".format(name, cmd))
                #continue
                #raise SystemExit
            #pkg_type, pkg_to_process = pkg_type_andor_pkg_to_process
            #pkg_type_with_pkg_to_process.append((pkg_type, pkg_to_process))
        #return pkg_type_with_pkg_to_process #[(pkg_type, pkg_to_process1), (pkg_type, pkg_to_process2), ...] 


    class noise(object):
        verbose = args.verbose
        quiet = args.quiet


    def ALL_error(cmd_arg):
        if cmd_arg in ['all', 'All']:
            raise SystemExit("\nError: Did you mean to specifiy ALL instead?")


    lang_arg = args.language

    if 'install_arg' in args:
        install_arg = args.install_arg 


    elif 'update_arg' in args:
        update_arg = args.update_arg 
        ALL_error(update_arg)


    elif 'remove_arg' in args:
        remove_arg = args.remove_arg
        ALL_error(remove_arg)


    elif 'turn_off_arg' in args:
        turn_off_arg = args.turn_off_arg
        ALL_error(turn_off_arg)


    elif 'turn_on_arg' in args:
        turn_on_arg = args.turn_on_arg
        ALL_error(turn_on_arg)

    ##########################################################
    ##########################################################



    #--------------------------------------------------------------------------------------------------------------
    # where stuff actually happens
    if noise.quiet:
        print('-'*60)

    everything_already_installed = utils.all_pkgs_and_branches_for_all_pkg_types_already_installed(installed_pkgs_dir)
    #print('\neverything_already_installed:') 
    #print(everything_already_installed) 


    command_and_items_to_process_when_multiple_items = {}   # but not for install command 



    # install pkg(s) 
    if 'install_arg' in args:

        # install from packages file
        if install_arg == "packages_file":
            try:  # bring in the packages file
                sys.dont_write_bytecode = True  # to avoid writing a .pyc files (for the packages file)
                pkgs_module = imp.load_source(packages_file, packages_file_path)    # used to import a hidden file (really hackey) 
            except (ImportError, IOError):
                print("No {0} file installed for use.".format(packages_file))
                if not os.path.isfile(packages_file_path):  # create packages file if one doesn't already exist.
                    #shutil.copy(join('data', packages_file), packages_file_path)    # create a template packages file
                    #print("So created template {0} file for installation of packages.".format(packages_file))

                    open(packages_file_path, 'a').close()  # creates an empty packages file
                    print("So created empty {0} file for installation of packages.".format(packages_file))

                raise SystemExit("Now add the desired packages to the {} file and re-run install.".format(packages_file))


            for pkg_type, pkgs_from_pkgs_file in pkgs_module.packages.items():
                utils.when_not_quiet_mode(utils.status('\t\tInstalling {0} packages'.format(pkg_type)), noise.quiet)

                if pkgs_from_pkgs_file:

                    for pkg_to_install in pkgs_from_pkgs_file: 

                        lang_and_pkg_to_install = pkg_to_install.split('-->')  # to see if a language is given 
                        if len(lang_and_pkg_to_install) == 2:
                            lang_arg, pkg_to_install = lang_and_pkg_to_install
                            pkg_inst = create_pkg_inst(lang_arg, pkg_type, install_dirs, packages_file)
                        elif len(lang_and_pkg_to_install) != 2:
                            print("\nError: need to specifiy a language in {0} for:".format(packages_file)) 
                            print("\t{}".format(pkg_to_install))
                            raise SystemExit

                        # important to see what has previously been installed, so as to not turn on a 2nd version of a package.
                        everything_already_installed = utils.all_pkgs_and_branches_for_all_pkg_types_already_installed(installed_pkgs_dir) 
                        pkg_inst.install(pkg_to_install, noise, everything_already_installed=everything_already_installed)
                else:
                    utils.when_not_quiet_mode('\nNo {0} packages specified in {1} to install.'.format(pkg_type, packages_file), noise.quiet)

        # install w/ command line arg(s)
        elif install_arg != "packages_file":

            pkg_type_and_pkg_to_process = install_arg
            pkg_type_andor_pkg_to_process = pkg_type_and_pkg_to_process.split('=') # need this check b/c pkg_type has to be specified when using cmdline 
            if len(pkg_type_andor_pkg_to_process) != 2:
                utils.how_to_specify_installation(pkg_type_andor_pkg_to_process[0])
                raise SystemExit

            pkg_type, pkg_to_install = pkg_type_andor_pkg_to_process
            pkg_to_install_specified_with_user_and_repo = pkg_to_install.split('/')
            if len(pkg_to_install_specified_with_user_and_repo) == 1:
                print("\nError: need to specifiy a user and branch for {}, like:".format(pkg_to_install))
                print("\t{} install github=username/pkg_name[^optional_branch]".format(name))   
                print("\t{} install bitbucket=hg+username/pkg_name[^optional_branch]".format(name))   
                raise SystemExit

            utils.when_not_quiet_mode(utils.status('\t\tInstalling {0} package'.format(pkg_type)), noise.quiet)
            pkg_inst = create_pkg_inst(lang_arg, pkg_type, install_dirs)

            # important to keep this here so it can be known what has previously been installed, so as to not turn on a 2nd version of a package.
            everything_already_installed = utils.all_pkgs_and_branches_for_all_pkg_types_already_installed(installed_pkgs_dir) 
            pkg_inst.install(pkg_to_install, noise, everything_already_installed=everything_already_installed)

    


    # list installed pkg(s) (by each package type)
    elif 'list_arg' in args:
        if everything_already_installed:

            count_of_listed = 0
            for lang_dir_name, pkg_type_dict in everything_already_installed.items():

                if not lang_arg:  # if a language arg is not given, then list all installed packages
                    utils.when_not_quiet_mode("\n{0} packages installed:".format(lang_dir_name), noise.quiet)

                for pkg_type, pkgs_and_branches in pkg_type_dict.items():

                    #if not lang_arg:  # if a language arg is given, then remove all pkgs for that lang's version
                        #when_not_quiet_mode("\t{0}:".format(pkg_type), noise.quiet)

                    if len(pkgs_and_branches) >= 1:

                        def list_packages(count_of_listed=count_of_listed):
                            for pkg_for_listing, branches in pkgs_and_branches.items(): 
                                for branch in branches:
                                    if branch.startswith('.__'):
                                        branch_if_were_on = branch.lstrip('.__')
                                        branch_if_were_on = '[{0}]'.format(branch_if_were_on)
                                        item_installed = '  {: >20} {: >25} {: >25} {: >10}'.format(pkg_for_listing, branch_if_were_on, pkg_type, "** off")

                                    elif not branch.startswith('.__'):                    
                                        branch = '[{0}]'.format(branch)
                                        item_installed = '  {: >20} {: >25} {: >25}'.format(pkg_for_listing, branch, pkg_type)
                                    count_of_listed += 1
                                    print(item_installed)
                            return count_of_listed

                        if lang_arg:  # if a language arg is given, then list pkgs for only that lang
                            pkg_inst = create_pkg_inst(lang_arg, pkg_type, install_dirs)
                            lang_cmd = pkg_inst.lang_cmd  # makes it so that the system default of a lang maps back on to it's particular version

                            if lang_dir_name == lang_cmd:
                                count_of_listed = list_packages()
                        else:
                            count_of_listed = list_packages()

            if count_of_listed == 0: 
                utils.when_not_quiet_mode('\n[ No packages for listing ]'.format(pkg_type), noise.quiet) <commit_msg>changed list; now it only displays everything.<commit_after>#! /usr/bin/env python

"""
#----------------------------------------------------------------
Author: <NAME> <<EMAIL>>
Creation Date: 07-30-2013
Purpose: this does the actual managing of the packages. 
#----------------------------------------------------------------
"""

import argparse
import os
from os.path import join
import sys 
import imp
import Bep.core.usage as usage 
from Bep.core.release_info import __version__, name
import package
import utils


def create_pkg_inst(lang_arg, pkg_type, install_dirs, packages_file=None):
    ''' install_dirs is a dict with the installed_pkgs_dir and the install_logs_dir '''

    # for future pkg_types, just add them to this dict
    supported_pkg_types = dict(github=package.Github, bitbucket=package.Bitbucket,
                               gitorious=package.Gitorious, local_repo=package.Local_Repo)

    def make_inst(pkg_type_cls):
        return pkg_type_cls(lang_arg, pkg_type, install_dirs)
    
    try:
        return make_inst(supported_pkg_types[pkg_type])
    except KeyError:
        if packages_file:  # installs from the pkgs file are the only thing that get this argument 
            not_pkg_type = '\nError: {0} in your {1} is an unrecognized package type.\n'.format(pkg_type, packages_file)
            raise SystemExit(not_pkg_type)
        else:
            not_pkg_type = '\nError: {0} is an unrecognized package type.\n'.format(pkg_type)
            raise SystemExit(not_pkg_type)



usr_home_dir = os.path.expanduser('~')  # specifies the user's home dir  

#top_level_dir = join(options['top_level_dir'], '.{}'.format(name))
top_level_dir = join(usr_home_dir, '.{}'.format(name))

installed_pkgs_dir = join(top_level_dir, 'installed_pkgs') 
install_logs_dir = join(top_level_dir, '.install_logs') 
install_dirs = dict(installed_pkgs_dir=installed_pkgs_dir, install_logs_dir=install_logs_dir)

#installation_db = 'installation_db.json'
#installation_db_path = join(top_level_dir, installation_db)

packages_file = '.{}_packages'.format(name)
packages_file_path = join(usr_home_dir, packages_file)



def main(): # needs to be done as a main func for setuptools to work correctly in creating an executable
    
    parser = argparse.ArgumentParser(description=name.upper(),
                            formatter_class=argparse.RawDescriptionHelpFormatter, 
                            #formatter_class=argparse.RawTextHelpFormatter, 
                            epilog=usage.epilog_use)

    parser.add_argument('--version', action='version', version='%(prog)s {0}'.format(__version__))
    parser.add_argument('-l', '--language', nargs='?', default='python', help=usage.lang_use)


    group = parser.add_mutually_exclusive_group()
    group.add_argument("-v", "--verbose", action="store_true", help=usage.verbose_use)
    group.add_argument("-q", "--quiet", action="store_true", help=usage.quiet_use)


    subparsers = parser.add_subparsers(title='Commands', 
                                       description='[ These are the commands that can be passed to %(prog)s ]',
                                       #help=usage.subparser_use)
                                       help='[ Command specific help info ]')


    ### create parser for the "list" command
    # maybe make is so that it can list all branches installed for a specific pkg,
    parser_list = subparsers.add_parser('list', help=usage.list_use)
    parser_list.add_argument('list_arg', action="store_true", help=usage.list_sub_use) #metavar="arg") 

    # nargs options:
    # (default): by not specifying nargs at all, you just get a string of 1 item
    # = N   where N is some specified number of args
    # = '?' makes a string of one item, and if no args are given, then default is used.
    # = '*' makes a list of all args passed after command and if no args given, then default is used.
    # = '+' makes list of all args passed after command, but requires at least one arg



    ### install command
    parser_install = subparsers.add_parser('install', help=usage.install_use.format(packages_file),
                                            formatter_class=argparse.RawTextHelpFormatter)
    parser_install.add_argument('install_arg', help=usage.install_sub_use.format(packages_file)) #metavar="arg")

    
    # NOTE this seems like a better way to go in the future:
    # parser_install.set_defaults(func=run_install)
    # then run_install would be defined to run the install process (rather than having the conditionals below)
    # def run_install(args):
    #   install_arg = args.install_arg  # would be a list of pkgs or a string of the packages file
    #   ...process the install_arg to decide what to install
    #   ...then do the install 




    ### remove command
    parser_remove = subparsers.add_parser('remove', help=usage.remove_use, 
                                            formatter_class=argparse.RawTextHelpFormatter)
    parser_remove.add_argument('remove_arg', help=usage.remove_sub_use.format(name=name))

    ### update command
    parser_update = subparsers.add_parser('update', help=usage.update_use,
                                            formatter_class=argparse.RawTextHelpFormatter)
    parser_update.add_argument('update_arg', help=usage.update_sub_use.format(name=name))
    

    ### turn_off command
    parser_turn_off = subparsers.add_parser('turn_off', help=usage.turn_off_use, 
                                            formatter_class=argparse.RawTextHelpFormatter)
    parser_turn_off.add_argument('turn_off_arg', help=usage.turn_off_sub_use.format(name=name))


    ### turn_on command
    parser_turn_on = subparsers.add_parser('turn_on', help=usage.turn_on_use, 
                                            formatter_class=argparse.RawTextHelpFormatter)
    parser_turn_on.add_argument('turn_on_arg', help=usage.turn_on_sub_use)#, metavar='arg')


    args = parser.parse_args()

    ##########################################################
    ###########  this section handles cmds passed  ###########

    #def parse_command_args(cmd, cmdline_arg):
        #pkg_type_with_pkg_to_process = []   # this will be a list of tuples 
        #for pkg_type_and_pkg_to_process in cmdline_arg:
            #pkg_type_andor_pkg_to_process = pkg_type_and_pkg_to_process.split('=') 
            #if len(pkg_type_andor_pkg_to_process) != 2:
                #print("\nError: with argument {}.".format(pkg_type_andor_pkg_to_process[0]))
                #print("{} argument needs to be specified like so:".format(cmd))
                #print("\t`pkg_type=repo_type+pkg_name[^branch_name]`")
                #print("\t(eg. `{0} {1} github=git+ipython/ipython[^optional_branch]`)\n".format(name, cmd))
                #continue
                #raise SystemExit
            #pkg_type, pkg_to_process = pkg_type_andor_pkg_to_process
            #pkg_type_with_pkg_to_process.append((pkg_type, pkg_to_process))
        #return pkg_type_with_pkg_to_process #[(pkg_type, pkg_to_process1), (pkg_type, pkg_to_process2), ...] 


    class noise(object):
        verbose = args.verbose
        quiet = args.quiet


    def ALL_error(cmd_arg):
        if cmd_arg in ['all', 'All']:
            raise SystemExit("\nError: Did you mean to specifiy ALL instead?")


    lang_arg = args.language

    if 'install_arg' in args:
        install_arg = args.install_arg 


    elif 'update_arg' in args:
        update_arg = args.update_arg 
        ALL_error(update_arg)


    elif 'remove_arg' in args:
        remove_arg = args.remove_arg
        ALL_error(remove_arg)


    elif 'turn_off_arg' in args:
        turn_off_arg = args.turn_off_arg
        ALL_error(turn_off_arg)


    elif 'turn_on_arg' in args:
        turn_on_arg = args.turn_on_arg
        ALL_error(turn_on_arg)

    ##########################################################
    ##########################################################



    #--------------------------------------------------------------------------------------------------------------
    # where stuff actually happens
    if noise.quiet:
        print('-'*60)

    everything_already_installed = utils.all_pkgs_and_branches_for_all_pkg_types_already_installed(installed_pkgs_dir)
    #print('\neverything_already_installed:') 
    #print(everything_already_installed) 


    command_and_items_to_process_when_multiple_items = {}   # but not for install command 



    # install pkg(s) 
    if 'install_arg' in args:

        # install from packages file
        if install_arg == "packages_file":
            try:  # bring in the packages file
                sys.dont_write_bytecode = True  # to avoid writing a .pyc files (for the packages file)
                pkgs_module = imp.load_source(packages_file, packages_file_path)    # used to import a hidden file (really hackey) 
            except (ImportError, IOError):
                print("No {0} file installed for use.".format(packages_file))
                if not os.path.isfile(packages_file_path):  # create packages file if one doesn't already exist.
                    #shutil.copy(join('data', packages_file), packages_file_path)    # create a template packages file
                    #print("So created template {0} file for installation of packages.".format(packages_file))

                    open(packages_file_path, 'a').close()  # creates an empty packages file
                    print("So created empty {0} file for installation of packages.".format(packages_file))

                raise SystemExit("Now add the desired packages to the {} file and re-run install.".format(packages_file))


            for pkg_type, pkgs_from_pkgs_file in pkgs_module.packages.items():
                utils.when_not_quiet_mode(utils.status('\t\tInstalling {0} packages'.format(pkg_type)), noise.quiet)

                if pkgs_from_pkgs_file:

                    for pkg_to_install in pkgs_from_pkgs_file: 

                        lang_and_pkg_to_install = pkg_to_install.split('-->')  # to see if a language is given 
                        if len(lang_and_pkg_to_install) == 2:
                            lang_arg, pkg_to_install = lang_and_pkg_to_install
                            pkg_inst = create_pkg_inst(lang_arg, pkg_type, install_dirs, packages_file)
                        elif len(lang_and_pkg_to_install) != 2:
                            print("\nError: need to specifiy a language in {0} for:".format(packages_file)) 
                            print("\t{}".format(pkg_to_install))
                            raise SystemExit

                        # important to see what has previously been installed, so as to not turn on a 2nd version of a package.
                        everything_already_installed = utils.all_pkgs_and_branches_for_all_pkg_types_already_installed(installed_pkgs_dir) 
                        pkg_inst.install(pkg_to_install, noise, everything_already_installed=everything_already_installed)
                else:
                    utils.when_not_quiet_mode('\nNo {0} packages specified in {1} to install.'.format(pkg_type, packages_file), noise.quiet)

        # install w/ command line arg(s)
        elif install_arg != "packages_file":

            pkg_type_and_pkg_to_process = install_arg
            pkg_type_andor_pkg_to_process = pkg_type_and_pkg_to_process.split('=') # need this check b/c pkg_type has to be specified when using cmdline 
            if len(pkg_type_andor_pkg_to_process) != 2:
                utils.how_to_specify_installation(pkg_type_andor_pkg_to_process[0])
                raise SystemExit

            pkg_type, pkg_to_install = pkg_type_andor_pkg_to_process
            pkg_to_install_specified_with_user_and_repo = pkg_to_install.split('/')
            if len(pkg_to_install_specified_with_user_and_repo) == 1:
                print("\nError: need to specifiy a user and branch for {}, like:".format(pkg_to_install))
                print("\t{} install github=username/pkg_name[^optional_branch]".format(name))   
                print("\t{} install bitbucket=hg+username/pkg_name[^optional_branch]".format(name))   
                raise SystemExit

            utils.when_not_quiet_mode(utils.status('\t\tInstalling {0} package'.format(pkg_type)), noise.quiet)
            pkg_inst = create_pkg_inst(lang_arg, pkg_type, install_dirs)

            # important to keep this here so it can be known what has previously been installed, so as to not turn on a 2nd version of a package.
            everything_already_installed = utils.all_pkgs_and_branches_for_all_pkg_types_already_installed(installed_pkgs_dir) 
            pkg_inst.install(pkg_to_install, noise, everything_already_installed=everything_already_installed)

    


    # list installed pkg(s) (by each package type)
    elif 'list_arg' in args:
        if everything_already_installed:

            count_of_listed = 0
            for lang_dir_name, pkg_type_dict in everything_already_installed.items():

                utils.when_not_quiet_mode("\n{0} packages installed:".format(lang_dir_name), noise.quiet)

                for pkg_type, pkgs_and_branches in pkg_type_dict.items():

                    if pkgs_and_branches:

                        def list_packages(count_of_listed=count_of_listed):
                            for pkg_for_listing, branches in pkgs_and_branches.items(): 
                                for branch in branches:
                                    if branch.startswith('.__'):
                                        branch_if_were_on = branch.lstrip('.__')
                                        branch_if_were_on = '[{0}]'.format(branch_if_were_on)
                                        item_installed = '  {: >20} {: >25} {: >25} {: >10}'.format(pkg_for_listing, branch_if_were_on, pkg_type, "** off")

                                    elif not branch.startswith('.__'):                    
                                        branch = '[{0}]'.format(branch)
                                        item_installed = '  {: >20} {: >25} {: >25}'.format(pkg_for_listing, branch, pkg_type)
                                    count_of_listed += 1
                                    print(item_installed)
                            return count_of_listed

                        count_of_listed = list_packages()

            if count_of_listed == 0: 
                utils.when_not_quiet_mode('\n[ No packages for listing ]'.format(pkg_type), noise.quiet) 
{'fraction_non_alphanumeric': 0.11484809871906645, 'fraction_numerical': 0.003822681242036081, 'mean_word_length': 2.3782283642954236, 'pattern_counts': {'":': 4, '<': 8, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 48, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2293271', 'n_tokens_mistral': 8874, 'n_tokens_neox': 8242, 'n_words': 1937}