<commit_before># -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: portclean.tcl 116449 2014-01-25 16:57:17Z <EMAIL> $
#
# Copyright (c) 2005-2007, 2009-2011, 2013 The MacPorts Project
# Copyright (c) 2004 <NAME> <<EMAIL>>
# Copyright (c) 2002 - 2003 Apple Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. Neither the name of Apple Inc. nor the names of its contributors
#    may be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

# the 'clean' target is provided by this package


# TODO:
# Register the "port clean inactive" command with port.tcl and all that involves.
# Add distfile version checking.
# Add multiple version checking. Test with multiple versions of Python? Or Perl? Or some other common multi-versioned software (Gimp?).
# Figure out what the hell is going on with "port clean all" vs "port clean installed"
# Add docstrings for the rest of the functions in here at the end. Lack of documentation is sad. 
# Remove the useless/structure comments and add actual docstrings.

# Finished:
# Implement a hash-map, or multidimensional array for ease of app info keeping. Write it yourself if you have to.

package provide portclean 1.0

package require portutil 1.0
package require registry_uninstall 2.0 
package require Pextlib 1.0

set org.macports.clean [target_new org.macports.clean portclean::clean_main]
target_runtype ${org.macports.clean} always
target_state ${org.macports.clean} no
target_provides ${org.macports.clean} clean
target_requires ${org.macports.clean} main
target_prerun ${org.macports.clean} portclean::clean_start

namespace eval portclean {
}

set_ui_prefix

proc portclean::is_inactive {app} {

    # Determine's whether an application is inactive or not.
    # Args: 
    #           app - An array where the fourth item in it is the activity of the application. 
    # Returns:
    #           1 if inactive, 0 if active.

    if {[lindex $app 4] == 0} {
        return 1
    }
    return 0
}

proc portclean::get_info {} {

    # Get's the information of all installed appliations (those returned by registry::instaled), and returns it in a
    # multidimensional list.
    #
    # Args:
    #           None
    #Returns:
    #           A multidimensional list where each app is a sublist, i.e., {{First Application Info} {Second Application Info} {...}}
    #           Indexes of each sublist are: 0 = name, 1 = version, 2 = revision, 3 = variets, 4 = activity, and 5 = epoch.
    
    set installed_apps [registry::installed]
    set app_info [list] 

    foreach app $installed_apps {

        set name     [lindex $app 0]
        set version  [lindex $app 1]
        set revision [lindex $app 2]
        set varients [lindex $app 3]
        set active   [lindex $app 4]
        set epoch    [lindex $app 5]

        lappend app_info [list $name $version $revision $varients $active $epoch]
    }

    return $app_info
}

proc portclean::delete_file {args} {

    # Attempts to delete a given file, and catches the errors if there are any.
    #
    # Args:
    #           args - The file path
    # Returns:
    #           None

    ui_debug "Removing file: $args"
    if {[catch {delete $args} result]} {
        ui_debug "$::errorInfo"
        ui_error "$result"
    }
}

proc portclean::clean_inactive {} {

    # Attempts to uninstall all inactive applications. (Performance is now O(N)!)
    #
    # Args: 
    #           None
    # Returns: 
    #           0 if execution was successful.

    set apps [get_info]
    set inactive_count 0<commit_msg>Fixed copyright and removed local-only functions from the namespace<commit_after># -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: portclean.tcl 116449 2014-01-25 16:57:17Z <EMAIL> $
#
# Copyright (c) 2005-2007, 2009-2011, 2013-2014 The MacPorts Project
# Copyright (c) 2004 Robert Shaw <<EMAIL>>
# Copyright (c) 2002 - 2003 Apple Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. Neither the name of Apple Inc. nor the names of its contributors
#    may be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

# the 'clean' target is provided by this package


# TODO:
# Register the "port clean inactive" command with port.tcl and all that involves.
# Add distfile version checking.
# Add multiple version checking. Test with multiple versions of Python? Or Perl? Or some other common multi-versioned software (Gimp?).
# Add docstrings for the rest of the functions in here at the end. Lack of documentation is sad. 
# Remove the useless/structure comments and add actual docstrings.

# Finished:
# Implement a hash-map, or multidimensional array for ease of app info keeping. Write it yourself if you have to.
# Figure out what the hell is going on with "port clean all" vs "port clean installed"

package provide portclean 1.0

package require portutil 1.0
package require registry_uninstall 2.0 
package require Pextlib 1.0

set org.macports.clean [target_new org.macports.clean portclean::clean_main]
target_runtype ${org.macports.clean} always
target_state ${org.macports.clean} no
target_provides ${org.macports.clean} clean
target_requires ${org.macports.clean} main
target_prerun ${org.macports.clean} portclean::clean_start

namespace eval portclean {
}

set_ui_prefix

proc is_inactive {app} {

    # Determine's whether an application is inactive or not.
    # Args: 
    #           app - An array where the fourth item in it is the activity of the application. 
    # Returns:
    #           1 if inactive, 0 if active.

    if {[lindex $app 4] == 0} {
        return 1
    }
    return 0
}

proc portclean::get_info {} {

    # Get's the information of all installed appliations (those returned by registry::instaled), and returns it in a
    # multidimensional list.
    #
    # Args:
    #           None
    #Returns:
    #           A multidimensional list where each app is a sublist, i.e., {{First Application Info} {Second Application Info} {...}}
    #           Indexes of each sublist are: 0 = name, 1 = version, 2 = revision, 3 = variets, 4 = activity, and 5 = epoch.
    
    set installed_apps [registry::installed]
    set app_info [list] 

    foreach app $installed_apps {

        set name     [lindex $app 0]
        set version  [lindex $app 1]
        set revision [lindex $app 2]
        set varients [lindex $app 3]
        set active   [lindex $app 4]
        set epoch    [lindex $app 5]

        lappend app_info [list $name $version $revision $varients $active $epoch]
    }

    return $app_info
}

proc delete_file {args} {

    # Attempts to delete a given file, and catches the errors if there are any.
    #
    # Args:
    #           args - The file path
    # Returns:
    #           None

    ui_debug "Removing file: $args"
    if {[catch {delete $args} result]} {
        ui_debug "$::errorInfo"
        ui_error "$result"
    }
}

proc portclean::clean_inactive {} {

    # Attempts to uninstall all inactive applications. (Performance is now O(N)!)
    #
    # Args: 
    #           None
    # Returns: 
    #           0 if execution was successful.

    set apps [get_info]
    set inactive_count 0
{'fraction_non_alphanumeric': 0.07853825964062185, 'fraction_numerical': 0.018574601251766607, 'mean_word_length': 3.2229326513213983, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '2234907', 'n_tokens_mistral': 3051, 'n_tokens_neox': 2729, 'n_words': 1236}