flist 0.1.30

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 74954e35dbe3808fe8a56740b5ac175d23352dc6
4
+ data.tar.gz: 8304a1b252e2bddb3e0c8da9cc725dc62fce8c32
5
+ SHA512:
6
+ metadata.gz: 21df6f570883e78784888d41f5018d7dfad5f6a1f5d64cca97cb1d5adc5594e4faf82d7934eb0f3ee0a7c21afa99d6ba4e68d9464eeccd5d6dee4072d405000b
7
+ data.tar.gz: e86f66c766f38f3517cc6d4fb4ede4f71b334e8de185b5a416376e8ae2d7df06b0d4789c9fffdfe6beb1e036774d8fcc9aa3f6df7c1bbf3f853db558e77ba13e
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in flist.gemspec
4
+ gemspec
5
+
6
+
@@ -0,0 +1,39 @@
1
+ # Flist
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/flist`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'flist'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install flist
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec flist` to use the code located in this directory, ignoring other installed copies of this gem.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/flist/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "flist"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ require 'arxutils'
3
+ require "flist"
4
+
5
+ dbconfig = Arxutils::Dbutil::DBCONFIG_MYSQL
6
+ dbconfig = Arxutils::Dbutil::DBCONFIG_SQLITE3
7
+
8
+ csv_fname = nil
9
+ csv_fname = ARGV[0] if ARGV.size > 0
10
+ csvin_fname = nil
11
+ csvin_fname = ARGV[1] if ARGV.size > 1
12
+
13
+ hs = {
14
+ "db_dir" => Arxutils::Dbutil::DB_DIR,
15
+ "migrate_dir" => Arxutils::Dbutil::MIGRATE_DIR,
16
+ "config_dir" => Arxutils::Dbutil::CONFIG_DIR,
17
+ "dbconfig" => dbconfig,
18
+ "log_fname" => Arxutils::Dbutil::DATABASELOG,
19
+ "csv_fname" => csv_fname ,
20
+ "csvin_fname" => csvin_fname,
21
+ }
22
+
23
+
24
+ fl = Flist::Flist.new(
25
+ :db,
26
+ hs
27
+ )
28
+ fl.list_a
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ require 'arxutils'
4
+ require 'flist'
5
+
6
+ data_ary = [
7
+ {
8
+ :flist => %W!base!,
9
+ :classname => "Dirz",
10
+ :classname_downcase => "dirz",
11
+ :items => [
12
+ ["path" , "string", "false"],
13
+ ["desc" , "string", "true"],
14
+ ],
15
+ :plural => "dirzs"
16
+ },
17
+
18
+ {
19
+ :flist => %W!base invalid current!,
20
+ :classname => "Flistz",
21
+ :classname_downcase => "flistz",
22
+
23
+ :items => [
24
+ ["dir_id" , "integer", "false"],
25
+ ["level" , "integer", "false"],
26
+ ["kind" , "string", "false"],
27
+ ["repo" , "string", "false"],
28
+ ["path" , "string", "false"],
29
+ ["project" , "integer", "false"],
30
+ ["desc" , "string", "true"],
31
+ ["comment" , "string", "true"],
32
+ ["atime" , "datetime", "false"],
33
+ ["ctime" , "datetime", "false"],
34
+ ["mtime" , "datetime", "false"],
35
+ ],
36
+ :plural => "flistzs"
37
+ },
38
+ ]
39
+
40
+ forced = true
41
+ dbconfig = Arxutils::DBCONFIG_SQLITE3
42
+ if ARGV[0] == "-mysql"
43
+ dbconfig = Arxutils::DBCONFIG_MYSQL
44
+ end
45
+ idx = 1
46
+ Arxutils::Migrate.migrate(
47
+ data_ary ,
48
+ idx,
49
+ dbconfig ,
50
+ forced
51
+ )
52
+
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'flist/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "flist"
8
+ spec.version = Flist::VERSION
9
+ spec.authors = ["yasuo kominami"]
10
+ spec.email = ["ykominami@gmail.com"]
11
+
12
+ spec.summary = %q{get flie listing in local machine.}
13
+ spec.description = %q{get flie listing in local machine.}
14
+ spec.homepage = ""
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ if spec.respond_to?(:metadata)
22
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
23
+ end
24
+ spec.add_dependency "rake", "~> 10.0"
25
+
26
+ spec.add_runtime_dependency "activerecord"
27
+ spec.add_runtime_dependency "sqlite3"
28
+ spec.add_runtime_dependency "arxutils" , "~> 0.1.0"
29
+ spec.add_runtime_dependency "ykutils" , "~> 0.1.0"
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.9"
32
+ spec.add_development_dependency "rspec"
33
+ end
@@ -0,0 +1,11 @@
1
+ #! -*- encoding : UTF-8 -*-
2
+
3
+ require "flist/version"
4
+
5
+ require 'flist/flist'
6
+ require 'flist/flist/store'
7
+ require 'flist/flist/filelist'
8
+ require 'flist/dbutil'
9
+
10
+ module Flist
11
+ end
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'flist/dbutil/dbmgr'
3
+ require 'flist/dbutil/dirzmgr'
4
+ require 'flist/dbutil/flistzmgr'
5
+
@@ -0,0 +1,39 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'active_record'
3
+ require 'forwardable'
4
+ require 'encx'
5
+ require 'flist/dbutil/flistzmgr'
6
+ require 'flist/dbutil/dirzmgr'
7
+
8
+ module Flist
9
+ module Dbutil
10
+ class Flistz < ActiveRecord::Base
11
+ end
12
+
13
+ class Dirz < ActiveRecord::Base
14
+ end
15
+
16
+ class Invalidflistz < ActiveRecord::Base
17
+ end
18
+
19
+ class Currentflistz < ActiveRecord::Base
20
+ belongs_to :flistz , foreign_key: 'org_id'
21
+ end
22
+
23
+ class DbMgr
24
+ extend Forwardable
25
+
26
+ def_delegators( :@flistzmgr , :post_process , :fl)
27
+ def_delegator( :@dirzmgr , :add , :dirz_add )
28
+ def_delegator( :@flistzmgr , :add , :flistz_add )
29
+ def_delegator( :@flistzmgr , :post_process , :flistz_post_process )
30
+
31
+ def initialize( register_time )
32
+ @db_encoding = Encoding::UTF_8
33
+ @encx = Encx::Encx.init(@db_encoding)
34
+ @flistzmgr = FlistzMgr.new( @encx, @db_encoding, register_time )
35
+ @dirzmgr = DirzMgr.new( @encx, @db_encoding, register_time )
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'pp'
3
+ require 'flist/dbutil/dbmgr'
4
+
5
+ module Flist
6
+ module Dbutil
7
+ class DirzMgr
8
+ def initialize(encx , db_encoding, register_time)
9
+ @encx = encx
10
+ @db_encoding = db_encoding
11
+ @register_time = register_time
12
+ end
13
+
14
+ def add( path )
15
+ path_conv = @encx.convert( path , @db_encoding )
16
+ ary = Dirz.where( path: path_conv )
17
+ if ary.size == 0
18
+ begin
19
+ dirz = Dirz.create( path: path_conv , start_datetime: @register_time )
20
+ rescue => ex
21
+ p ex.class
22
+ p ex.message
23
+ pp ex.backtrace
24
+
25
+ dirz = nil
26
+ end
27
+ else
28
+ dirz = ary.first
29
+ end
30
+ dirz
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,67 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'pp'
4
+ require 'flist/dbutil/dbmgr'
5
+
6
+ module Flist
7
+ module Dbutil
8
+ class FlistzMgr
9
+ def initialize(encx , db_encoding , register_time)
10
+ @encx = encx
11
+ @db_encoding = db_encoding
12
+ @register_time = register_time
13
+ @hs_by_path = {}
14
+ @hs_by_id = {}
15
+ end
16
+
17
+ def add( dir_id , level, kind, repo, path , project, desc, comment, atime, ctime, mtime )
18
+ flistz = @hs_by_path[path]
19
+ unless flistz
20
+
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
30
+
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
43
+ end
44
+ else
45
+ # ignore this case.
46
+ end
47
+
48
+ if flistz
49
+ @hs_by_path[path] = flistz
50
+ @hs_by_id[flistz.id] = flistz
51
+ end
52
+ flistz
53
+ end
54
+
55
+ def post_process( dir_id )
56
+ h_ids = Currentflistz.where( dir_id: dir_id).pluck(:org_id)
57
+ t_ids = @hs_by_id.keys
58
+ 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
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,185 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'flist/flist/filelist'
4
+ require 'encx'
5
+ require 'ykutils/debugutils'
6
+
7
+ require 'date'
8
+
9
+ module Flist
10
+ class Flist
11
+ attr_accessor :encx
12
+
13
+ extend Forwardable
14
+
15
+ include Ykutils::DebugUtils
16
+
17
+ def_delegators( :@store, :dirz_add )
18
+ def_delegators( :@store, :output )
19
+
20
+ def determine_filesystem(fname)
21
+ [
22
+ {
23
+ :home => "/home",
24
+ :c => "/c",
25
+ :v => "/v",
26
+ },
27
+
28
+ {
29
+ :home => File.expand_path(ENV['HOME']),
30
+ :c => "C:",
31
+ :v => "V:",
32
+ },
33
+ ].find{|x|
34
+ File.exist?( File.expand_path( File.join( File.expand_path(x[:home]) , fname ) ) )
35
+ }
36
+
37
+ end
38
+
39
+ def initialize( kind, hs )
40
+ @topx_keys = [:kind, :level, :all]
41
+ opts={}
42
+ argv=[]
43
+ debug = false
44
+
45
+ yamlfname = "env-a.yaml"
46
+ @dir = determine_filesystem( yamlfname )
47
+ fname = File.expand_path( File.join( @dir[:home] , yamlfname ) )
48
+ contents = File.open( fname ).read
49
+ erb = ERB.new(contents)
50
+ yaml = YAML.load( erb.result(binding) )
51
+
52
+ Encx::Encx.init('UTF-8')
53
+ @encx = Encx::Encx.encx
54
+
55
+ @store = Store.new( kind, hs )
56
+
57
+ @topdirhs = yaml["flist"]["topdirhs"]
58
+ @logdir = yaml["flist"]["logdir"]
59
+
60
+ @tops = yaml["flist"]["tops"]
61
+ @topx = {}
62
+ @topx[:all] = []
63
+ @topx_keys.map do |x| @topx[x] ||= {} end
64
+
65
+ @@item_class ||= Struct.new("Item" , :level , :kind, :re , :path )
66
+
67
+ init_topx(yaml)
68
+
69
+ init_skip_dirs(yaml)
70
+
71
+ regist_dirz
72
+ end
73
+
74
+ def init_skip_dirs(yaml)
75
+ @skip_dirs = {}
76
+ skip_dirs_array = yaml["flist"]["skip_dirs_array"]
77
+ skip_dirs_array.each do |x|
78
+ x_str = File.expand_path(x)
79
+ re_esc = Regexp.escape(x_str)
80
+ @skip_dirs[x] = @encx.make_regexp( "^#{re_esc}" )
81
+ end
82
+ end
83
+
84
+ def init_topx( yaml )
85
+ @tops = yaml["flist"]["tops"]
86
+ @tops.each do |k,v|
87
+ v.each do |path|
88
+ ary = path.split('/')
89
+ if ary[0] == ""
90
+ ary.shift
91
+ end
92
+ level = ary.size
93
+ re = @encx.make_regexp( "^#{path}" )
94
+ itemx = @@item_class.new( level , k , re , path )
95
+ @topx[:kind][k] ||= []
96
+ @topx[:kind][k] << itemx
97
+ @topx[:level][level] ||= []
98
+ @topx[:level][level] << itemx
99
+ @topx[:all] ||= []
100
+ @topx[:all] << itemx
101
+ end
102
+ end
103
+ end
104
+
105
+ def regist_dirz
106
+ @topdirhs.each do |k,v|
107
+ v.each do |k0,v0|
108
+ v0.each do |k1,v1|
109
+ dir = File.expand_path( @encx.convert(k1) )
110
+ x_str = @encx.convert(v1['fname'])
111
+ path = File.expand_path( File.join( dir , x_str ) )
112
+ dir_id = v1["dir_id"]
113
+ dirz = dirz_add( path )
114
+ end
115
+ end
116
+ end
117
+ end
118
+
119
+ def listup_x( name )
120
+ @topdirhs[name].each do |k0,v0|
121
+ k0_str = @encx.convert(k0)
122
+ v0.each do |k,v|
123
+ k_str = @encx.convert(k)
124
+ fname = v["fname"]
125
+ dir = @encx.convert(@logdir)
126
+ x_str = @encx.convert(fname)
127
+ csvpath = File.expand_path( File.join( dir , x_str ) )
128
+ dir_id = v["dir_id"]
129
+ top_path = File.expand_path( File.join( k0_str , k_str ) )
130
+ flist = Filelist.new( @encx, @skip_dirs, dir_id, top_path , 0 , name.to_sym )
131
+ flist.scan
132
+ flist.output
133
+ end
134
+ end
135
+ end
136
+
137
+ def listup_repo
138
+ listup_x( "repo" )
139
+ end
140
+
141
+ def listup_simple
142
+ listup_x( "simple" )
143
+ end
144
+
145
+ def lx
146
+ Flistz.where( dir_id: 1 ).select(:id)
147
+ end
148
+
149
+ def get_directory_list(dir_path, level)
150
+ ary = []
151
+ Dir.chdir(dir_path)
152
+ if level > 0
153
+ level -= 1
154
+ Dir.glob("*").each do |pa|
155
+ ary += get_directory_list(pa , level) if File.directory?(pa)
156
+ end
157
+ else
158
+ ary << Dir.pwd
159
+ end
160
+ Dir.chdir("..")
161
+ ary
162
+ end
163
+
164
+ def listx()
165
+ @topx[:kind].map do |x|
166
+ x[1].map do |item|
167
+ get_directory_list( item.path , x[0] )
168
+ end
169
+ end.flatten
170
+ end
171
+
172
+ def list_a
173
+ listx.each do |x|
174
+ top_path = @encx.convert(x)
175
+ # top_path = x
176
+ dirz = @store.dirz_add( top_path )
177
+ ary = top_path.split('/')
178
+ ary.shift
179
+ level = ary.size
180
+ flist = Filelist.new( @encx, @skip_dirs, @store , dirz.id, top_path , level )
181
+ flist.scanx( top_path , level )
182
+ end
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,291 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'ykutils/debugutils'
3
+
4
+ module Flist
5
+ class Flist
6
+ class Filelist
7
+ include Ykutils::DebugUtils
8
+
9
+ def initialize( encx , skip_dirs = {} , store = nil , dir_id = 0, top_dir = "" , top_level = 0 , mode = "" )
10
+ @encx = encx
11
+ @store = store
12
+ @skip_dirs = skip_dirs
13
+
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 )
20
+
21
+ @dir_id = dir_id
22
+ debug_utils_init
23
+ set_debug(true)
24
+
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
28
+ @items = {}
29
+ @dirs = {}
30
+ @files = {}
31
+
32
+ @top_dir = top_dir
33
+ @top_level = top_level
34
+ @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
+ end
39
+
40
+ def need_skip?(path_s)
41
+ 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
65
+ end
66
+
67
+ def time2datetime_utc( time )
68
+ # UTC
69
+ datetiem = DateTime.new( time.year, time.month, time.day, time.hour, time.min, time.sec , time.utc_offset )
70
+ end
71
+
72
+ def update_item(kind, level, repo, path, project = 0)
73
+ @items[path].kind = kind
74
+ @items[path].level = level
75
+ @items[path].repo = repo
76
+ @items[path].path = path
77
+ @items[path].project = preoject
78
+ end
79
+
80
+ def register_item(kind, level, repo, path, fileinfo, project = 0)
81
+ d_puts "register_item"
82
+ 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
96
+ end
97
+
98
+ def get_config(path)
99
+ alist = File.open(path){ |f|
100
+ f.readlines.select{ |x| x !~ /^-/ }.collect{ |x|
101
+ x.chomp.split(/:/)
102
+ }
103
+ }
104
+ Hash[*alist.flatten(1)]
105
+ end
106
+
107
+ 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
+ if ret
112
+ d_puts 'T'
113
+ else
114
+ d_puts 'F'
115
+ end
116
+ p ret
117
+ ret
118
+ end
119
+
120
+ def node_repository?(basename)
121
+ d_puts "In node_repository? path=#{basename}"
122
+ puts "# need_repository? 1"
123
+ ret = @encx.compare( basename , @hs[:node_modules] )
124
+ unless ret
125
+ puts "# need_repository? 2"
126
+ ret = @encx.compare(basename , @hs[:node_repository])
127
+ end
128
+ p ret
129
+ ret
130
+ end
131
+
132
+ def repository?(basename , bundle_repo)
133
+ d_puts "In repository? basename=#{basename} bundle_repo=#{bundle_repo}"
134
+ ret = dot_directory?(basename) or bundle_repo == basename or node_repository?(basename)
135
+ p ret
136
+ ret
137
+ end
138
+
139
+ def get_bundle_repository()
140
+ abs_path = nil
141
+ config_path = ".bundle/config"
142
+ if Dir.exist?(config_path)
143
+ config = get_config(config_path)
144
+ if config
145
+ @skip_dirs[bundle_pn.to_s] = @encx.make_regexp( "^#{config}" )
146
+ end
147
+
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
153
+ end
154
+ abs_path
155
+ end
156
+
157
+ def project_directory?(abs_path)
158
+ false
159
+ end
160
+
161
+ def ignore_directory?(basename)
162
+ puts "# ignore_directory? 1"
163
+ ret = @encx.compare(basename , @hs[:temp])
164
+ unless ret
165
+ puts "# ignore_directory? 2"
166
+ ret = @encx.compare(basename , @hs[:cvs])
167
+ end
168
+ p ret
169
+ ret
170
+ end
171
+
172
+ def make_fileinfo(path)
173
+ atime = File.atime(path)
174
+ ctime = File.ctime(path)
175
+ mtime = File.mtime(path)
176
+ @@fileinfo_class.new( atime , ctime, mtime )
177
+ end
178
+
179
+ def scanx_sub(x , bundle_repo , level, repo )
180
+ dir = nil
181
+ if File.directory?(x)
182
+ kind = "D"
183
+ 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)
187
+ # カレントディレクトリの直下にリポジトリが存在すれば、カレントディレクトリをプロジェクトとして登録する。リポジトリ自体は登録しない(管理外とする)。
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}" )
195
+ end
196
+
197
+ repo = x
198
+ return [repo , dir]
199
+ elsif ignore_directory?(x)
200
+ @skip_dirs[path_s] = @encx.make_regexp( "^#{path_s}" )
201
+ else
202
+ register_item(kind, level, "" , path_s , make_fileinfo(x) , 0)
203
+ dir = path_s
204
+ end
205
+ else
206
+ if @mode == :simple
207
+ kind = "F"
208
+
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
214
+ end
215
+ p "scan_sub"
216
+ p repo
217
+ p dir
218
+ [repo, dir]
219
+ end
220
+
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}"
225
+
226
+ # プロジェクトを格納するディレクトリであれば、
227
+ # (TO DO) project_directory?を実装する
228
+ 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
241
+ else
242
+ # スッキプすべきとして登録されたディレクトリまたは、そのサブディレクトリであれば、スキップする
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
267
+ end
268
+ end
269
+
270
+ def scan
271
+ d_puts("In scan")
272
+ # 調査対象のトップディレクトリ
273
+ # @top_dirはディレクトリ名(フルパスではない)である
274
+ Dir.chdir(@top_dir){
275
+ @topd_dir = Dir.getwd
276
+ }
277
+ # 調査対象のトップディレクトリが絶対パス、相対パスで指定された時を考慮して、
278
+ # トップディレクトリのbasename部分をとりだして調べる。
279
+ #
280
+ # 無視すべきディレクトリ名パターンにマッチすれば、@top_dir以下を調べない
281
+ unless ignore_directory?( File.basename(@top_dir))
282
+ Dir.chdir( File.join(@top_dir , "..") ){
283
+ @cur_dir = Dir.getwd
284
+
285
+ }
286
+ scanx(@top_dir , 0)
287
+ end
288
+ end
289
+ end
290
+ end
291
+ end
@@ -0,0 +1,79 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'forwardable'
3
+ require 'csv'
4
+
5
+ require 'arxutils'
6
+ require 'flist/dbutil/dbmgr'
7
+ require 'ykutils/debugutils'
8
+
9
+ module Flist
10
+ class Flist
11
+ class Store
12
+ extend Forwardable
13
+
14
+ include Ykutils::DebugUtils
15
+
16
+ def_delegators( :@dbmgr, :dirz_add )
17
+
18
+ def initialize( kind, hs )
19
+
20
+ debug=false
21
+
22
+ @dbmgr = Arxutils::Store.init(kind , hs ){ | register_time |
23
+ Dbutil::DbMgr.new( register_time )
24
+ }
25
+
26
+ @csv_fname = hs["csv_fname"]
27
+ @csvin_fname = hs["csvin_fname"]
28
+
29
+ debug_utils_init
30
+ d_puts("csv_fname=#{@csv_fname}")
31
+
32
+ if @csv_fname
33
+ @csv = CSV.open( @csv_fname , "w" ,
34
+ { :encoding => 'UTF-8',
35
+ :headers => @headers_s,
36
+ :force_quotes => true,
37
+ :write_headers => true,
38
+
39
+ } )
40
+ end
41
+
42
+ if @csvin_fname
43
+ @csvin = CSV.open( @csvin_fname , "r" ,
44
+ { :encoding => 'UTF-8',
45
+ :headers => @headers_s,
46
+ } )
47
+ end
48
+
49
+ d_puts "default_external=#{Encoding.default_external}"
50
+ Encoding.default_external=Encoding::UTF_8
51
+ d_puts "default_external=#{Encoding.default_external}"
52
+ d_puts "default_internal=#{Encoding.default_internal}"
53
+ Encoding.default_internal=Encoding::UTF_8
54
+ d_puts "default_internal=#{Encoding.default_internal}"
55
+ end
56
+
57
+ def finish
58
+ @csv.close if @csv
59
+ @csv_in.close if @csv_in
60
+ end
61
+
62
+ def post_process
63
+ @dbmgr.flistz_post_process(@dir_id) if @dbmgr
64
+ end
65
+
66
+ def output(items , dir_id)
67
+ d_puts "In output"
68
+
69
+ items.each do |k,v|
70
+ d_puts "v.path.encoding=#{v.path.encoding}"
71
+
72
+ @csv << [v.level, v.kind, v.repo, v.path, v.project, v.comment, v.atime, v.ctime, v.mtime] if @csv
73
+ @dbmgr.flistz_add( dir_id, v.level, v.kind, v.repo, v.path, v.project, "", v.comment, v.atime, v.ctime, v.mtime) if @dbmgr
74
+
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,3 @@
1
+ module Flist
2
+ VERSION = "0.1.30"
3
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flist
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.30
5
+ platform: ruby
6
+ authors:
7
+ - yasuo kominami
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: arxutils
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: ykutils
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.1.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.9'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.9'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: get flie listing in local machine.
112
+ email:
113
+ - ykominami@gmail.com
114
+ executables:
115
+ - flist
116
+ - makemigrate
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".gitignore"
121
+ - ".rspec"
122
+ - ".travis.yml"
123
+ - Gemfile
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - exe/flist
129
+ - exe/makemigrate
130
+ - flist.gemspec
131
+ - lib/flist.rb
132
+ - lib/flist/dbutil.rb
133
+ - lib/flist/dbutil/dbmgr.rb
134
+ - lib/flist/dbutil/dirzmgr.rb
135
+ - lib/flist/dbutil/flistzmgr.rb
136
+ - lib/flist/flist.rb
137
+ - lib/flist/flist/filelist.rb
138
+ - lib/flist/flist/store.rb
139
+ - lib/flist/version.rb
140
+ homepage: ''
141
+ licenses: []
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.4.8
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: get flie listing in local machine.
163
+ test_files: []
164
+ has_rdoc: