[121224] branches/gsoc14-cleanup/src/macports1.0/reclaim.tcl

ksammons at macports.org ksammons at macports.org
Fri Jun 20 16:14:05 PDT 2014


Revision: 121224
          https://trac.macports.org/changeset/121224
Author:   ksammons at macports.org
Date:     2014-06-20 16:14:05 -0700 (Fri, 20 Jun 2014)
Log Message:
-----------
Changed the reclaim namespace appearance.

Modified Paths:
--------------
    branches/gsoc14-cleanup/src/macports1.0/reclaim.tcl

Modified: branches/gsoc14-cleanup/src/macports1.0/reclaim.tcl
===================================================================
--- branches/gsoc14-cleanup/src/macports1.0/reclaim.tcl	2014-06-20 23:14:04 UTC (rev 121223)
+++ branches/gsoc14-cleanup/src/macports1.0/reclaim.tcl	2014-06-20 23:14:05 UTC (rev 121224)
@@ -17,193 +17,191 @@
 package require macports
 
 namespace eval reclaim {
-}
 
-proc reclaim::main {args} {
+    proc main {args} {
 
-    # The main function. Calls each individual function that needs to be run.
-    # Args: 
-    #           None
-    # Returns:
-    #           None
+        # The main function. Calls each individual function that needs to be run.
+        # Args: 
+        #           None
+        # Returns:
+        #           None
 
-    uninstall_inactive
-    remove_distfiles
-}
+        uninstall_inactive
+        remove_distfiles
+    }
 
