flist 0.1.30 → 0.1.33

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/main.yml +31 -0
  3. data/.gitignore +5 -0
  4. data/.rubocop.yml +12 -0
  5. data/.rubocop_todo.yml +129 -0
  6. data/Gemfile +22 -0
  7. data/Rakefile +50 -3
  8. data/SECURITY.md +21 -0
  9. data/bin/console +4 -3
  10. data/bin/setup +2 -0
  11. data/config/.gitkeep +0 -0
  12. data/config/config.yml +14 -0
  13. data/config/config_sample.yml +15 -0
  14. data/config/config_yml.sample +15 -0
  15. data/config/db_scheme.yml +71 -0
  16. data/config/db_scheme.yml.sample +48 -0
  17. data/config/dbsetup.rb +56 -0
  18. data/config/opts.rb +9 -0
  19. data/config/opts.rb.sample +7 -0
  20. data/config/setting.yml +2 -0
  21. data/config/sqlite3.yml +26 -0
  22. data/config/tmp/db_scheme.yml +71 -0
  23. data/db/migrate/010_create_countdatetime.rb +11 -0
  24. data/db/migrate/020_create_flistz.rb +22 -0
  25. data/db/migrate/030_create_invalidflistz.rb +13 -0
  26. data/db/migrate/040_create_currentflistz.rb +15 -0
  27. data/db/migrate/050_create_dirz.rb +12 -0
  28. data/db/migrate/060_create_invaliddirz.rb +13 -0
  29. data/db/migrate/070_create_currentdirz.rb +15 -0
  30. data/exe/flist +80 -27
  31. data/flist.gemspec +33 -20
  32. data/lib/dbacrecord.rb +36 -0
  33. data/lib/flist/cli.rb +49 -0
  34. data/lib/flist/config.rb +16 -0
  35. data/lib/flist/csvx.rb +29 -0
  36. data/lib/flist/dbutil/dbmgr.rb +25 -24
  37. data/lib/flist/dbutil/dirzmgr.rb +75 -12
  38. data/lib/flist/dbutil/flistzmgr.rb +81 -34
  39. data/lib/flist/dbutil.rb +4 -4
  40. data/lib/flist/flist/filelist.rb +219 -168
  41. data/lib/flist/flist.rb +282 -101
  42. data/lib/flist/version.rb +3 -1
  43. data/lib/flist.rb +51 -5
  44. data/lib/template/config_yml.erb +15 -0
  45. metadata +128 -33
  46. data/exe/makemigrate +0 -52
  47. data/lib/flist/flist/store.rb +0 -79
@@ -1,65 +1,112 @@
1
- # -*- coding: utf-8 -*-
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'pp'
4
4
  require 'flist/dbutil/dbmgr'
5
5
 
6
6
  module Flist
7
7
  module Dbutil
8
+ # ファイル情報マネージャ
8
9
  class FlistzMgr
9
- def initialize(encx , db_encoding , register_time)
10
+ include Ykutils::DebugUtils
11
+
12
+ def initialize(encx, db_encoding, register_time)
13
+ # 指定エンコーディングの基づいたパス操作
10
14
  @encx = encx
15
+ # DBのエンコーディング
11
16
  @db_encoding = db_encoding
17
+ # DB接続時のタイムスタンプ
12
18
  @register_time = register_time
19
+ # DBに登録・更新したファイル情報をのハッシュ
20
+ # キーはパス
13
21
  @hs_by_path = {}
22
+ # DBに登録・更新したファイル情報のハッシュ
23
+ # キーはファイル情報のobject_id
14
24
  @hs_by_id = {}
25
+ # DBに登録・更新したファイル情報に対応するディレクトリID
26
+ @set_of_dir_id = Set.new
15
27
  end
16
28
 
17
- def add( dir_id , level, kind, repo, path , project, desc, comment, atime, ctime, mtime )
18
- flistz = @hs_by_path[path]
19
- unless flistz
29
+ # ファイル情報追加・更新
30
+ # DBに未登録の時は追加し、登録済みの時は更新する
31
+ def add(dir_id, level, kind, repo, path, project, desc, comment, atime, ctime, mtime)
32
+ d_puts 'Flist::Dbutil::FlistzMgr add'
33
+ # pathをDBのエンコーディングに変換する
34
+ path_conv = @encx.convert(path, @db_encoding)
35
+ # パスが表すファイル情報をハッシュから得る
36
+ flistz = @hs_by_path[path_conv]
37
+ # パスに対応するファイル情報が見つかれば何もしない
38
+ return flistz if flistz
20
39
 
21
- path_conv = @encx.convert( path , @db_encoding )
22
- cur_flistz = Currentflistz.where( dir_id: dir_id , path: path_conv ).limit(1)
23
- if cur_flistz.size == 0
24
- begin
25
- flistz = Flistz.create( dir_id: dir_id , level: level, kind: kind, repo: repo, path: path_conv , project: project, desc: desc, comment: comment, atime: atime, ctime: ctime, mtime: mtime , start_datetime: @register_time )
26
- rescue => ex
27
- p ex.class
28
- p ex.message
29
- pp ex.backtrace
40
+ # FlistzのViewから、dir_idとパスで指定したファイル情報を得る
41
+ cur_flistz = Currentflistz.where(dir_id: dir_id, path: path_conv).limit(1)
42
+ if cur_flistz.size.zero?
43
+ # 見つからなければ、新たにファイル情報をDBに登録する
44
+ begin
45
+ d_puts '#### FlistzMgr'
46
+ d_puts "dir_id=#{dir_id}"
47
+ d_puts "level=#{level}"
48
+ d_puts "kind=#{kind}"
49
+ d_puts "repo=#{repo}"
50
+ d_puts "path=#{path_conv}"
51
+ d_puts "project=#{project}"
52
+ d_puts "desc=#{desc}"
53
+ d_puts "comment=#{comment}"
54
+ d_puts "atime=#{atime}"
55
+ d_puts "ctime=#{ctime}"
56
+ d_puts "mtime=#{mtime}"
57
+ d_puts "@register_time=#{@register_time}"
58
+ d_puts '#### FlistzMgr End'
59
+ flistz = Flistz.create(dir_id: dir_id, level: level, kind: kind,
60
+ repo: repo, path: path_conv, project: project,
61
+ desc: desc, comment: comment,
62
+ atime: atime, ctime: ctime, mtime: mtime,
63
+ start_datetime: @register_time)
64
+ rescue StandardError => e
65
+ p e.class
66
+ p e.message
67
+ pp e.backtrace
30
68
 
31
- flistz = nil
32
- end
33
- else
34
- current_flistz = cur_flistz.first.flistz
35
- hs = {atime: atime, ctime: ctime , mtime: mtime , repo: repo, project: project, desc: desc , comment: comment}
36
- value_hs = hs.reduce({}){ |hsx, item|
37
- if current_flistz[ item[0] ] != item[1]
38
- hsx[ item[0] ] = item[1]
39
- end
40
- hsx
41
- }
42
- current_flistz.update(value_hs) if value_hs.size > 0
69
+ flistz = nil
43
70
  end
44
71
  else
45
- # ignore this case.
72
+ # DBから見つかれば、最初に見つけたファイル情報を更新する
73
+ # current_flistz = cur_flistz.first.flistz
74
+ current_flistz = cur_flistz[0].flistz
75
+ hs = { atime: atime, ctime: ctime, mtime: mtime, repo: repo,
76
+ project: project, desc: desc, comment: comment }
77
+ value_hs = hs.each_with_object({}) do |item, hsx|
78
+ hsx[item[0]] = item[1] if current_flistz[item[0]] != item[1]
79
+ end
80
+ current_flistz.update(value_hs) if value_hs.size.positive?
81
+ flistz = current_flistz
46
82
  end
47
83
 
84
+ # DBに登録・更新したファイル情報をハッシュに格納
48
85
  if flistz
49
86
  @hs_by_path[path] = flistz
50
- @hs_by_id[flistz.id] = flistz
87
+ @hs_by_id[flistz.object_id] = flistz
88
+ @set_of_dir_id.add(dir_id)
51
89
  end
52
90
  flistz
53
91
  end
54
92
 
