cpee-model-management 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76e0d7c0432ac96ec120c71aaf6fd7c5743c3399ebfd362c9c05c00c8ed31be2
4
- data.tar.gz: fc22ce69a793d227476be4cd24e97a9c78d07dbe39f2a1fae6b12aa2ed6becc8
3
+ metadata.gz: 7bb70d01ebeeb6576722a378ec65514aa3118432737caf27d979c54ac3f4d73e
4
+ data.tar.gz: a69e9dc695583d226724283e2364c03a51978d488c8f718cb088708ec29468e8
5
5
  SHA512:
6
- metadata.gz: 4b1cc4fabe2a895873ee7c3dd8d9ff5389306c22ae550885c71835a0b0605720603cee8f4da2129a3631f1f86efc0237be1482afc592f2776c7a0ab552eb6535
7
- data.tar.gz: 0fbcf28cfa5d9d76b4eb0e09614390f9009f597152ad093e753ea4fbeac68386574a89c713544c205f19c225738edeaa86424dd15568291f112a6143e8b1b4f8
6
+ metadata.gz: 00aa163e4d9be3bc7e55d37116e33c4e99f47e3d8dad2a570d24648993c1a5016f79385c5fdbdf3cbd62783023441a93d073f3be40ebef2da75bdbd058b43917
7
+ data.tar.gz: 8ae2de3be4e438df6d5e0f99223d25bab844fc2663b79c42f465bada4bd9916eec111258eed21a2fda6e6c61db19d3b742f9087cb67cffcc230bb4d7c2073a45
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cpee-model-management"
3
- s.version = "1.0.1"
3
+ s.version = "1.0.2"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.license = "LGPL-3.0"
6
6
  s.summary = "(Lifecycle) manage your process models in a directory or git repo."
@@ -22,72 +22,134 @@ require 'riddl/server'
22
22
  require 'riddl/client'
23
23
  require 'riddl/protocols/utils'
24
24
  require 'fileutils'
25
+ require 'pathname'
25
26
 
26
27
  module CPEE
27
28
  module ModelManagement
28
29
 
29
30
  SERVER = File.expand_path(File.join(__dir__,'moma.xml'))
30
31
 