-proc reclaim::walk_files {dir delete dist_paths} {
+    proc walk_files {dir delete dist_paths} {
 
-    # Recursively walk through each directory that isn't an installed port and if delete each file that isn't a directory if requested.
-    # Args:
-    #           dir             - A string path of the given directory to walk through
-    #           delete          - Whether to delete each file found that isn't a directory or not. Set to 'yes' or 'no'. 
-    #           dist_paths      - A list of the full paths for all distfiles from installed ports  
-    # Returns: 
-    #           'no' if no distfiles were found, and 'yes' if distfiles were found. 
+        # Recursively walk through each directory that isn't an installed port and if delete each file that isn't a directory if requested.
+        # Args:
+        #           dir             - A string path of the given directory to walk through
+        #           delete          - Whether to delete each file found that isn't a directory or not. Set to 'yes' or 'no'. 
+        #           dist_paths      - A list of the full paths for all distfiles from installed ports  
+        # Returns: 
+        #           'no' if no distfiles were found, and 'yes' if distfiles were found. 
 
-    set found_distfile no 
+        set found_distfile no 
 
 
-    foreach item [readdir $dir] {
+        foreach item [readdir $dir] {
 
-        set currentPath [file join $dir $item]
+            set currentPath [file join $dir $item]
 
-        if {[file isdirectory $currentPath]} {
-            walk_files $currentPath $delete $dist_paths
+            if {[file isdirectory $currentPath]} {
+                walk_files $currentPath $delete $dist_paths
 
-        } else {
-            
-            if {[lsearch $dist_paths $currentPath] == -1} {
-                set found_distfile yes
+            } else {
+                
+                if {[lsearch $dist_paths $currentPath] == -1} {
+                    set found_distfile yes
 
-                # Only care about files that exist in /distfiles that are not a distfile from an installed file.
-                ui_msg "Found distfile: $item"
+                    # Only care about files that exist in /distfiles that are not a distfile from an installed file.
+                    ui_msg "Found distfile: $item"
 
-                if {$delete eq "yes"} {
-                    ui_msg "Removing distfile: $item"
+                    if {$delete eq "yes"} {
+                        ui_msg "Removing distfile: $item"
 
-                    # Because we're only deleting files (not directories) that we know exist, if there was an error, it's because of lack of root privledges.
-                    if {[catch {file delete $currentPath} result]} { 
-                        file delete $currentPath
+                        # Because we're only deleting files (not directories) that we know exist, if there was an error, it's because of lack of root privledges.
+                        if {[catch {file delete $currentPath} result]} { 
+                            file delete $currentPath
+                        }
                     }
                 }
             }
         }
+
+        return $found_distfile
     }
 
-    return $found_distfile
-}
+    proc remove_distfiles {} {
 
-proc reclaim::remove_distfiles {} {
+        # Check for distfiles in both the root, and home directories. If found, delete them.
+        # Args:
+        #               None
+        # Returns:
+        #               0 on successful execution
 
-    # Check for distfiles in both the root, and home directories. If found, delete them.
-    # Args:
-    #               None
-    # Returns:
-    #               0 on successful execution
+        global macports::portdbpath
+        global macports::user_home
 
-    global macports::portdbpath
-    global macports::user_home
+        # The root and home distfile folder locations, respectively. 
+        set root_dist       [file join ${macports::portdbpath} distfiles]
+        set home_dist       ${macports::user_home}/.macports$root_dist
 
-    # The root and home distfile folder locations, respectively. 
-    set root_dist       [file join ${macports::portdbpath} distfiles]
-    set home_dist       ${macports::user_home}/.macports$root_dist
+        set port_info    [get_info]
+        set dist_path    [list]
 
-    set port_info    [get_info]
-    set dist_path    [list]
+        foreach port $port_info {
 
-    foreach port $port_info {
+            # Get mport reference
+            set mport [mportopen_installed [lindex $port 0] [lindex $port 1] [lindex $port 2] [lindex $port 3] {}]
 
-        # Get mport reference
-        set mport [mportopen_installed [lindex $port 0] [lindex $port 1] [lindex $port 2] [lindex $port 3] {}]
+            # Setup sub-Tcl-interpreter that executed the installed port
+            set workername [ditem_key $mport workername]
 
-        # Setup sub-Tcl-interpreter that executed the installed port
-        set workername [ditem_key $mport workername]
+            # Append that port's distfiles to the list
+            set subdir [$workername eval return \$dist_subdir]
+            set name   [$workername eval return \$distfiles]
 
-        # Append that port's distfiles to the list
-        set subdir [$workername eval return \$dist_subdir]
-        set name   [$workername eval return \$distfiles]
+            set root_path [file join $root_dist $subdir $name]
+            set home_path [file join $home_dist $subdir $name]
 
-        set root_path [file join $root_dist $subdir $name]
-        set home_path [file join $home_dist $subdir $name]
+            # Add the full file path to the list, depending where it's located.
+            if {[file isfile $root_path]} {
+                lappend dist_path $root_path
 
-        # Add the full file path to the list, depending where it's located.
-        if {[file isfile $root_path]} {
-            lappend dist_path $root_path
-
-        } else {
-            if {[file isfile $home_path]} {
-                lappend dist_path $home_path
+            } else {
+                if {[file isfile $home_path]} {
+                    lappend dist_path $home_path
+                }
             }
         }
-    }
 
-    # Walk through each directory, and delete any files found. Alert the user if no files were found.
-    if {[walk_files $root_dist yes $dist_path] eq "no"} {
-        ui_msg "No distfiles found in root directory."
-    }
+        # Walk through each directory, and delete any files found. Alert the user if no files were found.
+        if {[walk_files $root_dist yes $dist_path] eq "no"} {
+            ui_msg "No distfiles found in root directory."
+        }
 
-    #if {[walk_files $home_dist yes $dist_path] eq "no"} {
-    #    ui_msg "No distfiles found in home directory."
-    #}
+        #if {[walk_files $home_dist yes $dist_path] eq "no"} {
+        #    ui_msg "No distfiles found in home directory."
+        #}
 
-    return 0
-} 
+        return 0
+    } 
 
-proc reclaim::is_inactive {app} {
+    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.
+        # 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
+        if {[lindex $app 4] == 0} {
+            return 1
+        }
+        return 0
     }
-    return 0
-}
 
-proc reclaim::get_info {} {
+    proc get_info {} {
 
-    # Get's the information of all installed appliations (those returned by registry::installed), 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 = variants, 4 = activity, and 5 = epoch.
-    
-    return [registry::installed] 
-}
+        # Get's the information of all installed appliations (those returned by registry::installed), 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 = variants, 4 = activity, and 5 = epoch.
+        
+        return [registry::installed] 
+    }
 
-proc reclaim::uninstall_inactive {} {
+    proc uninstall_inactive {} {
 
-    # Attempts to uninstall all inactive applications. (Performance is now O(N)!)
-    #
-    # Args: 
-    #           None
-    # Returns: 
-    #           0 if execution was successful. Errors (for now) if execution wasn't. 
+        # Attempts to uninstall all inactive applications. (Performance is now O(N)!)
+        #
+        # Args: 
+        #           None
+        # Returns: 
+        #           0 if execution was successful. Errors (for now) if execution wasn't. 
 
-    set apps            [get_info]
-    set inactive_apps   [list]
-    set inactive_names  [list]
-    set inactive_count  0
+        set apps            [get_info]
+        set inactive_apps   [list]
+        set inactive_names  [list]
+        set inactive_count  0
 
-    foreach app $apps {
+        foreach app $apps {
 
-        if { [is_inactive $app] } {
-            lappend inactive_apps $app
-            lappend inactive_names [lindex $app 0]
-            incr inactive_count
+            if { [is_inactive $app] } {
+                lappend inactive_apps $app
+                lappend inactive_names [lindex $app 0]
+                incr inactive_count
+            }
         }
-    }
-    if { $inactive_count == 0 } {
-        ui_msg "Found no inactive ports."
+        if { $inactive_count == 0 } {
+            ui_msg "Found no inactive ports."
 
-    } else {
+        } else {
 
-        ui_msg "Found inactive ports: $inactive_names."
-        ui_msg "Would you like to uninstall these apps? \[Y/N\]: "
-        set input [gets stdin]
+            ui_msg "Found inactive ports: $inactive_names."
+            ui_msg "Would you like to uninstall these apps? \[Y/N\]: "
+            set input [gets stdin]
 
-        if {$input eq "Y" || $input eq "y" } {
+            if {$input eq "Y" || $input eq "y" } {
 
-            foreach app $inactive_apps {
-                set name [lindex $app 0]
-                ui_msg "Uninstalling: $name"
-                incr inactive_count
+                foreach app $inactive_apps {
+                    set name [lindex $app 0]
+                    ui_msg "Uninstalling: $name"
+                    incr inactive_count
 
-                # Note: 'uninstall' takes a name, version, and an options list. 
-                registry_uninstall::uninstall [lindex $app 0] [lindex $app 1] [lindex $app 2] [lindex $app 3] {}
+                    # Note: 'uninstall' takes a name, version, and an options list. 
+                    registry_uninstall::uninstall [lindex $app 0] [lindex $app 1] [lindex $app 2] [lindex $app 3] {}
+                }
+            } else {
+                ui_msg "Not uninstalling applications."
             }
-        } else {
-            ui_msg "Not uninstalling applications."
         }
+        return 0
     }
-    return 0
 }
-
-
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20140620/cb8a8452/attachment-0001.html>


More information about the macports-changes mailing list