55
- def post_process( dir_id )
56
- h_ids = Currentflistz.where( dir_id: dir_id).pluck(:org_id)
93
+ # 後処理
94
+ def post_process
95
+ @set_of_dir_id.each do |dir_id|
96
+ post_process_for_dir_id(dir_id)
97
+ end
98
+ end
99
+
100
+ # 後処理(ディレクトリID)
101
+ # DBに登録済データのうち、ハッシュに存在しないデータをInvalidflistzに登録する
102
+ def post_process_for_dir_id(dir_id)
103
+ h_ids = Currentflistz.where(dir_id: dir_id).pluck(:org_id)
57
104
  t_ids = @hs_by_id.keys
58
105
  ids = h_ids - t_ids
59
- if ids.size > 0
60
- ids.each do |idx|
61
- Invalidflistz.create( org_id: idx , end_datetime: @register_time )
62
- end
106
+ return unless ids.size.positive?
107
+
108
+ ids.each do |idx|
109
+ Invalidflistz.create(org_id: idx, end_datetime: @register_time)
63
110
  end
64
111
  end
65
112
  end
data/lib/flist/dbutil.rb CHANGED
@@ -1,5 +1,5 @@
1
- # -*- coding: utf-8 -*-
2
- require 'flist/dbutil/dbmgr'
3
- require 'flist/dbutil/dirzmgr'
4
- require 'flist/dbutil/flistzmgr'
1
+ # frozen_string_literal: true
5
2
 
3
+ require_relative 'dbutil/dbmgr'
4
+ require_relative 'dbutil/dirzmgr'
5
+ require_relative 'dbutil/flistzmgr'
@@ -1,75 +1,76 @@
1
- # -*- coding: utf-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  require 'ykutils/debugutils'
3
4
 
4
5
  module Flist
5
6
  class Flist
7
+ # 詳細ファイルリストクラス
6
8
  class Filelist
7
9
  include Ykutils::DebugUtils
8
10
 
9
- def initialize( encx , skip_dirs = {} , store = nil , dir_id = 0, top_dir = "" , top_level = 0 , mode = "" )
11
+ @fileinfo_class = Struct.new(:atime, :ctime, :mtime)
12
+ @item_class = Struct.new(:level, :kind, :repo, :path, :path_conv, :project,
13
+ :desc, :comment, :atime, :ctime, :mtime)
14
+
15
+ def self.make_instance_of_fileinfo_class(atime, ctime, mtime)
16
+ @fileinfo_class.new(atime, ctime, mtime)
17
+ end
18
+
19
+ def self.make_instance_of_item_class(level = nil, kind = nil, repo = nil, path = nil,
20
+ path_conv = nil, project = nil, desc = nil,
21
+ comment = nil,
22
+ atime = nil, ctime = nil, mtime = nil)
23
+ @item_class.new(level, kind, repo, path, path_conv, project, desc,
24
+ comment, atime, ctime, mtime)
25
+ end
26
+
27
+ def initialize(dbmgr, csvx, encx, skip_dirs = {}, dir_id = 0, top_dir = '',
28
+ top_level = 0, mode = '')
29
+ @dbmgr = dbmgr
30
+ @csvx = csvx
10
31
  @encx = encx
11
- @store = store
12
32
  @skip_dirs = skip_dirs
13
33
 
14
- @hs = {}
15
- @hs[:dot_directory] = @encx.make_regexp( '^(\.|_).+' )
16
- @hs[:node_repository] = @encx.make_regexp( '[^_]_packages' )
17
- @hs[:node_modules] = @encx.make_regexp( 'node_modules|bower_modules' )
18
- @hs[:temp] = @encx.make_regexp( 'te?mp' , Regexp::IGNORECASE )
19
- @hs[:cvs] = @encx.make_regexp( 'cvs' , Regexp::IGNORECASE )
34
+ # パス名判別用正規表現
35
+ @hash = {}
36
+ @hash[:dot_directory] = @encx.make_regexp('^(\.|_).+')
37
+ @hash[:node_repository] = @encx.make_regexp('[^_]_packages')
38
+ @hash[:node_modules] = @encx.make_regexp('node_modules|bower_modules')
39
+ @hash[:temp] = @encx.make_regexp('te?mp', Regexp::IGNORECASE)
40
+ @hash[:cvs] = @encx.make_regexp('cvs', Regexp::IGNORECASE)
20
41
 
42
+ # 設定ファイルの"topdirhs"で定義されたグループに含まれるサブディレクトリを表すID
21
43
  @dir_id = dir_id
22
- debug_utils_init
23
- set_debug(true)
44
+ raise InvalidDirIdError, "invalid @dir_id=#{@dir_id}" unless @dir_id
24
45
 
25
- @@fileinfo_class ||= Struct.new("Fileinfo" , :atime, :ctime, :mtime )
26
- @@item_class ||= Struct.new("Itemfi" , :level , :kind, :repo, :path , :path_conv, :project, :comment , :atime, :ctime, :mtime )
27
- @cur_item = @@item_class.new
46
+ # 全Itemを収めるハッシュ(キーはそのItemを指すパス)
28
47
  @items = {}
48
+ # Itemのうち、ディレクトリを収めるハッシュ(キーはそのItemを指すパス)
29
49
  @dirs = {}
50
+ # Itemのうち、ファイルを収めるハッシュ(キーはそのItemを指すパス)
30
51
  @files = {}
31
52
 
53
+ # このFilelistのトップディレクトリ(トップディレクトリより下位のディレクトリ、ファイルの情報を持つ)
32
54
  @top_dir = top_dir
55
+ # このFilelistのトップディレクトリの階層の深さ
33
56
  @top_level = top_level
34
57
  @mode = mode
35
- @headers_sym = [:level , :kind, :repo, :path , :project, :comment , :atime, :ctime, :mtime]
36
- @items = {}
37
- @headers_s = @headers_sym.map{ |x| x.to_s }
38
58
  end
39
59
 
40
60
  def need_skip?(path_s)
41
61
  ret = nil
42
- if @skip_dirs
43
- ret = @skip_dirs.keys.find { |x| @encx.compare( path_s , x ) }
44
- end
45
- ret != nil
46
- =begin
47
- d_puts "need_skip? path_s=#{path_s}"
48
- ret = false
49
- if @skip_dirs
50
- # p "=@skip_dirs="
51
- # @skip_dirs.each do |x| puts x end
52
- @skip_dirs.each do |k,v|
53
- # p v
54
- puts "# need_skip?"
55
- ret = @encx.compare( path_s , v)
56
- if ret
57
- break
58
- end
59
- end
60
- end
61
- d_puts "need_skip? ret=#{ret}"
62
-
63
- ret
64
- =end
62
+ ret = @skip_dirs.keys.find { |x| @encx.compare(path_s, x) } if @skip_dirs
63
+ ret_value = !ret.nil?
64
+ d_puts "need_skip? path_s=#{path_s}|ret_value=#{ret_value}"
65
+ ret_value
65
66
  end
66
67
 
67
- def time2datetime_utc( time )
68
+ def time2datetime_utc(time)
68
69
  # UTC
69
- datetiem = DateTime.new( time.year, time.month, time.day, time.hour, time.min, time.sec , time.utc_offset )
70
+ DateTime.new(time.year, time.month, time.day, time.hour, time.min, time.sec, time.utc_offset)
70
71
  end
71
72
 
72
- def update_item(kind, level, repo, path, project = 0)
73
+ def update_item(kind, level, repo, path, _project = 0)
73
74
  @items[path].kind = kind
74
75
  @items[path].level = level
75
76
  @items[path].repo = repo
@@ -77,213 +78,263 @@ module Flist
77
78
  @items[path].project = preoject
78
79
  end
79
80
 
81
+ # ハッシュ@itemsにpathをキーに登録する
80
82
  def register_item(kind, level, repo, path, fileinfo, project = 0)
81
- d_puts "register_item"
83
+ d_puts 'register_item'
82
84
  d_puts "path=#{path}"
