<commit_before>#
# Copyright (c) 2008 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.rpath.com/permanent/licenses/CPL-1.0.
#
# This program is distributed in the hope that it will be useful, but
# without any warranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#
"""
status command and related utilities.
"""
import os

from rbuild import errors
from rbuild import pluginapi
from rbuild.pluginapi import command

class StatusCommand(command.BaseCommand):
    """
    Prints status relative to the repository
    """

    commands = ['status']

    def runCommand(self, handle, _, args):
        if len(args) == 2:
            directory = handle.Product.getDefaultProductDirectory()
            if directory is None:
                raise errors.RbuildError('Could not find product from'
                                         ' current directory')
            directories = [directory]
        else:
            directories = args[2:]

        for directory in directories:
            handle.Status.printDirectoryStatus(directory)


class Status(pluginapi.Plugin):
    name = 'status'

    def registerCommands(self):
        self.handle.Commands.registerCommand(StatusCommand)

    def printDirectoryStatus(self, dirName):
        '''
        Prints status of all source checkouts under a certain directory.
        @param dirName: Full path name of the directory to print
        '''
        dirName = os.path.abspath(dirName)
        productDir = self.handle.Product.getDefaultProductDirectory(dirName)
        if not productDir:
            raise errors.RbuildError('could not find product for directory %s',
                dirName)
        product = self.handle.Product.getProductStoreFromDirectory(productDir)
        self.printProductStatus(product)
        self._printOneDirectoryStatus(dirName)
        for dirpath, dirnames, _ in os.walk(dirName):
            for oneDir in dirnames:
                if oneDir == '.rbuild':
                    continue
                self._printOneDirectoryStatus(os.path.join(dirpath, oneDir))

    def _printOneDirectoryStatus(self, dirName):
        '''
        Prints directory status, if any, for a directory that is a
        checkout or stage.  For a directory that is neither a checkout
        not a stage, do nothing.
        @param dirName: Name of directory
        '''<commit_msg>sort status output so that it is stable<commit_after>#
# Copyright (c) 2008 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.rpath.com/permanent/licenses/CPL-1.0.
#
# This program is distributed in the hope that it will be useful, but
# without any warranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#
"""
status command and related utilities.
"""
import os

from rbuild import errors
from rbuild import pluginapi
from rbuild.pluginapi import command

class StatusCommand(command.BaseCommand):
    """
    Prints status relative to the repository
    """

    commands = ['status']

    def runCommand(self, handle, _, args):
        if len(args) == 2:
            directory = handle.Product.getDefaultProductDirectory()
            if directory is None:
                raise errors.RbuildError('Could not find product from'
                                         ' current directory')
            directories = [directory]
        else:
            directories = args[2:]

        for directory in directories:
            handle.Status.printDirectoryStatus(directory)


class Status(pluginapi.Plugin):
    name = 'status'

    def registerCommands(self):
        self.handle.Commands.registerCommand(StatusCommand)

    def printDirectoryStatus(self, dirName):
        '''
        Prints status of all source checkouts under a certain directory.
        @param dirName: Full path name of the directory to print
        '''
        dirName = os.path.abspath(dirName)
        productDir = self.handle.Product.getDefaultProductDirectory(dirName)
        if not productDir:
            raise errors.RbuildError('could not find product for directory %s'
                % dirName)
        product = self.handle.Product.getProductStoreFromDirectory(productDir)
        self.printProductStatus(product)
        self._printOneDirectoryStatus(dirName)
        for dirpath, dirnames, _ in os.walk(dirName):
            for oneDir in sorted(dirnames):
                if oneDir == '.rbuild':
                    continue
                self._printOneDirectoryStatus(os.path.join(dirpath, oneDir))

    def _printOneDirectoryStatus(self, dirName):
        '''
        Prints directory status, if any, for a directory that is a
        checkout or stage.  For a directory that is neither a checkout
        not a stage, do nothing.
        @param dirName: Name of directory
        '''
{'fraction_non_alphanumeric': 0.0736196319018405, 'fraction_numerical': 0.0037181632273656814, 'mean_word_length': 2.565275016567263, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7511918', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1322, 'n_words': 501}