disloku 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/lib/disloku/BaseCommand.rb +79 -0
  3. data/lib/disloku/ChangeSet.rb +13 -1
  4. data/lib/disloku/CliAdapter.rb +36 -0
  5. data/lib/disloku/Constants.rb +4 -0
  6. data/lib/disloku/FileChange.rb +7 -2
  7. data/lib/disloku/Log.rb +39 -12
  8. data/lib/disloku/Repository.rb +10 -1
  9. data/lib/disloku/SysCmd.rb +2 -2
  10. data/lib/disloku/commands/Build.rb +30 -0
  11. data/lib/disloku/commands/Config.rb +17 -0
  12. data/lib/disloku/commands/Deploy.rb +38 -0
  13. data/lib/disloku/config/Connection.rb +34 -0
  14. data/lib/disloku/config/ConnectionStore.rb +19 -0
  15. data/lib/disloku/config/Mapping.rb +84 -0
  16. data/lib/disloku/config/MappingStore.rb +19 -0
  17. data/lib/disloku/config/NamedConfigStore.rb +41 -0
  18. data/lib/disloku/config/Options.rb +51 -0
  19. data/lib/disloku/config/Target.rb +37 -0
  20. data/lib/disloku/config/YamlConfig.rb +54 -0
  21. data/lib/disloku/git/ChangeSetProvider.rb +19 -6
  22. data/lib/disloku/git/Repository.rb +16 -2
  23. data/lib/disloku/svn/ChangeSetProvider.rb +44 -41
  24. data/lib/disloku/svn/Repository.rb +24 -21
  25. data/lib/disloku/tasks/FolderTask.rb +5 -5
  26. data/lib/disloku/tasks/NetSftpTask.rb +39 -29
  27. data/lib/disloku/util/File.rb +9 -3
  28. data/lib/disloku.rb +24 -10
  29. metadata +20 -15
  30. data/lib/disloku/Commit.rb +0 -7
  31. data/lib/disloku/Config.rb +0 -52
  32. data/lib/disloku/Connection.rb +0 -31
  33. data/lib/disloku/ConnectionStore.rb +0 -16
  34. data/lib/disloku/Disloku.rb +0 -103
  35. data/lib/disloku/Mapping.rb +0 -81
  36. data/lib/disloku/MappingStore.rb +0 -16
  37. data/lib/disloku/NamedConfigStore.rb +0 -39
  38. data/lib/disloku/Options.rb +0 -46
  39. data/lib/disloku/Target.rb +0 -35
  40. data/lib/disloku/tasks/PsFtpTask.rb +0 -58