83
- @cur_item.kind = kind
84
- @cur_item.level = level
85
- @cur_item.repo = repo
86
- @cur_item.path_conv = @encx.convert(path)
87
- @cur_item.path = path
88
- @cur_item.project = project
89
- @cur_item.comment = ""
90
- @cur_item.atime = time2datetime_utc( fileinfo.atime )
91
- @cur_item.ctime = time2datetime_utc( fileinfo.ctime )
92
- @cur_item.mtime = time2datetime_utc( fileinfo.mtime )
93
-
94
- @items[path] = @cur_item
95
- @cur_item = @@item_class.new
85
+ cur_item = self.class.make_instance_of_item_class
86
+ # @cur_item = @@item_class.new
87
+ cur_item.kind = kind
88
+ cur_item.level = level
89
+ cur_item.repo = repo
90
+ cur_item.path_conv = @encx.convert(path)
91
+ cur_item.path = path
92
+ cur_item.project = project
93
+ cur_item.comment = ''
94
+ cur_item.atime = time2datetime_utc(fileinfo.atime)
95
+ cur_item.ctime = time2datetime_utc(fileinfo.ctime)
96
+ cur_item.mtime = time2datetime_utc(fileinfo.mtime)
97
+
98
+ @items[path] = cur_item
96
99
  end
97
100
 
98
101
  def get_config(path)
99
- alist = File.open(path){ |f|
100
- f.readlines.select{ |x| x !~ /^-/ }.collect{ |x|
102
+ alist = File.open(path) do |f|
103
+ f.readlines.grep_v(/^-/).collect do |x|
101
104
  x.chomp.split(/:/)
102
- }
103
- }
105
+ end
106
+ end
104
107
  Hash[*alist.flatten(1)]
105
108
  end
106
109
 
107
110
  def dot_directory?(basename)
108
- d_puts "In dot_directory? path=#{basename}"
109
- puts "# dot_directory?"
110
- ret = @encx.compare(basename , @hs[:dot_directory])
111
+ d_puts "In dot_directory? basename=#{basename}"
112
+ ret = @encx.compare(basename, @hash[:dot_directory])
111
113
  if ret
112
114
  d_puts 'T'
113
115
  else
114
116
  d_puts 'F'
115
117
  end
116
- p ret
118
+ d_puts "In dot_directory? basename=#{basename}|ret=#{ret}"
117
119
  ret
118
120
  end
119
121
 
120
122
  def node_repository?(basename)
121
123
  d_puts "In node_repository? path=#{basename}"
122
- puts "# need_repository? 1"
123
- ret = @encx.compare( basename , @hs[:node_modules] )
124
+ ret = @encx.compare(basename, @hash[:node_modules])
124
125
  unless ret
125
- puts "# need_repository? 2"
126
- ret = @encx.compare(basename , @hs[:node_repository])
126
+ d_puts '# node_repository? 2'
127
+ ret = @encx.compare(basename, @hash[:node_repository])
127
128
  end
128
- p ret
129
+ d_puts "# node_repository? basename=#{basename}|ret=#{ret}"
129
130
  ret
130
131
  end
131
132
 
132
- def repository?(basename , bundle_repo)
133
- d_puts "In repository? basename=#{basename} bundle_repo=#{bundle_repo}"
133
+ def repository?(basename, bundle_repo)
134
134
  ret = dot_directory?(basename) or bundle_repo == basename or node_repository?(basename)
135
- p ret
135
+ d_puts "In repository? basename=#{basename} bundle_repo=#{bundle_repo}|ret=#{ret}"
136
136
  ret
137
137
  end
138
138
 
139
- def get_bundle_repository()
139
+ def bundle_repository
140
140
  abs_path = nil
141
- config_path = ".bundle/config"
141
+ config_path = '.bundle/config'
142
142
  if Dir.exist?(config_path)
143
143
  config = get_config(config_path)
144
- if config
145
- @skip_dirs[bundle_pn.to_s] = @encx.make_regexp( "^#{config}" )
146
- end
144
+ @skip_dirs[bundle_pn.to_s] = @encx.make_regexp("^#{config}") if config
147
145
 
148
- if config["BUNDLE_PATH"]
149
- if Dir.exist?(config["BUNDLE_PATH"])
150
- abs_path = Dir.open(config["BUNDLE_PATH"]){ |d| d.pwd}
151
- end
152
- end
146
+ abs_path = Dir.open(config['BUNDLE_PATH'], &:pwd) if config['BUNDLE_PATH'] && Dir.exist?(config['BUNDLE_PATH'])
153
147
  end
154
148
  abs_path
155
149
  end
156
150
 
157
- def project_directory?(abs_path)
151
+ def project_directory?(_abs_path)
158
152
  false
159
153
  end
160
154
 
161
155
  def ignore_directory?(basename)