32
+ def self::git_mv(models,old,new)
33
+ cdir = Dir.pwd
34
+ Dir.chdir(File.join(models,File.dirname(old)))
35
+ p1 = Pathname.new(File.dirname(old))
36
+ p2 = Pathname.new(File.dirname(new))
37
+ old = File.basename(old)
38
+ new = File.join(p1.relative_path_from(p1).to_s,File.basename(new))
39
+ `git mv "#{old}" "#{new}" 2>/dev/null`
40
+ `git rm -rf "#{old + '.active'}" "#{new + '.active'}" 2>/dev/null`
41
+ `git rm -rf "#{old + '.active-uuid'}" "#{new + '.active-uuid'}" 2>/dev/null`
42
+ `git mv "#{old + '.author'}" "#{new + '.author'}" 2>/dev/null`
43
+ `git mv "#{old + '.creator'}" "#{new + '.creator'}" 2>/dev/null`
44
+ `git mv "#{old + '.stage'}" "#{new + '.stage'}" 2>/dev/null`
45
+ Dir.chdir(cdir)
46
+ end
47
+ def self::git_rm(models,new)
48
+ cdir = Dir.pwd
49
+ Dir.chdir(File.join(models,File.dirname(new)))
50
+ new = File.basename(new)
51
+ `git rm -rf "#{new}" 2>/dev/null`
52
+ FileUtils.rm_rf(new)
53
+ `git rm -rf "#{new}.active" 2>/dev/null`
54
+ `git rm -rf "#{new}.active-uuid" 2>/dev/null`
55
+ `git rm -rf "#{new}.author" 2>/dev/null`
56
+ `git rm -rf "#{new}.creator" 2>/dev/null`
57
+ `git rm -rf "#{new}.stage" 2>/dev/null`
58
+ Dir.chdir(cdir)
59
+ end
60
+ def self::git_shift(models,new)
61
+ cdir = Dir.pwd
62
+ Dir.chdir(File.join(models,File.dirname(new)))
63
+ new = File.basename(new)
64
+ `git rm -rf "#{new}.active" 2>/dev/null`
65
+ `git rm -rf "#{new}.active-uuid" 2>/dev/null`
66
+ Dir.chdir(cdir)
67
+ end
68
+ def self::git_commit(models,new,author)
69
+ Process.fork do
70
+ exec 'ruby', File.join(__dir__,'commit.rb'), File.realpath(models), new, author
71
+ end
72
+ end
73
+ def self::fs_mv(models,old,new)
74
+ fname = File.join(models,old)
75
+ fnname = File.join(models,new)
76
+ FileUtils.mv(fname,fnname)
77
+ File.delete(fname + '.active',fnname + '.active') rescue nil
78
+ File.delete(fname + '.active-uuid',fnname + '.active-uuid') rescue nil
79
+ FileUtils.mv(fname + '.author',fnname + '.author') rescue nil
80
+ FileUtils.mv(fname + '.creator',fnname + '.creator') rescue nil
81
+ FileUtils.mv(fname + '.stage',fnname + '.stage') rescue nil
82
+ end
83
+ def self::fs_cp(models,old,new)
84
+ fname = File.join(models,old)
85
+ fnname = File.join(models,new)
86
+ FileUtils.cp(fname,fnname)
87
+ File.delete(fname + '.active',fnname + '.active') rescue nil
88
+ File.delete(fname + '.active-uuid',fnname + '.active-uuid') rescue nil
89
+ FileUtils.cp(fname + '.author',fnname + '.author') rescue nil
90
+ FileUtils.cp(fname + '.creator',fnname + '.creator') rescue nil
91
+ FileUtils.cp(fname + '.stage',fnname + '.stage') rescue nil
92
+ end
93
+ def self::fs_rm(models,new)
94
+ fname = File.join(models,new)
95
+ FileUtils.rm_rf(fname)
96
+ File.delete(fname + '.active') rescue nil
97
+ File.delete(fname + '.active-uuid') rescue nil
98
+ File.delete(fname + '.author') rescue nil
99
+ File.delete(fname + '.creator') rescue nil
100
+ File.delete(fname + '.stage') rescue nil
101
+ end
102
+ def self::fs_shift(models,new)
103
+ fname = File.join(models,new)
104
+ File.delete(fname + '.active') rescue nil
105
+ File.delete(fname + '.active-uuid') rescue nil
106
+ Dir.chdir(cdir)
107
+ end
108
+
109
+ def self::git_dir(models,file)
110
+ return nil if file.nil?
111
+ cdir = Dir.pwd
112
+ tdir = File.dirname(file)
113
+ Dir.chdir(File.join(models,tdir))
114
+ res = `git rev-parse --absolute-git-dir 2>/dev/null`
115
+ Dir.chdir(cdir)
116
+ res == '' ? nil : res
117
+ end
118
+
31
119
  def self::op(author,op,models,new,old=nil) #{{{
