Class: BuildTool::Commands::Gc

Inherits:
ModuleBasedCommand show all
Defined in:
lib/build-tool/commands/gc.rb

Overview

BuildCommand

Instance Attribute Summary

Attributes inherited from Base

#cmd, #options, #parent

Instance Method Summary collapse

Methods inherited from ModuleBasedCommand

#clean, #clone, #configure, #fetch, #initialize, #install, #is_module_ready?, #make, #prepare_module, #rebase, #reconfigure, #remove_build_directory, #remove_source_directory, #summarize

Methods inherited from Standard

#complete_module, #complete_modules, #initialize, #log_directory, #while_logging_to

Methods inherited from Base

#<=>, #cleanup_after_vcs_access, #complete_arguments, #complete_readline, #configuration, #debug, #debug2, #do_complete, #each_option, #error, #execute, #fullname, #info, #initialize, #log?, #quiet, #setup_command, #setup_options, #show_help, #skip_command, #summarize, #teardown_command, #trace, #usage, #verbose, #warn

Methods included from HelpText

#cmdalias, #description, included, #long_description, #name

Constructor Details

This class inherits a constructor from BuildTool::Commands::ModuleBasedCommand

Instance Method Details

#applicable?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/build-tool/commands/gc.rb', line 25

def applicable?
    BuildTool::Application.instance.has_recipe?
end

#cleanup_logdirectoriesObject

Clean up the log directories.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/build-tool/commands/gc.rb', line 41

def cleanup_logdirectories
    logdir = configuration.log_directory

    info( "Removing outdated log files( older than 10 days )." )
    # FIRST STEP: Removing old command logs from db and log/ directory.
    BuildTool::History::CommandLog.older_than.each do |cmd|
        if cmd.logdir
            verbose( "  - Removing outdated log #{cmd.logdir}");
            FileUtils.rm_rf( cmd.logdir, :noop => $noop ) if File.exist?( cmd.logdir )
        end
        cmd.destroy() if not $noop
    end

    # SECOND STEP: Remove old command logs from log/ directory that have no associated
    # entry in the database
    info( "Removing orphaned log directories" )
    logdir.children().sort().each do |abspath|
        next if abspath.basename().to_s == 'latest'
        # Check if it is in the db
        cl = BuildTool::History::CommandLog.where( :logdir => abspath.to_s )
        if cl.count == 0
            verbose( '  - Removing %s' % abspath.to_s )
            FileUtils.rm_r( abspath, :noop => $noop )
        else
            debug( '  - Keeping %s' % abspath.to_s )
        end
    end

    # THIRD STEP: Remove old command logs from database that have no associated directory
    # in log/
    info( "Removing orphaned database entries." )
    BuildTool::History::CommandLog.all( :order => :id ).each do |cl|
        abspath = Pathname.new( cl.logdir )
        if not abspath.exist?
            verbose( '  - Removing orphaned db entry %d' % cl.id )
            cl.destroy() if not $noop
        end
    end
    return 0
end

#do_execute(args) ⇒ Object

Make sure at least the log directories are cleaned up



30
31
32
33
34
35
36
37
38
# File 'lib/build-tool/commands/gc.rb', line 30

def do_execute( args )
    cleanup_logdirectories()

    # Only call the base class if there we modules specified. We get an error else.
    if args.length > 0
        return super
    end
    return 0
end

#do_execute_module(mod) ⇒ Object



82
83
84
# File 'lib/build-tool/commands/gc.rb', line 82

def do_execute_module( mod )
    mod.gc
end

#initialize_optionsObject



18
19
20
21
22
23
# File 'lib/build-tool/commands/gc.rb', line 18

def initialize_options
    options.banner = "Usage: #{self.fullname} [OPTIONS]... [MODULE|GROUP]..."
    options.separator( "" )
    options.separator( "Options" )
    super
end