162
- puts "# ignore_directory? 1"
163
- ret = @encx.compare(basename , @hs[:temp])
156
+ ret = @encx.compare(basename, @hash[:temp])
164
157
  unless ret
165
- puts "# ignore_directory? 2"
166
- ret = @encx.compare(basename , @hs[:cvs])
158
+ d_puts '# ignore_directory? 2'
159
+ ret = @encx.compare(basename, @hash[:cvs])
167
160
  end
168
- p ret
161
+ d_puts "# ignore_directory? ret=#{ret}"
169
162
  ret
170
163
  end
171
164
 
172
165
  def make_fileinfo(path)
166
+ raise InvalidMakeItemArgsError, "path=#{path}" unless path.instance_of?(String)
167
+
173
168
  atime = File.atime(path)
174
169
  ctime = File.ctime(path)
175
170
  mtime = File.mtime(path)
176
- @@fileinfo_class.new( atime , ctime, mtime )
171
+ self.class.make_instance_of_fileinfo_class(atime, ctime, mtime)
172
+ # @@fileinfo_class.new( atime , ctime, mtime )
173
+ end
174
+
175
+ def repository_files(kind, level, repo, dir, fileinfo, path_s)
176
+ register_item(kind, level, repo, dir, fileinfo, 1)
177
+
178
+ @dirs[path_s] = @encx.make_regexp("^#{path_s}") unless @dirs[path_s]
179
+ @skip_dirs[path_s] = @encx.make_regexp("^#{path_s}") unless @skip_dirs[path_s]
180
+
181
+ [repo, dir]
177
182
  end
178
183
 
179
- def scanx_sub(x , bundle_repo , level, repo )
184
+ def scanx_sub(item, bundle_repo, level, _level_limit, repo)
180
185
  dir = nil
181
- if File.directory?(x)
182
- kind = "D"
186
+ if File.directory?(item)
187
+ kind = 'D'
183
188
  dir = @encx.convert(@cur_dir)
184
- x_str = @encx.convert(x)
185
- path_s = File.expand_path( File.join( dir , x_str ) )
186
- if repository?(x , bundle_repo)
189
+ unless item.instance_of?(String)
190
+ p item
191
+ raise InvalidSacnxSubArgumentError, "item=#{item}"
192
+ end
193
+ x_item = @encx.convert(item)
194
+ path_s = File.expand_path(File.join(dir, x_item))
195
+ if repository?(x_item, bundle_repo)
187
196
  # カレントディレクトリの直下にリポジトリが存在すれば、カレントディレクトリをプロジェクトとして登録する。リポジトリ自体は登録しない(管理外とする)。
188
- register_item(kind, level, x , dir , make_fileinfo(x_str) , 1)
189
-
190
- unless @dirs[path_s]
191
- @dirs[path_s] = @encx.make_regexp( "^#{path_s}" )
192
- end
193
- unless @skip_dirs[path_s]
194
- @skip_dirs[path_s] = @encx.make_regexp( "^#{path_s}" )
197
+ d_puts "REPOSITORY #{dir}|#{path_s}"
198
+ # return nil
199
+ unless x_item.instance_of?(String)
200
+ p x_item
201
+ raise InvalidSacnxSubArgumentError, "x_item=#{x_item}"
195
202
  end
196
-
197
- repo = x
198
- return [repo , dir]
199
- elsif ignore_directory?(x)
200
- @skip_dirs[path_s] = @encx.make_regexp( "^#{path_s}" )
203
+ return repository_files(kind, level, x_item, dir, make_fileinfo(x_item), path_s)
204
+ elsif ignore_directory?(x_item)
205
+ d_puts "SKIP_DIRECTORY #{x_item}|#{path_s}"
206
+ @skip_dirs[path_s] = @encx.make_regexp("^#{path_s}")
201
207
  else
202
- register_item(kind, level, "" , path_s , make_fileinfo(x) , 0)
208
+ d_puts "REGISTER_DIRECTORY #{x_item}|#{path_s}"
209
+ register_item(kind, level, '', path_s, make_fileinfo(x_item), 0)
203
210
  dir = path_s
204
211
  end
205
- else
206
- if @mode == :simple
207
- kind = "F"
212
+ elsif @mode == :simple
213
+ kind = 'F'
208
214
 
