lg_pod_plugin 1.0.4 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/lib/git/author.rb +14 -0
  3. data/lib/git/base/factory.rb +101 -0
  4. data/lib/git/base.rb +670 -0
  5. data/lib/git/branch.rb +126 -0
  6. data/lib/git/branches.rb +71 -0
  7. data/lib/git/config.rb +22 -0
  8. data/lib/git/diff.rb +155 -0
  9. data/lib/git/encoding_utils.rb +33 -0
  10. data/lib/git/escaped_path.rb +77 -0
  11. data/lib/git/index.rb +5 -0
  12. data/lib/git/lib.rb +1215 -0
  13. data/lib/git/log.rb +135 -0
  14. data/lib/git/object.rb +312 -0
  15. data/lib/git/path.rb +31 -0
  16. data/lib/git/remote.rb +36 -0
  17. data/lib/git/repository.rb +6 -0
  18. data/lib/git/stash.rb +27 -0
  19. data/lib/git/stashes.rb +55 -0
  20. data/lib/git/status.rb +199 -0
  21. data/lib/git/url.rb +127 -0
  22. data/lib/git/version.rb +5 -0
  23. data/lib/git/working_directory.rb +4 -0
  24. data/lib/git/worktree.rb +38 -0
  25. data/lib/git/worktrees.rb +47 -0
  26. data/lib/git.rb +326 -0
  27. data/lib/lg_pod_plugin/database.rb +104 -104
  28. data/lib/lg_pod_plugin/{download.rb → downloader.rb} +1 -1
  29. data/lib/lg_pod_plugin/file_path.rb +1 -1
  30. data/lib/lg_pod_plugin/git_util.rb +154 -50
  31. data/lib/lg_pod_plugin/install.rb +27 -21
  32. data/lib/lg_pod_plugin/l_cache.rb +13 -14
  33. data/lib/lg_pod_plugin/l_util.rb +39 -0
  34. data/lib/lg_pod_plugin/request.rb +9 -10
  35. data/lib/lg_pod_plugin/version.rb +1 -1
  36. data/lib/lg_pod_plugin.rb +1 -3
  37. data/lib/rchardet/big5freq.rb +927 -0
  38. data/lib/rchardet/big5prober.rb +42 -0
  39. data/lib/rchardet/chardistribution.rb +250 -0
  40. data/lib/rchardet/charsetgroupprober.rb +110 -0
  41. data/lib/rchardet/charsetprober.rb +70 -0
  42. data/lib/rchardet/codingstatemachine.rb +67 -0
  43. data/lib/rchardet/constants.rb +42 -0
  44. data/lib/rchardet/escprober.rb +90 -0
  45. data/lib/rchardet/escsm.rb +245 -0
  46. data/lib/rchardet/eucjpprober.rb +88 -0
  47. data/lib/rchardet/euckrfreq.rb +597 -0
  48. data/lib/rchardet/euckrprober.rb +42 -0
  49. data/lib/rchardet/euctwfreq.rb +431 -0
  50. data/lib/rchardet/euctwprober.rb +42 -0
  51. data/lib/rchardet/gb18030freq.rb +474 -0
  52. data/lib/rchardet/gb18030prober.rb +42 -0
  53. data/lib/rchardet/hebrewprober.rb +289 -0
  54. data/lib/rchardet/jisfreq.rb +571 -0
  55. data/lib/rchardet/jpcntx.rb +229 -0
  56. data/lib/rchardet/langbulgarianmodel.rb +229 -0
  57. data/lib/rchardet/langcyrillicmodel.rb +330 -0
  58. data/lib/rchardet/langgreekmodel.rb +227 -0
  59. data/lib/rchardet/langhebrewmodel.rb +202 -0
  60. data/lib/rchardet/langhungarianmodel.rb +226 -0
  61. data/lib/rchardet/langthaimodel.rb +201 -0
  62. data/lib/rchardet/latin1prober.rb +147 -0
  63. data/lib/rchardet/mbcharsetprober.rb +89 -0
  64. data/lib/rchardet/mbcsgroupprober.rb +47 -0
  65. data/lib/rchardet/mbcssm.rb +542 -0
  66. data/lib/rchardet/sbcharsetprober.rb +122 -0
  67. data/lib/rchardet/sbcsgroupprober.rb +58 -0
  68. data/lib/rchardet/sjisprober.rb +88 -0
  69. data/lib/rchardet/universaldetector.rb +179 -0
  70. data/lib/rchardet/utf8prober.rb +87 -0
  71. data/lib/rchardet/version.rb +3 -0
  72. data/lib/rchardet.rb +67 -0
  73. data/lib/zip/central_directory.rb +212 -0
  74. data/lib/zip/compressor.rb +9 -0
  75. data/lib/zip/constants.rb +115 -0
  76. data/lib/zip/crypto/decrypted_io.rb +40 -0
  77. data/lib/zip/crypto/encryption.rb +11 -0
  78. data/lib/zip/crypto/null_encryption.rb +43 -0
  79. data/lib/zip/crypto/traditional_encryption.rb +99 -0
  80. data/lib/zip/decompressor.rb +31 -0
  81. data/lib/zip/deflater.rb +34 -0
  82. data/lib/zip/dos_time.rb +53 -0
  83. data/lib/zip/entry.rb +719 -0
  84. data/lib/zip/entry_set.rb +88 -0
  85. data/lib/zip/errors.rb +19 -0
  86. data/lib/zip/extra_field/generic.rb +44 -0
  87. data/lib/zip/extra_field/ntfs.rb +94 -0
  88. data/lib/zip/extra_field/old_unix.rb +46 -0
  89. data/lib/zip/extra_field/universal_time.rb +77 -0
  90. data/lib/zip/extra_field/unix.rb +39 -0
  91. data/lib/zip/extra_field/zip64.rb +70 -0
  92. data/lib/zip/extra_field/zip64_placeholder.rb +15 -0
  93. data/lib/zip/extra_field.rb +103 -0
  94. data/lib/zip/file.rb +468 -0
  95. data/lib/zip/filesystem.rb +643 -0
  96. data/lib/zip/inflater.rb +54 -0
  97. data/lib/zip/input_stream.rb +180 -0
  98. data/lib/zip/ioextras/abstract_input_stream.rb +122 -0
  99. data/lib/zip/ioextras/abstract_output_stream.rb +43 -0
  100. data/lib/zip/ioextras.rb +36 -0
  101. data/lib/zip/null_compressor.rb +15 -0
  102. data/lib/zip/null_decompressor.rb +19 -0
  103. data/lib/zip/null_input_stream.rb +10 -0
  104. data/lib/zip/output_stream.rb +198 -0
  105. data/lib/zip/pass_thru_compressor.rb +23 -0
  106. data/lib/zip/pass_thru_decompressor.rb +31 -0
  107. data/lib/zip/streamable_directory.rb +15 -0
  108. data/lib/zip/streamable_stream.rb +52 -0
  109. data/lib/zip/version.rb +3 -0
  110. data/lib/zip.rb +72 -0
  111. metadata +103 -31
data/lib/git.rb ADDED
@@ -0,0 +1,326 @@
1
+ # Add the directory containing this file to the start of the load path if it
2
+ # isn't there already.
3
+ $:.unshift(File.dirname(__FILE__)) unless
4
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
5
+
6
+ require 'git/author'
7
+ require 'git/base'
8
+ require 'git/branch'
9
+ require 'git/branches'
10
+ require 'git/config'
11
+ require 'git/diff'
12
+ require 'git/encoding_utils'
13
+ require 'git/escaped_path'
14
+ require 'git/index'
15
+ require 'git/lib'
16
+ require 'git/log'
17
+ require 'git/object'
18
+ require 'git/path'
19
+ require 'git/remote'
20
+ require 'git/repository'
21
+ require 'git/status'
22
+ require 'git/stash'
23
+ require 'git/stashes'
24
+ require 'git/url'
25
+ require 'git/version'
26
+ require 'git/working_directory'
27
+ require 'git/worktree'
28
+ require 'git/worktrees'
29
+
30
+ lib = Git::Lib.new(nil, nil)
31
+ unless lib.meets_required_version?
32
+ $stderr.puts "[WARNING] The git gem requires git #{lib.required_command_version.join('.')} or later, but only found #{lib.current_command_version.join('.')}. You should probably upgrade."
33
+ end
34
+
35
+ # The Git module provides the basic functions to open a git
36
+ # reference to work with. You can open a working directory,
37
+ # open a bare repository, initialize a new repo or clone an
38
+ # existing remote repository.
39
+ #
40
+ # @author Scott Chacon (mailto:schacon@gmail.com)
41
+ #
42
+ module Git
43
+ #g.config('user.name', 'Scott Chacon') # sets value
44
+ #g.config('user.email', 'email@email.com') # sets value
45
+ #g.config('user.name') # returns 'Scott Chacon'
46
+ #g.config # returns whole config hash
47
+ def config(name = nil, value = nil)
48
+ lib = Git::Lib.new
49
+ if(name && value)
50
+ # set value
51
+ lib.config_set(name, value)
52
+ elsif (name)
53
+ # return value
54
+ lib.config_get(name)
55
+ else
56
+ # return hash
57
+ lib.config_list
58
+ end
59
+ end
60
+
61
+ def self.configure
62
+ yield Base.config
63
+ end
64
+
65
+ def self.config
66
+ return Base.config
67
+ end
68
+
69
+ def global_config(name = nil, value = nil)
70
+ self.class.global_config(name, value)
71
+ end
72
+
73
+ # Open a bare repository
74
+ #
75
+ # Opens a bare repository located in the `git_dir` directory.
76
+ # Since there is no working copy, you can not checkout or commit
77
+ # but you can do most read operations.
78
+ #
79
+ # @see https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefbarerepositoryabarerepository
80
+ # What is a bare repository?
81
+ #
82
+ # @example Open a bare repository and retrieve the first commit SHA
83
+ # repository = Git.bare('ruby-git.git')
84
+ # puts repository.log[0].sha #=> "64c6fa011d3287bab9158049c85f3e85718854a0"
85
+ #
86
+ # @param [Pathname] git_dir The path to the bare repository directory
87
+ # containing an initialized Git repository. If a relative path is given, it
88
+ # is converted to an absolute path using
89
+ # [File.expand_path](https://www.rubydoc.info/stdlib/core/File.expand_path).
90
+ #
91
+ # @param [Hash] options The options for this command (see list of valid
92
+ # options below)
93
+ #
94
+ # @option options [Logger] :log A logger to use for Git operations. Git commands
95
+ # are logged at the `:info` level. Additional logging is done at the `:debug`
96
+ # level.
97
+ #
98
+ # @return [Git::Base] an object that can execute git commands in the context
99
+ # of the bare repository.
100
+ #
101
+ def self.bare(git_dir, options = {})
102
+ Base.bare(git_dir, options)
103
+ end
104
+
105
+ # Clone a repository into an empty or newly created directory
106
+ #
107
+ # @see https://git-scm.com/docs/git-clone git clone
108
+ # @see https://git-scm.com/docs/git-clone#_git_urls_a_id_urls_a GIT URLs
109
+ #
110
+ # @param repository_url [URI, Pathname] The (possibly remote) repository url to clone
111
+ # from. See [GIT URLS](https://git-scm.com/docs/git-clone#_git_urls_a_id_urls_a)
112
+ # for more information.
113
+ #
114
+ # @param directory [Pathname, nil] The directory to clone into
115
+ #
116
+ # If `directory` is a relative directory it is relative to the `path` option if
117
+ # given. If `path` is not given, `directory` is relative to the current working
118
+ # directory.
119
+ #
120
+ # If `nil`, `directory` will be set to the basename of the last component of
121
+ # the path from the `repository_url`. For example, for the URL:
122
+ # `https://github.com/org/repo.git`, `directory` will be set to `repo`.
123
+ #
124
+ # If the last component of the path is `.git`, the next-to-last component of
125
+ # the path is used. For example, for the URL `/Users/me/foo/.git`, `directory`
126
+ # will be set to `foo`.
127
+ #
128
+ # @param [Hash] options The options for this command (see list of valid
129
+ # options below)
130
+ #
131
+ # @option options [Boolean] :bare Make a bare Git repository. See
132
+ # [what is a bare repository?](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefbarerepositoryabarerepository).
133
+ #
134
+ # @option options [String] :branch The name of a branch or tag to checkout
135
+ # instead of the default branch.
136
+ #
137
+ # @option options [Integer] :depth Create a shallow clone with a history
138
+ # truncated to the specified number of commits.
139
+ #
140
+ # @option options [Logger] :log A logger to use for Git operations. Git
141
+ # commands are logged at the `:info` level. Additional logging is done
142
+ # at the `:debug` level.
143
+ #
144
+ # @option options [Boolean] :mirror Set up a mirror of the source repository.
145
+ #
146
+ # @option options [String] :origin Use the value instead `origin` to track
147
+ # the upstream repository.
148
+ #
149
+ # @option options [Pathname] :path The directory to clone into. May be used
150
+ # as an alternative to the `directory` parameter. If specified, the
151
+ # `path` option is used instead of the `directory` parameter.
152
+ #
153
+ # @option options [Boolean] :recursive After the clone is created, initialize
154
+ # all submodules within, using their default settings.
155
+ #
156
+ # @example Clone into the default directory `ruby-git`
157
+ # git = Git.clone('https://github.com/ruby-git/ruby-git.git')
158
+ #
159
+ # @example Clone and then checkout the `development` branch
160
+ # git = Git.clone('https://github.com/ruby-git/ruby-git.git', branch: 'development')
161
+ #
162
+ # @example Clone into a different directory `my-ruby-git`
163
+ # git = Git.clone('https://github.com/ruby-git/ruby-git.git', 'my-ruby-git')
164
+ # # or:
165
+ # git = Git.clone('https://github.com/ruby-git/ruby-git.git', path: 'my-ruby-git')
166
+ #
167
+ # @example Create a bare repository in the directory `ruby-git.git`
168
+ # git = Git.clone('https://github.com/ruby-git/ruby-git.git', bare: true)
169
+ #
170
+ # @return [Git::Base] an object that can execute git commands in the context
171
+ # of the cloned local working copy or cloned repository.
172
+ #
173
+ def self.clone(repository_url, directory = nil, options = {})
174
+ clone_to_options = options.select { |key, _value| %i[bare mirror].include?(key) }
175
+ directory ||= Git::URL.clone_to(repository_url, **clone_to_options)
176
+ Base.clone(repository_url, directory, options)
177
+ end
178
+
179
+ # Export the current HEAD (or a branch, if <tt>options[:branch]</tt>
180
+ # is specified) into the +name+ directory, then remove all traces of git from the
181
+ # directory.
182
+ #
183
+ # See +clone+ for options. Does not obey the <tt>:remote</tt> option,
184
+ # since the .git info will be deleted anyway; always uses the default
185
+ # remote, 'origin.'
186
+ def self.export(repository, name, options = {})
187
+ options.delete(:remote)
188
+ repo = clone(repository, name, {:depth => 1}.merge(options))
189
+ repo.checkout("origin/#{options[:branch]}") if options[:branch]
190
+ Dir.chdir(repo.dir.to_s) { FileUtils.rm_r '.git' }
191
+ end
192
+
193
+ # Same as g.config, but forces it to be at the global level
194
+ #
195
+ #g.config('user.name', 'Scott Chacon') # sets value
196
+ #g.config('user.email', 'email@email.com') # sets value
197
+ #g.config('user.name') # returns 'Scott Chacon'
198
+ #g.config # returns whole config hash
199
+ def self.global_config(name = nil, value = nil)
200
+ lib = Git::Lib.new(nil, nil)
201
+ if(name && value)
202
+ # set value
203
+ lib.global_config_set(name, value)
204
+ elsif (name)
205
+ # return value
206
+ lib.global_config_get(name)
207
+ else
208
+ # return hash
209
+ lib.global_config_list
210
+ end
211
+ end
212
+
213
+ # Create an empty Git repository or reinitialize an existing Git repository
214
+ #
215
+ # @param [Pathname] directory If the `:bare` option is NOT given or is not
216
+ # `true`, the repository will be created in `"#{directory}/.git"`.
217
+ # Otherwise, the repository is created in `"#{directory}"`.
218
+ #
219
+ # All directories along the path to `directory` are created if they do not exist.
220
+ #
221
+ # A relative path is referenced from the current working directory of the process
222
+ # and converted to an absolute path using
223
+ # [File.expand_path](https://www.rubydoc.info/stdlib/core/File.expand_path).
224
+ #
225
+ # @param [Hash] options The options for this command (see list of valid
226
+ # options below)
227
+ #
228
+ # @option options [Boolean] :bare Instead of creating a repository at
229
+ # `"#{directory}/.git"`, create a bare repository at `"#{directory}"`.
230
+ # See [what is a bare repository?](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefbarerepositoryabarerepository).
231
+ #
232
+ # @option options [String] :initial_branch Use the specified name for the
233
+ # initial branch in the newly created repository.
234
+ #
235
+ # @option options [Pathname] :repository the path to put the newly initialized
236
+ # Git repository. The default for non-bare repository is `"#{directory}/.git"`.
237
+ #
238
+ # A relative path is referenced from the current working directory of the process
239
+ # and converted to an absolute path using
240
+ # [File.expand_path](https://www.rubydoc.info/stdlib/core/File.expand_path).
241
+ #
242
+ # @option options [Logger] :log A logger to use for Git operations. Git
243
+ # commands are logged at the `:info` level. Additional logging is done
244
+ # at the `:debug` level.
245
+ #
246
+ # @return [Git::Base] an object that can execute git commands in the context
247
+ # of the newly initialized repository
248
+ #
249
+ # @example Initialize a repository in the current directory
250
+ # git = Git.init
251
+ #
252
+ # @example Initialize a repository in some other directory
253
+ # git = Git.init '~/code/ruby-git'
254
+ #
255
+ # @example Initialize a bare repository
256
+ # git = Git.init '~/code/ruby-git.git', bare: true
257
+ #
258
+ # @example Initialize a repository in a non-default location (outside of the working copy)
259
+ # git = Git.init '~/code/ruby-git', repository: '~/code/ruby-git.git'
260
+ #
261
+ # @see https://git-scm.com/docs/git-init git init
262
+ #
263
+ def self.init(directory = '.', options = {})
264
+ Base.init(directory, options)
265
+ end
266
+
267
+ # returns a Hash containing information about the references
268
+ # of the target repository
269
+ #
270
+ # options
271
+ # :refs
272
+ #
273
+ # @param [String|NilClass] location the target repository location or nil for '.'
274
+ # @return [{String=>Hash}] the available references of the target repo.
275
+ def self.ls_remote(location = nil, options = {})
276
+ Git::Lib.new.ls_remote(location, options)
277
+ end
278
+
279
+ # Open a an existing Git working directory
280
+ #
281
+ # Git.open will most likely be the most common way to create
282
+ # a git reference, referring to an existing working directory.
283
+ #
284
+ # If not provided in the options, the library will assume
285
+ # the repository and index are in the default places (`.git/`, `.git/index`).
286
+ #
287
+ # @example Open the Git working directory in the current directory
288
+ # git = Git.open
289
+ #
290
+ # @example Open a Git working directory in some other directory
291
+ # git = Git.open('~/Projects/ruby-git')
292
+ #
293
+ # @example Use a logger to see what is going on
294
+ # logger = Logger.new(STDOUT)
295
+ # git = Git.open('~/Projects/ruby-git', log: logger)
296
+ #
297
+ # @example Open a working copy whose repository is in a non-standard directory
298
+ # git = Git.open('~/Projects/ruby-git', repository: '~/Project/ruby-git.git')
299
+ #
300
+ # @param [Pathname] working_dir the path to the working directory to use
301
+ # for git commands.
302
+ #
303
+ # A relative path is referenced from the current working directory of the process
304
+ # and converted to an absolute path using
305
+ # [File.expand_path](https://www.rubydoc.info/stdlib/core/File.expand_path).
306
+ #
307
+ # @param [Hash] options The options for this command (see list of valid
308
+ # options below)
309
+ #
310
+ # @option options [Pathname] :repository used to specify a non-standard path to
311
+ # the repository directory. The default is `"#{working_dir}/.git"`.
312
+ #
313
+ # @option options [Pathname] :index used to specify a non-standard path to an
314
+ # index file. The default is `"#{working_dir}/.git/index"`
315
+ #
316
+ # @option options [Logger] :log A logger to use for Git operations. Git
317
+ # commands are logged at the `:info` level. Additional logging is done
318
+ # at the `:debug` level.
319
+ #
320
+ # @return [Git::Base] an object that can execute git commands in the context
321
+ # of the opened working copy
322
+ #
323
+ def self.open(working_dir, options = {})
324
+ Base.open(working_dir, options)
325
+ end
326
+ end
@@ -1,104 +1,104 @@
1
- require "sqlite3"
2
- require 'singleton'
3
- require_relative 'l_cache'
4
-
5
- module LgPodPlugin
6
-
7
- class LSqliteDb
8
- include Singleton
9
- REQUIRED_ATTRS ||= %i[db table_name].freeze
10
- attr_accessor(*REQUIRED_ATTRS)
11
- # 初始化 db
12
- def initialize
13
- root_path = LFileManager.download_director.join("database")
14
- db_file_path = root_path.join("my.db")
15
- if !root_path.exist? || !db_file_path.exist?
16
- FileUtils.mkdir(root_path)
17
- FileUtils.chdir(root_path)
18
- FileUtils.touch("my.db")
19
- end
20
- # FileUtils.chdir(root_path)
21
- self.db = SQLite3::Database.new(db_file_path.to_path)
22
- #添加表
23
- # sql = "create table IF NOT EXISTS LgPodTable (id integer primary key autoincrement not null, name varchar(100), branch varchar(100), commit varchar(100));"
24
- sql = "create table if not exists lg_pod_table(
25
- id integer primary key autoincrement not null,
26
- name varchar(100),
27
- branch varchar(100),
28
- sha varchar(100),
29
- tag varchar(100),
30
- local_path varchar(150),
31
- update_time TimeStamp NOT NULL DEFAULT CURRENT_TIMESTAMP)"
32
- self.db.execute(sql)
33
- self.table_name = "lg_pod_table"
34
- super
35
- end
36
-
37
- def insert_table(name, branch, sha, tag, path)
38
- timestamp = Time.now.to_i * 1000
39
- pod_info = self.select_table(name, branch)
40
- if pod_info.name
41
- self.db.execute_batch(
42
- "UPDATE #{table_name} SET sha = (:sha), tag = (:tag), local_path = (:local_path), update_time = (:update_time) where (name = :name) and (branch = :branch)", {"branch" => branch,"name" => name, "sha" => sha,"tag" => tag, :update_time => timestamp, :local_path => path.to_path}
43
- )
44
- else
45
- self.db.execute("INSERT INTO #{table_name} (name, branch, sha, tag, local_path, update_time)
46
- VALUES (?, ?, ?, ?,?,?)", [name, branch, sha, tag, path.to_path, timestamp])
47
- end
48
- end
49
-
50
- def should_clean_pod_info(name, branch)
51
- current_pod = self.select_table(name, branch)
52
- if current_pod&.path && !Dir.exist?(current_pod.path)
53
- self.delete_table(current_pod.name, current_pod.branch)
54
- end
55
- array = self.select_tables(name, branch)
56
- if array.count <= 2
57
- return
58
- end
59
-
60
- #待删除的 pod 换成
61
- pod_info = array.first
62
- if pod_info&.path && Dir.exist?(pod_info.path)
63
- FileUtils.rm_rf(pod_info.path)
64
- self.delete_table(pod_info.name, pod_info.branch)
65
- array.delete(pod_info)
66
- end
67
-
68
- end
69
-
70
- def select_table(name, branch)
71
- pod_info = LCachePodInfo.new
72
- self.db.execute( "select * from #{self.table_name} where name = '#{name}' and branch = '#{branch}'; ") do |row|
73
- pod_info.name = row[1]
74
- pod_info.branch = row[2]
75
- pod_info.sha = row[3]
76
- pod_info.tag = row[4]
77
- pod_info.path = row[5]
78
- pod_info.timestamp = row[6]
79
- end
80
- pod_info
81
- end
82
-
83
- def select_tables(name, branch)
84
- array = []
85
- self.db.execute( "select * from #{self.table_name} where name = '#{name}' and branch != '#{branch}' order by update_time;") do |row|
86
- pod_info = LCachePodInfo.new
87
- pod_info.name = row[1]
88
- pod_info.branch = row[2]
89
- pod_info.sha = row[3]
90
- pod_info.tag = row[4]
91
- pod_info.path = row[5]
92
- pod_info.timestamp = row[6]
93
- array.append(pod_info)
94
- end
95
- array
96
- end
97
-
98
- def delete_table(name, branch)
99
- self.db.execute("delete from #{self.table_name} where name = ? and branch = ? ;", [name, branch])
100
- end
101
-
102
- end
103
-
104
- end
1
+ # require "sqlite3"
2
+ # require 'singleton'
3
+ # require_relative 'l_cache'
4
+ #
5
+ # module LgPodPlugin
6
+ #
7
+ # class LSqliteDb
8
+ # include Singleton
9
+ # REQUIRED_ATTRS ||= %i[db table_name].freeze
10
+ # attr_accessor(*REQUIRED_ATTRS)
11
+ # # 初始化 db
12
+ # def initialize
13
+ # root_path = LFileManager.download_director.join("database")
14
+ # db_file_path = root_path.join("my.db")
15
+ # if !root_path.exist? || !db_file_path.exist?
16
+ # FileUtils.mkdir(root_path)
17
+ # FileUtils.chdir(root_path)
18
+ # FileUtils.touch("my.db")
19
+ # end
20
+ # # FileUtils.chdir(root_path)
21
+ # self.db = SQLite3::Database.new(db_file_path.to_path)
22
+ # #添加表
23
+ # # sql = "create table IF NOT EXISTS LgPodTable (id integer primary key autoincrement not null, name varchar(100), branch varchar(100), commit varchar(100));"
24
+ # sql = "create table if not exists lg_pod_table(
25
+ # id integer primary key autoincrement not null,
26
+ # name varchar(100),
27
+ # branch varchar(100),
28
+ # sha varchar(100),
29
+ # tag varchar(100),
30
+ # local_path varchar(150),
31
+ # update_time TimeStamp NOT NULL DEFAULT CURRENT_TIMESTAMP)"
32
+ # self.db.execute(sql)
33
+ # self.table_name = "lg_pod_table"
34
+ # super
35
+ # end
36
+ #
37
+ # def insert_table(name, branch, sha, tag, path)
38
+ # timestamp = Time.now.to_i * 1000
39
+ # pod_info = self.select_table(name, branch)
40
+ # if pod_info.name
41
+ # self.db.execute_batch(
42
+ # "UPDATE #{table_name} SET sha = (:sha), tag = (:tag), local_path = (:local_path), update_time = (:update_time) where (name = :name) and (branch = :branch)", {"branch" => branch,"name" => name, "sha" => sha,"tag" => tag, :update_time => timestamp, :local_path => path.to_path}
43
+ # )
44
+ # else
45
+ # self.db.execute("INSERT INTO #{table_name} (name, branch, sha, tag, local_path, update_time)
46
+ # VALUES (?, ?, ?, ?,?,?)", [name, branch, sha, tag, path.to_path, timestamp])
47
+ # end
48
+ # end
49
+ #
50
+ # def should_clean_pod_info(name, branch)
51
+ # current_pod = self.select_table(name, branch)
52
+ # if current_pod&.path && !Dir.exist?(current_pod.path)
53
+ # self.delete_table(current_pod.name, current_pod.branch)
54
+ # end
55
+ # array = self.select_tables(name, branch)
56
+ # if array.count <= 2
57
+ # return
58
+ # end
59
+ #
60
+ # #待删除的 pod 换成
61
+ # pod_info = array.first
62
+ # if pod_info&.path && Dir.exist?(pod_info.path)
63
+ # FileUtils.rm_rf(pod_info.path)
64
+ # self.delete_table(pod_info.name, pod_info.branch)
65
+ # array.delete(pod_info)
66
+ # end
67
+ #
68
+ # end
69
+ #
70
+ # def select_table(name, branch)
71
+ # pod_info = LCachePodInfo.new
72
+ # self.db.execute( "select * from #{self.table_name} where name = '#{name}' and branch = '#{branch}'; ") do |row|
73
+ # pod_info.name = row[1]
74
+ # pod_info.branch = row[2]
75
+ # pod_info.sha = row[3]
76
+ # pod_info.tag = row[4]
77
+ # pod_info.path = row[5]
78
+ # pod_info.timestamp = row[6]
79
+ # end
80
+ # pod_info
81
+ # end
82
+ #
83
+ # def select_tables(name, branch)
84
+ # array = []
85
+ # self.db.execute( "select * from #{self.table_name} where name = '#{name}' and branch != '#{branch}' order by update_time;") do |row|
86
+ # pod_info = LCachePodInfo.new
87
+ # pod_info.name = row[1]
88
+ # pod_info.branch = row[2]
89
+ # pod_info.sha = row[3]
90
+ # pod_info.tag = row[4]
91
+ # pod_info.path = row[5]
92
+ # pod_info.timestamp = row[6]
93
+ # array.append(pod_info)
94
+ # end
95
+ # array
96
+ # end
97
+ #
98
+ # def delete_table(name, branch)
99
+ # self.db.execute("delete from #{self.table_name} where name = ? and branch = ? ;", [name, branch])
100
+ # end
101
+ #
102
+ # end
103
+ #
104
+ # end
@@ -1,6 +1,6 @@
1
1
  require 'git'
2
2
  require_relative 'l_cache'
3
- require_relative 'database'
3
+ # require_relative 'database'
4
4
  require_relative 'file_path'
5
5
 
6
6
  module LgPodPlugin
@@ -20,7 +20,7 @@ module LgPodPlugin
20
20
  # pod缓存工作目录, 根据项目所在路径计算所得 确保唯一
21
21
  def self.cache_workspace(root)
22
22
  timestamp = "_#{Time.now.to_i}_"
23
- key = root.to_path + timestamp + "#{(rand() * 10000000).to_i}"
23
+ key = root.to_path + timestamp + "#{(rand * 10000000).to_i}"
24
24
  director = Digest::MD5.hexdigest(key)
25
25
  return self.download_director.join(director)
26
26
  end