32
- if File.exists?(File.join(models,'.git'))
33
- cdir = Dir.pwd
34
- Dir.chdir(models)
35
- case op
36
- when 'mv'
37
- fname = old
38
- fnname = new
39
- `git mv "#{fname}" "#{fnname}" 2>/dev/null`
40
- `git rm -rf "#{fname + '.active'}" "#{fnname + '.active'}" 2>/dev/null`
41
- `git rm -rf "#{fname + '.active-uuid'}" "#{fnname + '.active-uuid'}" 2>/dev/null`
42
- `git mv "#{fname + '.author'}" "#{fnname + '.author'}" 2>/dev/null`
43
- `git mv "#{fname + '.creator'}" "#{fnname + '.creator'}" 2>/dev/null`
44
- `git mv "#{fname + '.stage'}" "#{fnname + '.stage'}" 2>/dev/null`
45
- when 'rm'
46
- fname = new
47
- `git rm -rf "#{fname}" 2>/dev/null`
48
- FileUtils.rm_rf(fname)
49
- `git rm -rf "#{fname}.active" 2>/dev/null`
50
- `git rm -rf "#{fname}.active-uuid" 2>/dev/null`
51
- `git rm -rf "#{fname}.author" 2>/dev/null`
52
- `git rm -rf "#{fname}.creator" 2>/dev/null`
53
- `git rm -rf "#{fname}.stage" 2>/dev/null`
54
- when 'shift'
55
- fname = new
56
- `git rm -rf "#{fname}.active" 2>/dev/null`
57
- `git rm -rf "#{fname}.active-uuid" 2>/dev/null`
120
+ git_ndir = CPEE::ModelManagement::git_dir(models,new)
121
+ git_odir = CPEE::ModelManagement::git_dir(models,old)
122
+
123
+ if op == 'rm' && !git_ndir.nil?
124
+ git_rm models, new
125
+ git_commit models, new, author
126
+ elsif op == 'shift' && !git_ndir.nil?
127
+ git_shift models, new
128
+ git_commit models, new, author
129
+ elsif op == 'mv' && (!git_ndir.nil? || !git_odir.nil?)
130
+ if git_ndir == git_odir
131
+ git_mv models, old, new
132
+ git_commit models, new, author
133
+ elsif git_ndir != git_odir && !git_ndir.nil? && !git_odir.nil?
134
+ fs_cp models, old, new
135
+ git_rm models, old
136
+ git_commit models, old, author
137
+ git_commit models, new, author
138
+ elsif git_ndir != git_odir && git_ndir.nil?
139
+ fs_cp models, old, new
140
+ git_rm models, old
141
+ git_commit models, old, author
142
+ elsif git_ndir != git_odir && git_odir.nil?
143
+ fs_mv models, old, new
144
+ git_commit models, new, author
58
145
  end
59
- fname = new
60
- `git add "#{fname}" 2>/dev/null`
61
- `git add "#{fname}.active" 2>/dev/null`
62
- `git add "#{fname}.active-uuid" 2>/dev/null`
63
- `git add "#{fname}.author" 2>/dev/null`
64
- `git add "#{fname}.creator" 2>/dev/null`
65
- `git add "#{fname}.stage" 2>/dev/null`
66
- `git commit -m "#{author.gsub(/"/,"'")}"`
67
- Dir.chdir(cdir)
146
+ elsif !git_ndir.nil?
147
+ git_commit models, new, author
68
148
  else
69
149
  case op
70
- when 'mv'
71
- fname = File.join(models,old)
72
- fnname = File.join(models,new)
73
- FileUtils.mv(fname,fnname)
74
- File.delete(fname + '.active',fnname + '.active') rescue nil
75
- File.delete(fname + '.active-uuid',fnname + '.active-uuid') rescue nil
76
- FileUtils.mv(fname + '.author',fnname + '.author') rescue nil
77
- FileUtils.mv(fname + '.creator',fnname + '.creator') rescue nil
78
- FileUtils.mv(fname + '.stage',fnname + '.stage') rescue nil
79
- when 'rm'
80
- fname = File.join(models,new)
81
- FileUtils.rm_rf(fname)
82
- File.delete(fname + '.active') rescue nil
83
- File.delete(fname + '.active-uuid') rescue nil
84
- File.delete(fname + '.author') rescue nil
85
- File.delete(fname + '.creator') rescue nil
86
- File.delete(fname + '.stage') rescue nil
87
- when 'shift'
88
- fname = File.join(models,new)
89
- File.delete(fname + '.active') rescue nil
90
- File.delete(fname + '.active-uuid') rescue nil
150
+ when 'mv'; fs_mv(models,old,new)
151
+ when 'rm'; fs_rm(models,new)
152
+ when 'shift'; fs_shift(models,new)
91
153
  end
92
154
  end
93
155
  end #}}}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpee-model-management
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler
8
8
  autorequire:
9
9
  bindir: tools
10
10
  cert_chain: []
11
- date: 2021-03-25 00:00:00.000000000 Z
11
+ date: 2021-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: riddl