209
- dir = @encx.convert(@cur_dir)
210
- x_str = @encx.convert(x)
211
- path_s = File.expand_path( File.join( dir , x_str) )
212
- register_item(kind, level, "" , path_s , make_fileinfo(x_str) , 0)
213
- end
215
+ dir = @encx.convert(@cur_dir)
216
+ x_item = @encx.convert(item)
217
+ path_s = File.expand_path(File.join(dir, x_item))
218
+ register_item(kind, level, '', path_s, make_fileinfo(x_item), 0)
214
219
  end
215
- p "scan_sub"
216
- p repo
217
- p dir
220
+
218
221
  [repo, dir]
219
222
  end
220
223
 
221
- def scanx(abs_dir_path , level)
222
- d_puts "=scanx====#{Dir.pwd}"
223
- d_puts "abs_dir_path=#{abs_dir_path}"
224
- d_puts "abs_dir_path.encoding=#{abs_dir_path.encoding}"
224
+ def project_directory_files
225
+ dir = @encx.convert(@cur_dir)
226
+ x_str = @encx.convert(x)
227
+ d_puts "1 #{dir}"
228
+ register_item(kind, level, '', dir, make_fileinfo(x_str), 1)
229
+ @dirs[dir] = @encx.make_regexp("^#{abs_dir_path}") unless @dirs[dir]
230
+
231
+ # プロジェクトを格納するディレクトリは、今後スキップさせる
232
+ @skip_dirs[dir] = @encx.make_regexp("^#{abs_dir_path}") unless skip_dirs[dir]
233
+ end
234
+
235
+ def non_skip_files(abs_dir_path, level, level_limit)
236
+ next_level = level + 1
237
+ next_level_limit = level_limit - 1
238
+ Dir.chdir(abs_dir_path) do
239
+ d_puts "non_skip_files chdir #{abs_dir_path}"
240
+ repo = nil
241
+ dirs = []
242
+ @cur_dir = Dir.getwd
243
+ bundle_repo = bundle_repository
244
+
245
+ if next_level_limit <= 0
246
+ Dir.foreach('.') do |x|
247
+ next if ['.', '..'].include?(x)
248
+
249
+ # d_puts "scanx x=#{x}"
250
+ # d_puts "=========#{x.encoding}"
251
+ # d_puts "@cur_dir=#{@cur_dir}"
252
+ x_str = @encx.convert(x)
253
+ repo, dir = scanx_sub(x_str, bundle_repo, next_level, next_level_limit, repo)
254
+ dirs << dir if dir
255
+ end
256
+ unless repo.nil?
257
+ dirs.each do |d|
258
+ scanx(d, next_level, next_level_limit)
259
+ end
260
+ end
261
+ end
262
+ end
263
+ end
264
+
265
+ def scanx(abs_dir_path, level, level_limit)
266
+ d_puts "######### scanx abs_dir_path=#{abs_dir_path} level=#{level} level_limit=#{level_limit}"
267
+ next_level = level + 1
268
+ next_level_limit = level_limit - 1
269
+ # d_puts "=scanx====#{Dir.pwd}"
270
+ # d_puts "abs_dir_path=#{abs_dir_path}"
271
+ # d_puts "abs_dir_path.encoding=#{abs_dir_path.encoding}"
225
272
 
226
273
  # プロジェクトを格納するディレクトリであれば、
227
274
  # (TO DO) project_directory?を実装する
228
275
  if project_directory?(abs_dir_path)
229
- dir = @encx.convert(@cur_dir)
230
- x_str = @encx.convert(x)
231
- d_puts "1 #{dir}"
232
- register_item(kind, level, "" , dir , make_fileinfo(x_str) , 1)
233
- unless @dirs[dir]
234
- @dirs[dir] = @encx.make_regexp( "^#{abs_dir_path}" )
235
- end
236
-
237
- # プロジェクトを格納するディレクトリは、今後スキップさせる
238
- unless skip_dirs[dir]
239
- @skip_dirs[dir] = @encx.make_regexp( "^#{abs_dir_path}" )
240
- end
276
+ project_directory_files
241
277
  else