@@ -1,103 +0,0 @@
1
- require_relative('DislokuError')
2
- require_relative('Config')
3
- require_relative('Options')
4
- require_relative('MappingStore')
5
- require_relative('ConnectionStore')
6
- require_relative('Target')
7
- require_relative('git/Repository')
8
- require_relative('tasks/FolderTask')
9
- require_relative('tasks/NetSftpTask')
10
-
11
- module Disloku
12
- class Disloku
13
- attr_accessor :repository, :config
14
-
15
- def initialize(cliOptions)
16
- @repository = Git::Repository.new(cliOptions[:dir])
17
- @config = loadConfiguration()
18
- @options = Options.new(@config["options"], cliOptions)
19
- @mappingStore = MappingStore.new(@config["mappings"])
20
- @connectionStore = ConnectionStore.new(@config["connections"])
21
- end
22
-
23
- def loadConfiguration()
24
- repoConfig = File.join(repository.root, 'disloku.config')
25
- if (!File.exists?(repoConfig))
26
- raise DislokuError.new("There is no disloku.config file in #{repository.root}")
27
- end
28
-
29
- config = Config.new(repoConfig)
30
-
31
- userHome = File.expand_path("~")
32
- userConfig = File.join(userHome, ".disloku.config")
33
- if (File.exists?(userConfig))
34
- base = Config.new(userConfig)
35
- config.merge(base)
36
- end
37
-
38
- return config
39
- end
40
-
41
- def buildPackage(from, to)
42
- changesets = @repository.getChangeSets(from, to)
43
-
44
- folderInput = {
45
- :options => @options,
46
- :allowOverride => false,
47
- :changesets => changesets,
48
- :target => nil,
49
- }
50
-
51
- resolveTargets([@options.target]).each() do |t|
52
- folderInput[:target] = t
53
-
54
- result = Tasks::FolderTask.new(folderInput).execute()
55
- p(result)
56
- end
57
- end
58
-
59
- def deployPackage(from, to)
60
- changesets = @repository.getChangeSets(from, to)
61
-
62
- folderInput = {
63
- :options => @options,
64
- :allowOverride => false,
65
- :changesets => changesets,
66
- :target => nil,
67
- }
68
-
69
- resolveTargets([@options.target]).each() do |t|
70
- folderInput[:target] = t
71
-
72
- result = Tasks::FolderTask.new(folderInput).execute()
73
-
74
- sftpInput = result.merge({
75
- :repository => @repository,
76
- :options => @options,
77
- :target => t,
78
- })
79
-
80
- result = Tasks::NetSftpTask.new(sftpInput).execute()
81
- end
82
- end
83
-
84
- def resolveTargets(targets)
85
- actualTargets = []
86
-
87
- while (targets.count > 0)
88
- current = targets.shift()
89
- targetConfig = @config["targets"][current]
90
- if (targetConfig != nil)
91
- if (targetConfig["targets"] != nil)
92
- targetConfig["targets"].value().each() { |x| targets.push(x.value()) }
93
- next
94
- end
95
-
96
- actualTargets.push(Target.new(current, targetConfig, @mappingStore, @connectionStore))
97
- end
98
- end
99
-
100
- return actualTargets
101
- end
102
- end
103
- end
@@ -1,81 +0,0 @@
1
- require_relative('util/Hash')
2
- require_relative('util/File')
3
-
4
- module Disloku
5
- class Mapping
6
-
7
- def initialize(config, mappingStore = nil, allowDefault = true)
8
- @mapping = {}
9
-
10
- mappingConfig = config["mapping"]
11
- if (!mappingConfig.nil?)
12
- mappingConfig.value().each() do |m|
13
- node = @mapping
14
- src = m["src"].value()
15
-
16
- if (src.kind_of?(Symbol))
17
- segments = [src]
18
- else
19
- segments = src.split(/#{Util::SPLIT_EXP}/)
20
-
21
- segments[0..-2].each() do |segment|
22
- if (!node.has_key?(segment))
23
- node[segment] = {}
24
- end
25
- node = node[segment]
26
- end
27
- end
28
-
29
- if (!m["block"].nil? && m["block"].value())
30
- node[segments[-1]] = :block
31
- else
32
- dst = m["dst"].value()
33
- if (dst.kind_of?(Symbol))
34
- node[segments[-1]] = dst
35
- else
36
- node[segments[-1]] = m["dst"].value().split(/#{Util::SPLIT_EXP}/)
37
- end
38
- end
39
- end
40
- elsif (allowDefault)
41
- @mapping[:any] = :keep
42
- end
43
-
44
- baseMapping = config["baseMapping"].nil? ? nil : config["baseMapping"].value()
45
-
46
- if (!baseMapping.nil?)
47
- if (mappingStore.nil?)
48
- raise ArgumentError.new("mapping has a base but no mapping manager was passed")
49
- else
50
- @mapping = mappingStore.get(baseMapping).getTree().recursive_merge(@mapping)
51
- end
52
- end
53
- end
54
-
55
- def getTree()
56
- return @mapping
57
- end
58
-
59
- def mapPath(pathSegments)
60
- node = @mapping
61
- for i in 0..pathSegments.count
62
- if (node.has_key?(pathSegments[i]))
63
- node = node[pathSegments[i]]
64
- elsif (node.has_key?(:any))
65
- node = node[:any]
66
- else
67
- return nil
68
- end
69
-
70
- if (node == :block)
71
- return nil
72
- elsif (node == :keep)
73
- return pathSegments
74
- elsif (node.kind_of?(Array))
75
- return Array.new(node).concat(pathSegments[(i + 1)..-1])
76
- end
77
- end
78
- end
79
-
80
- end
81
- end
@@ -1,16 +0,0 @@
1
- require_relative('NamedConfigStore')
2
- require_relative('Mapping')
3
-
4
- module Disloku
5
- class MappingStore < NamedConfigStore
6
-
7
- def initialize(config = nil)
8
- super(config)
9
- end
10
-
11
- def transformConfig(configObject)
12
- return Mapping.new(configObject, self, false)
13
- end
14
-
15
- end
16
- end
@@ -1,39 +0,0 @@
1
- require_relative('DislokuError')
2
- require_relative('Connection')
3
-
4
- module Disloku
5
- class NamedConfigStore
6
-
7
- def initialize(config = nil)
8
- @store = {}
9
- if (!config.nil?)
10
- load(config)
11
- end
12
- end
13
-
14
- def get(name)
15
- if (@store.has_key?(name))
16
- return @store[name]
17
- else
18
- raise DislokuError.new("There is no stored object with the name '#{name}' in this store")
19
- end
20
- end
21
-
22
- def add(name, configObject)
23
- @store[name] = transformConfig(configObject)
24
- end
25
-
26
- def load(config)
27
- if (!config.nil?)
28
- config.value().each_key() do |key|
29
- add(key, config[key])
30
- end
31
- end
32
- end
33
-
34
- def transformConfig(configObject)
35
- return configObject
36
- end
37
-
38
- end
39
- end
@@ -1,46 +0,0 @@
1
- require_relative('Log')
2
- require_relative('Config')
3
- require_relative('util/Kernel')
4
- require('tmpdir')
5
- require('fileutils')
6
-
7
- module Disloku
8
- class Options
9
-
10
- def initialize(config, cliOptions)
11
- @options = {
12
- :ignoreDeleteErrors => false,
13
- :createDeletesFile => false,
14
- :target => "default",
15
- :packageDir => :temp,
16
- }
17
-
18
- @options.each_key() do |key|
19
- if (cliOptions.has_key?(key.to_s()))
20
- @options[key] = cliOptions[key.to_s()]
21
- elsif (config[key.to_s()] != nil)
22
- @options[key] = config[key.to_s()].value()
23
- end
24
- end
25
-
26
- if (@options[:packageDir] == :temp)
27
- @options[:packageDir] = Dir.mktmpdir("disloku")
28
- Log.instance.debug("Creating tmp directory #{@options[:packageDir]}")
29
-
30
- # make sure the temp directory is deleted when the program exists
31
- at_exit {
32
- Log.instance.debug("Removing tmp directory #{@options[:packageDir]}")
33
- FileUtils.rm_r(@options[:packageDir], :force => true)
34
- }
35
- end
36
- end
37
-
38
- def method_missing(name, *args, &block)
39
- if (!@options.has_key?(name))
40
- raise ArgumentError.new("There's no option '#{name}' here")
41
- end
42
-
43
- return @options[name]
44
- end
45
- end
46
- end
@@ -1,35 +0,0 @@
1
- require_relative('Mapping')
2
- require_relative('Connection')
3
- require_relative('util/File')
4
-
5
- module Disloku
6
- class Target
7
- attr_accessor :name, :connection
8
-
9
- def initialize(name, targetConfig, mappingStore, connectionStore)
10
- @name = name
11
- @config = targetConfig
12
-
13
- if (@config["connection"].value().kind_of?(String))
14
- @connection = connectionStore.get(@config["connection"].value())
15
- else
16
- @connection = Connection.new(@config["connection"])
17
- end
18
-
19
- @mapping = Mapping.new(@config, mappingStore)
20
- end
21
-
22
- def mapPath(pathSegments)
23
- return @mapping.mapPath(pathSegments)
24
- end
25
-
26
- def method_missing(name, *args, &block)
27
- if (!@config.has?(name.to_s()))
28
- return nil
29
- end
30
-
31
- return @config[name.to_s()].value()
32
- end
33
-
34
- end
35
- end
@@ -1,58 +0,0 @@
1
- require_relative('../Log')
2
- require_relative('../BaseTask')
3
- require('open3')
4
-
5
- module Disloku
6
- module Tasks
7
- # class PsFtpTask < BaseTask
8
- # def initialize(stream, config, changesets)
9
- # super(stream, changesets)
10
- # @config = config.yaml["psftp"]
11
- # end
12
-
13
- # def beforeExecute()
14
- # Log.instance.info(@config["path"])
15
- # env = @config["env"][0]
16
- # Log.instance.info(env)
17
- # cmd = "\"#{@config['path']}\""
18
-
19
- # if (env.has_key?("key"))
20
- # cmd += " -i \"#{env['key']}\""
21
- # else
22
- # cmd += " -pw #{env['password']}"
23
- # end
24
-
25
- # cmd += " #{env['user']}@#{env['host']}"
26
-
27
- # Log.instance.info(cmd)
28
-
29
- # @stream, @output = Open3.popen2(cmd)
30
- # writeLine("cd #{env['targetDir']}")
31
- # end
32
-
33
- # def executeTask(changeset)
34
- # changeset.each() do |change|
35
- # destination = change.file.segments.join("/")
36
- # case change.changeType
37
- # when :modified, :added
38
- # path = change.file.getPathSegments().join('/')
39
- # Log.instance.info("mkdir \"#{path}\"")
40
- # writeLine("mkdir \"#{path}\"")
41
- # Log.instance.info("put \"#{change.file.filePath}\" \"#{destination}\"")
42
- # writeLine("put \"#{change.file.filePath}\" \"#{destination}\"")
43
- # when :deleted
44
- # writeLine("del \"#{destination}\"")
45
- # else
46
- # Log.instance.info("ignoring change type #{change.changeType}")
47
- # end
48
- # end
49
- # end
50
-
51
- # def afterExecute()
52
- # writeLine("quit")
53
-
54
- # @output.readlines.each(&Log.instance.method(:info))
55
- # end
56
- # end
57
- end
58
- end