Class: L5MTools::Application

Inherits:
Object
  • Object
show all
Includes:
Tools
Defined in:
lib/l5m-tools.rb,
lib/l5m-tools/application.rb

Instance Method Summary collapse

Methods included from Tools

#ask, #change_directory, #copy_with_replace, #copy_with_replace_without_puts, #duplicate_and_replace, #replace, #send_mail, #to_file, #user_home

Instance Method Details

#del(*args) ⇒ Object

read file list from file and delete them



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/l5m-tools/application.rb', line 67

def del(*args)
     unless File.exist?(args[0])
        del_wo_csv(*args)
    else
        File.open(args[0], "r") do |infile|
            while (line = infile.gets)
                line = line.chomp.strip
                if line.length > 0 && line[0] != '#'
                    rm(line, :force => true)
                end
            end
        end
    end
end

#del_wo_csv(*args) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/l5m-tools/application.rb', line 55

def del_wo_csv(*args)
    package = args[0]
    application = args[1]
    Dir.glob("#{WORKSPACE}/#{package}/{src,WebContent}/**/#{application}*.*", File::FNM_CASEFOLD).each{|line|  
        bn = File.basename(line, ".*")
        unless(bn[application.length] =~ /[a-z0-9]/)
            puts line
            rm(line, :force => true)
        end                
    }
end

#dupObject



22
# File 'lib/l5m-tools.rb', line 22

alias :dup :duplicate_app

#duplicate_app(*args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/l5m-tools/application.rb', line 20

def duplicate_app(*args)
    delete = args.delete('-d')
    replacements  = {args[1] => args[2]}

    unless File.exist?(args[0])
        duplicate_wo_csv(*args)
    else
        File.open(args[0], "r") do |infile|
            while (line = infile.gets)
                line = line.chomp.strip
                if line.length > 0 && line[0] != '#'
                    #duplicate_and_replace( line.chomp ,  replacements ) 
                    #FileUtils.rm(line, :force => true) if delete
                    rm(line, :force => true) if duplicate_and_replace( line.chomp ,  replacements )[1] != line && delete
                end 
            end
        end
    end
end

#duplicate_wo_csv(*args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/l5m-tools/application.rb', line 40

def duplicate_wo_csv(*args)
    delete = args.delete('-d')
    package = args[0]
    application = args[1]
    replacements  = {args[1] => args[2]}
    Dir.glob("#{WORKSPACE}/#{package}/{src,WebContent}/**/#{application}*.*", File::FNM_CASEFOLD).each{|line|  
        bn = File.basename(line, ".*")
        #puts line #File.basename(line, ".*") 
        unless(bn[application.length] =~ /[a-z0-9]/)
            #puts line #File.basename(line, ".*") 
            rm(line, :force => true) if duplicate_and_replace( line.chomp ,  replacements )[1] != line && delete
        end                
    }
end

#helpObject



109
110
111
112
113
# File 'lib/l5m-tools/application.rb', line 109

def help
    puts <<-EOF
        Please go to https://github.com/RONGHAI/l5m-tools
    EOF
end

#makeObject



21
22
23
24
25
26
# File 'lib/l5m-tools.rb', line 21

def make_app(*args, &block)
    package = ask("rem","Please input package name").downcase
    application = ask("","Please input application name") 
    use_base_worker = ask("true","Use AbstractBaseWorker?").to_boolean
    old_make_app(package, application, use_base_worker, &block)
end

#make_app(package, application, use_base_worker, &block) ⇒ Object



15
16
17
18
19
20
# File 'lib/l5m-tools.rb', line 15

def make_app(*args, &block)
    package = ask("rem","Please input package name").downcase
    application = ask("","Please input application name") 
    use_base_worker = ask("true","Use AbstractBaseWorker?").to_boolean
    old_make_app(package, application, use_base_worker, &block)
end

#old_make_appObject



14
# File 'lib/l5m-tools.rb', line 14

alias old_make_app make_app

#rm(file, options) ⇒ Object

that is svn remove



11
12
13
14
15
16
17
18
19
# File 'lib/l5m-tools/application.rb', line 11

def rm(file, options)
    #FileUtils.rm(file, :force => true)
    # remove file from svn
    package = file[(WORKSPACE.length+1)..(-1)]
    svnfile = package[(package.index(/[\/\\]/) + 1)..(-1)]
    package = package[0...(package.index(/[\/\\]/))]
    require 'l5m-tools/l5m-tools-module'
    L5MTools.svn.delete([package], {}, [ "--force", svnfile])
end

#run(*args, &block) ⇒ Object



23
24
25
# File 'lib/l5m-tools.rb', line 23

def run(*args, &block)
    send args.shift, *args, &block
end

#versionObject



105
106
107
108
# File 'lib/l5m-tools/application.rb', line 105

def version
    file = Pathname.new(__FILE__).parent.parent.parent.to_s + "/VERSION"
    puts(File.exist?(file) ? File.read(file) : "") 
end