278
+ return if next_level_limit <= 0
279
+
242
280
  # スッキプすべきとして登録されたディレクトリまたは、そのサブディレクトリであれば、スキップする
243
- unless need_skip?(abs_dir_path)
244
- Dir.chdir(abs_dir_path) do
245
- repo = nil
246
- dirs = []
247
- kind = nil
248
- @cur_dir = Dir.getwd
249
- bundle_repo = get_bundle_repository( )
250
-
251
- Dir.foreach('.') do |x|
252
- next if x == '.' or x == '..'
253
- d_puts "scanx x=#{x}"
254
- d_puts "=========#{x.encoding}"
255
- d_puts "@cur_dir=#{@cur_dir}"
256
- x_str = @encx.convert(x)
257
- repo , dir = scanx_sub(x_str , bundle_repo , level, repo )
258
- dirs << dir if dir
259
- end
260
- if repo != nil
261
- dirs.each do |d|
262
- scanx(d , level + 1)
263
- end
264
- end
265
- end
266
- end
281
+ non_skip_files(abs_dir_path, next_level, next_level_limit) unless need_skip?(abs_dir_path)
267
282
  end
268
283
  end
269
284
 
270
285
  def scan
271
- d_puts("In scan")
286
+ d_puts('In scan')
272
287
  # 調査対象のトップディレクトリ
273
288
  # @top_dirはディレクトリ名(フルパスではない)である
274
- Dir.chdir(@top_dir){
289
+ Dir.chdir(@top_dir) do
275
290
  @topd_dir = Dir.getwd
276
- }
291
+ end
277
292
  # 調査対象のトップディレクトリが絶対パス、相対パスで指定された時を考慮して、
278
293
  # トップディレクトリのbasename部分をとりだして調べる。
279
294
  #
280
295
  # 無視すべきディレクトリ名パターンにマッチすれば、@top_dir以下を調べない
281
- unless ignore_directory?( File.basename(@top_dir))
282
- Dir.chdir( File.join(@top_dir , "..") ){
283
- @cur_dir = Dir.getwd
296
+ return if ignore_directory?(File.basename(@top_dir))
297
+
298
+ Dir.chdir(File.join(@top_dir, '..')) do
299
+ @cur_dir = Dir.getwd
300
+ end
301
+ d_puts "scan @cur_dir=#{@cur_dir} call scanx @top_dir=#{@top_dir}"
302
+ next_level = 0
303
+ next_level_limit = 2
304
+ scanx(@top_dir, next_level, next_level_limit)
305
+
306
+ d_puts '########## scan End'
307
+ end
308
+
309
+ def output
310
+ d_puts 'In output'
311
+
312
+ @items.each do |_k, v|
313
+ d_puts "v.path.encoding=#{v.path.encoding}"
314
+
315
+ if @csv
316
+ @csvx.csv << [@dir_id, v.level, v.kind, v.repo, v.path, v.project, '', v.comment, v.atime, v.ctime,
317
+ v.mtime]
318
+ end
319
+ d_puts '#### Flielist'
320
+ d_puts "dir_id=#{@dir_id}"
321
+ d_puts "level=#{v.level}"
322
+ d_puts "kind=#{v.kind}"
323
+ d_puts "repo=#{v.repo}"
324
+ d_puts "path=#{v.path_conv}"
325
+ d_puts "project=#{v.project}"
326
+ d_puts "desc=#{v.desc}"
327
+ d_puts "comment=#{v.comment}"
328
+ d_puts "atime=#{v.atime}"
329
+ d_puts "ctime=#{v.ctime}"
330
+ d_puts "mtime=#{v.mtime}"
331
+ d_puts '#### Flilelist End'
332
+ raise InvalidDirIdError, "invalid @dir_id=#{@dir_id}" unless @dir_id
333
+ raise InvalidRepoError, "invalid v.repo=#{v.repo}" unless v.repo
334
+ raise InvalidCommitError, "invalid v.comment=#{v.comment}" unless v.comment
284
335
 
285
- }
286
- scanx(@top_dir , 0)
336
+ @dbmgr.flistz_add(@dir_id, v.level, v.kind, v.repo, v.path, v.project,
337
+ v.desc, v.comment, v.atime, v.ctime, v.mtime)
287
338
  end
288
339
  end
289
340
  end