raykit 0.0.526 → 0.0.529
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -21
- data/README.md +25 -25
- data/bin/raykit +6 -6
- data/lib/raykit/auto_setup.rb +69 -69
- data/lib/raykit/command.rb +374 -374
- data/lib/raykit/conan/buildinfo.rb +69 -69
- data/lib/raykit/conanpackage.rb +49 -49
- data/lib/raykit/configuration.rb +53 -53
- data/lib/raykit/console.rb +310 -310
- data/lib/raykit/default_content.rb +227 -227
- data/lib/raykit/dir.rb +96 -96
- data/lib/raykit/dotnet.rb +174 -174
- data/lib/raykit/environment.rb +115 -115
- data/lib/raykit/filesystem.rb +34 -34
- data/lib/raykit/git/commit.rb +16 -16
- data/lib/raykit/git/directory.rb +244 -216
- data/lib/raykit/git/files.rb +46 -46
- data/lib/raykit/git/repositories.rb +89 -89
- data/lib/raykit/git/repository.rb +362 -362
- data/lib/raykit/installer.rb +17 -17
- data/lib/raykit/log.rb +80 -80
- data/lib/raykit/logevent.rb +29 -29
- data/lib/raykit/logger.rb +100 -100
- data/lib/raykit/logging.rb +57 -57
- data/lib/raykit/markdown.rb +21 -21
- data/lib/raykit/msbuild.rb +54 -54
- data/lib/raykit/nugetpackage.rb +54 -54
- data/lib/raykit/nunit.rb +13 -13
- data/lib/raykit/project.rb +343 -343
- data/lib/raykit/rake.rb +39 -39
- data/lib/raykit/runner.rb +42 -42
- data/lib/raykit/secrets.rb +38 -38
- data/lib/raykit/sourceImport.rb +76 -76
- data/lib/raykit/sourceImports.rb +43 -43
- data/lib/raykit/string.rb +18 -18
- data/lib/raykit/symbols.rb +115 -115
- data/lib/raykit/tasks.rb +91 -91
- data/lib/raykit/text.rb +32 -32
- data/lib/raykit/timer.rb +31 -31
- data/lib/raykit/version.rb +95 -95
- data/lib/raykit/vstest.rb +24 -24
- data/lib/raykit/wix.rb +61 -61
- data/lib/raykit/wt.rb +28 -28
- data/lib/raykit/zip.rb +73 -73
- data/lib/raykit.rb +135 -129
- metadata +3 -3
@@ -1,227 +1,227 @@
|
|
1
|
-
module Raykit
|
2
|
-
class DefaultContent
|
3
|
-
def self.gitignore
|
4
|
-
<<-GITIGNORE
|
5
|
-
# General
|
6
|
-
[Aa]rtifacts/
|
7
|
-
|
8
|
-
# Ruby
|
9
|
-
*.gem
|
10
|
-
*.rbc
|
11
|
-
/.config
|
12
|
-
/coverage/
|
13
|
-
/InstalledFiles
|
14
|
-
/pkg/
|
15
|
-
/spec/reports/
|
16
|
-
/spec/examples.txt
|
17
|
-
/test/tmp/
|
18
|
-
/test/version_tmp/
|
19
|
-
/tmp/
|
20
|
-
/.yardoc/
|
21
|
-
/_yardoc/
|
22
|
-
/doc/
|
23
|
-
/rdoc/
|
24
|
-
/.bundle/
|
25
|
-
/vendor/bundle
|
26
|
-
/lib/bundler/man/
|
27
|
-
.rvmrc
|
28
|
-
|
29
|
-
# Rust
|
30
|
-
/target/
|
31
|
-
Cargo.lock
|
32
|
-
**/*.rs.bk
|
33
|
-
/target
|
34
|
-
/Cargo.lock
|
35
|
-
|
36
|
-
# DotNet
|
37
|
-
*.rsuser
|
38
|
-
*.suo
|
39
|
-
*.user
|
40
|
-
*.userosscache
|
41
|
-
*.sln.docstates
|
42
|
-
*.txt
|
43
|
-
*.userprefs
|
44
|
-
BenchmarkDotNet.Artifacts/
|
45
|
-
[Dd]ebug/
|
46
|
-
[Dd]ebugPublic/
|
47
|
-
[Rr]elease/
|
48
|
-
[Rr]eleases/
|
49
|
-
x64/
|
50
|
-
x86/
|
51
|
-
[Aa][Rr][Mm]/
|
52
|
-
[Aa][Rr][Mm]64/
|
53
|
-
bld/
|
54
|
-
[Bb]in/
|
55
|
-
[Oo]bj/
|
56
|
-
[Ll]og/
|
57
|
-
[Aa]rtifacts/
|
58
|
-
.vs/
|
59
|
-
Generated\ Files/
|
60
|
-
[Tt]est[Rr]esult*/
|
61
|
-
[Bb]uild[Ll]og.*
|
62
|
-
*.VisualState.xml
|
63
|
-
TestResult.xml
|
64
|
-
[Dd]ebugPS/
|
65
|
-
[Rr]eleasePS/
|
66
|
-
dlldata.c
|
67
|
-
BenchmarkDotNet.Artifacts/
|
68
|
-
|
69
|
-
project.lock.json
|
70
|
-
project.fragment.lock.json
|
71
|
-
artifacts/
|
72
|
-
StyleCopReport.xml
|
73
|
-
*_i.c
|
74
|
-
*_p.c
|
75
|
-
*_h.h
|
76
|
-
*.ilk
|
77
|
-
*.meta
|
78
|
-
*.obj
|
79
|
-
*.iobj
|
80
|
-
*.pch
|
81
|
-
*.pdb
|
82
|
-
*.ipdb
|
83
|
-
*.pgc
|
84
|
-
*.pgd
|
85
|
-
*.rsp
|
86
|
-
*.sbr
|
87
|
-
*.tlb
|
88
|
-
*.tli
|
89
|
-
*.tlh
|
90
|
-
*.tmp
|
91
|
-
*.tmp_proj
|
92
|
-
*_wpftmp.csproj
|
93
|
-
*.log
|
94
|
-
*.vspscc
|
95
|
-
*.vssscc
|
96
|
-
.builds
|
97
|
-
*.pidb
|
98
|
-
*.svclog
|
99
|
-
*.scc
|
100
|
-
_Chutzpah*
|
101
|
-
ipch/
|
102
|
-
*.aps
|
103
|
-
*.ncb
|
104
|
-
*.opendb
|
105
|
-
*.opensdf
|
106
|
-
*.sdf
|
107
|
-
*.cachefile
|
108
|
-
*.VC.db
|
109
|
-
*.VC.VC.opendb
|
110
|
-
*.psess
|
111
|
-
*.vsp
|
112
|
-
*.vspx
|
113
|
-
*.sap
|
114
|
-
*.e2e
|
115
|
-
$tf/
|
116
|
-
*.gpState
|
117
|
-
_ReSharper*/
|
118
|
-
*.[Rr]e[Ss]harper
|
119
|
-
*.DotSettings.user
|
120
|
-
.JustCode
|
121
|
-
_TeamCity*
|
122
|
-
*.dotCover
|
123
|
-
.axoCover/*
|
124
|
-
!.axoCover/settings.json
|
125
|
-
*.coverage
|
126
|
-
*.coveragexml
|
127
|
-
_NCrunch_*
|
128
|
-
.*crunch*.local.xml
|
129
|
-
nCrunchTemp_*
|
130
|
-
*.mm.*
|
131
|
-
AutoTest.Net/
|
132
|
-
.sass-cache/
|
133
|
-
[Ee]xpress/
|
134
|
-
DocProject/buildhelp/
|
135
|
-
DocProject/Help/*.HxT
|
136
|
-
DocProject/Help/*.HxC
|
137
|
-
DocProject/Help/*.hhc
|
138
|
-
DocProject/Help/*.hhk
|
139
|
-
DocProject/Help/*.hhp
|
140
|
-
DocProject/Help/Html2
|
141
|
-
DocProject/Help/html
|
142
|
-
publish/
|
143
|
-
*.[Pp]ublish.xml
|
144
|
-
*.azurePubxml
|
145
|
-
*.pubxml
|
146
|
-
*.publishproj
|
147
|
-
PublishScripts/
|
148
|
-
*.nupkg
|
149
|
-
**/[Pp]ackages/*
|
150
|
-
!**/[Pp]ackages/build/
|
151
|
-
*.nuget.props
|
152
|
-
*.nuget.targets
|
153
|
-
csx/
|
154
|
-
*.build.csdef
|
155
|
-
ecf/
|
156
|
-
rcf/
|
157
|
-
AppPackages/
|
158
|
-
BundleArtifacts/
|
159
|
-
Package.StoreAssociation.xml
|
160
|
-
_pkginfo.txt
|
161
|
-
*.appx
|
162
|
-
*.[Cc]ache
|
163
|
-
# but keep track of directories ending in .cache
|
164
|
-
!*.[Cc]ache/
|
165
|
-
ClientBin/
|
166
|
-
~$*
|
167
|
-
*~
|
168
|
-
*.dbmdl
|
169
|
-
*.dbproj.schemaview
|
170
|
-
*.jfm
|
171
|
-
*.pfx
|
172
|
-
*.publishsettings
|
173
|
-
orleans.codegen.cs
|
174
|
-
**/wwwroot/lib/
|
175
|
-
Generated_Code/
|
176
|
-
_UpgradeReport_Files/
|
177
|
-
Backup*/
|
178
|
-
UpgradeLog*.XML
|
179
|
-
UpgradeLog*.htm
|
180
|
-
ServiceFabricBackup/
|
181
|
-
*.rptproj.bak
|
182
|
-
*.mdf
|
183
|
-
*.ldf
|
184
|
-
*.ndf
|
185
|
-
*.rdl.data
|
186
|
-
*.bim.layout
|
187
|
-
*.bim_*.settings
|
188
|
-
*.rptproj.rsuser
|
189
|
-
FakesAssemblies/
|
190
|
-
*.GhostDoc.xml
|
191
|
-
.ntvs_analysis.dat
|
192
|
-
node_modules/
|
193
|
-
*.plg
|
194
|
-
*.opt
|
195
|
-
*.vbw
|
196
|
-
**/*.HTMLClient/GeneratedArtifacts
|
197
|
-
**/*.DesktopClient/GeneratedArtifacts
|
198
|
-
**/*.DesktopClient/ModelManifest.xml
|
199
|
-
**/*.Server/GeneratedArtifacts
|
200
|
-
**/*.Server/ModelManifest.xml
|
201
|
-
_Pvt_Extensions
|
202
|
-
.paket/paket.exe
|
203
|
-
paket-files/
|
204
|
-
.fake/
|
205
|
-
.idea/
|
206
|
-
*.sln.iml
|
207
|
-
.cr/personal
|
208
|
-
__pycache__/
|
209
|
-
*.pyc
|
210
|
-
tools/**
|
211
|
-
!tools/packages.config
|
212
|
-
*.tss
|
213
|
-
*.jmconfig
|
214
|
-
*.btp.cs
|
215
|
-
*.btm.cs
|
216
|
-
*.odx.cs
|
217
|
-
*.xsd.cs
|
218
|
-
OpenCover/
|
219
|
-
ASALocalRun/
|
220
|
-
*.binlog
|
221
|
-
*.nvuser
|
222
|
-
.mfractor/
|
223
|
-
.localhistory/
|
224
|
-
GITIGNORE
|
225
|
-
end # def self.gitignore
|
226
|
-
end # class DefaultContent
|
227
|
-
end # module Raykit
|
1
|
+
module Raykit
|
2
|
+
class DefaultContent
|
3
|
+
def self.gitignore
|
4
|
+
<<-GITIGNORE
|
5
|
+
# General
|
6
|
+
[Aa]rtifacts/
|
7
|
+
|
8
|
+
# Ruby
|
9
|
+
*.gem
|
10
|
+
*.rbc
|
11
|
+
/.config
|
12
|
+
/coverage/
|
13
|
+
/InstalledFiles
|
14
|
+
/pkg/
|
15
|
+
/spec/reports/
|
16
|
+
/spec/examples.txt
|
17
|
+
/test/tmp/
|
18
|
+
/test/version_tmp/
|
19
|
+
/tmp/
|
20
|
+
/.yardoc/
|
21
|
+
/_yardoc/
|
22
|
+
/doc/
|
23
|
+
/rdoc/
|
24
|
+
/.bundle/
|
25
|
+
/vendor/bundle
|
26
|
+
/lib/bundler/man/
|
27
|
+
.rvmrc
|
28
|
+
|
29
|
+
# Rust
|
30
|
+
/target/
|
31
|
+
Cargo.lock
|
32
|
+
**/*.rs.bk
|
33
|
+
/target
|
34
|
+
/Cargo.lock
|
35
|
+
|
36
|
+
# DotNet
|
37
|
+
*.rsuser
|
38
|
+
*.suo
|
39
|
+
*.user
|
40
|
+
*.userosscache
|
41
|
+
*.sln.docstates
|
42
|
+
*.txt
|
43
|
+
*.userprefs
|
44
|
+
BenchmarkDotNet.Artifacts/
|
45
|
+
[Dd]ebug/
|
46
|
+
[Dd]ebugPublic/
|
47
|
+
[Rr]elease/
|
48
|
+
[Rr]eleases/
|
49
|
+
x64/
|
50
|
+
x86/
|
51
|
+
[Aa][Rr][Mm]/
|
52
|
+
[Aa][Rr][Mm]64/
|
53
|
+
bld/
|
54
|
+
[Bb]in/
|
55
|
+
[Oo]bj/
|
56
|
+
[Ll]og/
|
57
|
+
[Aa]rtifacts/
|
58
|
+
.vs/
|
59
|
+
Generated\ Files/
|
60
|
+
[Tt]est[Rr]esult*/
|
61
|
+
[Bb]uild[Ll]og.*
|
62
|
+
*.VisualState.xml
|
63
|
+
TestResult.xml
|
64
|
+
[Dd]ebugPS/
|
65
|
+
[Rr]eleasePS/
|
66
|
+
dlldata.c
|
67
|
+
BenchmarkDotNet.Artifacts/
|
68
|
+
|
69
|
+
project.lock.json
|
70
|
+
project.fragment.lock.json
|
71
|
+
artifacts/
|
72
|
+
StyleCopReport.xml
|
73
|
+
*_i.c
|
74
|
+
*_p.c
|
75
|
+
*_h.h
|
76
|
+
*.ilk
|
77
|
+
*.meta
|
78
|
+
*.obj
|
79
|
+
*.iobj
|
80
|
+
*.pch
|
81
|
+
*.pdb
|
82
|
+
*.ipdb
|
83
|
+
*.pgc
|
84
|
+
*.pgd
|
85
|
+
*.rsp
|
86
|
+
*.sbr
|
87
|
+
*.tlb
|
88
|
+
*.tli
|
89
|
+
*.tlh
|
90
|
+
*.tmp
|
91
|
+
*.tmp_proj
|
92
|
+
*_wpftmp.csproj
|
93
|
+
*.log
|
94
|
+
*.vspscc
|
95
|
+
*.vssscc
|
96
|
+
.builds
|
97
|
+
*.pidb
|
98
|
+
*.svclog
|
99
|
+
*.scc
|
100
|
+
_Chutzpah*
|
101
|
+
ipch/
|
102
|
+
*.aps
|
103
|
+
*.ncb
|
104
|
+
*.opendb
|
105
|
+
*.opensdf
|
106
|
+
*.sdf
|
107
|
+
*.cachefile
|
108
|
+
*.VC.db
|
109
|
+
*.VC.VC.opendb
|
110
|
+
*.psess
|
111
|
+
*.vsp
|
112
|
+
*.vspx
|
113
|
+
*.sap
|
114
|
+
*.e2e
|
115
|
+
$tf/
|
116
|
+
*.gpState
|
117
|
+
_ReSharper*/
|
118
|
+
*.[Rr]e[Ss]harper
|
119
|
+
*.DotSettings.user
|
120
|
+
.JustCode
|
121
|
+
_TeamCity*
|
122
|
+
*.dotCover
|
123
|
+
.axoCover/*
|
124
|
+
!.axoCover/settings.json
|
125
|
+
*.coverage
|
126
|
+
*.coveragexml
|
127
|
+
_NCrunch_*
|
128
|
+
.*crunch*.local.xml
|
129
|
+
nCrunchTemp_*
|
130
|
+
*.mm.*
|
131
|
+
AutoTest.Net/
|
132
|
+
.sass-cache/
|
133
|
+
[Ee]xpress/
|
134
|
+
DocProject/buildhelp/
|
135
|
+
DocProject/Help/*.HxT
|
136
|
+
DocProject/Help/*.HxC
|
137
|
+
DocProject/Help/*.hhc
|
138
|
+
DocProject/Help/*.hhk
|
139
|
+
DocProject/Help/*.hhp
|
140
|
+
DocProject/Help/Html2
|
141
|
+
DocProject/Help/html
|
142
|
+
publish/
|
143
|
+
*.[Pp]ublish.xml
|
144
|
+
*.azurePubxml
|
145
|
+
*.pubxml
|
146
|
+
*.publishproj
|
147
|
+
PublishScripts/
|
148
|
+
*.nupkg
|
149
|
+
**/[Pp]ackages/*
|
150
|
+
!**/[Pp]ackages/build/
|
151
|
+
*.nuget.props
|
152
|
+
*.nuget.targets
|
153
|
+
csx/
|
154
|
+
*.build.csdef
|
155
|
+
ecf/
|
156
|
+
rcf/
|
157
|
+
AppPackages/
|
158
|
+
BundleArtifacts/
|
159
|
+
Package.StoreAssociation.xml
|
160
|
+
_pkginfo.txt
|
161
|
+
*.appx
|
162
|
+
*.[Cc]ache
|
163
|
+
# but keep track of directories ending in .cache
|
164
|
+
!*.[Cc]ache/
|
165
|
+
ClientBin/
|
166
|
+
~$*
|
167
|
+
*~
|
168
|
+
*.dbmdl
|
169
|
+
*.dbproj.schemaview
|
170
|
+
*.jfm
|
171
|
+
*.pfx
|
172
|
+
*.publishsettings
|
173
|
+
orleans.codegen.cs
|
174
|
+
**/wwwroot/lib/
|
175
|
+
Generated_Code/
|
176
|
+
_UpgradeReport_Files/
|
177
|
+
Backup*/
|
178
|
+
UpgradeLog*.XML
|
179
|
+
UpgradeLog*.htm
|
180
|
+
ServiceFabricBackup/
|
181
|
+
*.rptproj.bak
|
182
|
+
*.mdf
|
183
|
+
*.ldf
|
184
|
+
*.ndf
|
185
|
+
*.rdl.data
|
186
|
+
*.bim.layout
|
187
|
+
*.bim_*.settings
|
188
|
+
*.rptproj.rsuser
|
189
|
+
FakesAssemblies/
|
190
|
+
*.GhostDoc.xml
|
191
|
+
.ntvs_analysis.dat
|
192
|
+
node_modules/
|
193
|
+
*.plg
|
194
|
+
*.opt
|
195
|
+
*.vbw
|
196
|
+
**/*.HTMLClient/GeneratedArtifacts
|
197
|
+
**/*.DesktopClient/GeneratedArtifacts
|
198
|
+
**/*.DesktopClient/ModelManifest.xml
|
199
|
+
**/*.Server/GeneratedArtifacts
|
200
|
+
**/*.Server/ModelManifest.xml
|
201
|
+
_Pvt_Extensions
|
202
|
+
.paket/paket.exe
|
203
|
+
paket-files/
|
204
|
+
.fake/
|
205
|
+
.idea/
|
206
|
+
*.sln.iml
|
207
|
+
.cr/personal
|
208
|
+
__pycache__/
|
209
|
+
*.pyc
|
210
|
+
tools/**
|
211
|
+
!tools/packages.config
|
212
|
+
*.tss
|
213
|
+
*.jmconfig
|
214
|
+
*.btp.cs
|
215
|
+
*.btm.cs
|
216
|
+
*.odx.cs
|
217
|
+
*.xsd.cs
|
218
|
+
OpenCover/
|
219
|
+
ASALocalRun/
|
220
|
+
*.binlog
|
221
|
+
*.nvuser
|
222
|
+
.mfractor/
|
223
|
+
.localhistory/
|
224
|
+
GITIGNORE
|
225
|
+
end # def self.gitignore
|
226
|
+
end # class DefaultContent
|
227
|
+
end # module Raykit
|
data/lib/raykit/dir.rb
CHANGED
@@ -1,96 +1,96 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "tmpdir"
|
4
|
-
require "find"
|
5
|
-
require_relative "./environment"
|
6
|
-
|
7
|
-
class Dir
|
8
|
-
def self.get_text(dir, relative_name)
|
9
|
-
File.read("#{dir}/#{relative_name}")
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.set_text(dir, relative_name, text)
|
13
|
-
File.open("#{dir}/#{relative_name}", "w") { |f| f.write text }
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.directory_size(directory)
|
17
|
-
total_size = 0
|
18
|
-
Find.find(directory) do |path|
|
19
|
-
if File.file?(path)
|
20
|
-
total_size += File.size(path)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
total_size
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.humanize_size(size_in_bytes)
|
27
|
-
units = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB"]
|
28
|
-
|
29
|
-
return "0 Bytes" if size_in_bytes == 0
|
30
|
-
|
31
|
-
exponent = (Math.log(size_in_bytes) / Math.log(1024)).to_i
|
32
|
-
exponent = units.size - 1 if exponent > units.size - 1 # Cap at the largest known unit
|
33
|
-
|
34
|
-
size = size_in_bytes.to_f / (1024 ** exponent)
|
35
|
-
format("%.2f %s", size, units[exponent])
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.get_git_directories(dir)
|
39
|
-
git_dirs = []
|
40
|
-
Dir.chdir(dir) do
|
41
|
-
Dir.glob("**/.git/index") do |f|
|
42
|
-
git_dir = File.dirname(File.dirname(f))
|
43
|
-
git_dirs << git_dir
|
44
|
-
end
|
45
|
-
end
|
46
|
-
git_dirs
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.get_git_urls(dir)
|
50
|
-
urls = Set.new
|
51
|
-
Dir.chdir(dir) do
|
52
|
-
get_git_directories(dir).each do |git_dir|
|
53
|
-
Dir.chdir(git_dir) do
|
54
|
-
url = `git config --get remote.origin.url`.strip
|
55
|
-
urls.add(url)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
urls
|
60
|
-
end
|
61
|
-
|
62
|
-
def self.get_data_dir
|
63
|
-
unless ENV["DATA_DIR"].nil?
|
64
|
-
data_dir = ENV["DATA_DIR"]
|
65
|
-
return data_dir if Dir.exist?(data_dir)
|
66
|
-
end
|
67
|
-
home_dir = Raykit::Environment.home_dir
|
68
|
-
return home_dir if Dir.exist?(home_dir)
|
69
|
-
|
70
|
-
Dir.tmpdir
|
71
|
-
end
|
72
|
-
|
73
|
-
require "fileutils"
|
74
|
-
|
75
|
-
def self.remove_empty_directories(dir)
|
76
|
-
# List all entries in the directory except for '.' and '..'
|
77
|
-
Dir.entries(dir).each do |entry|
|
78
|
-
next if entry == "." || entry == ".." # Skip the current and parent directory entries
|
79
|
-
|
80
|
-
path = File.join(dir, entry) # Construct the full path
|
81
|
-
|
82
|
-
if File.directory?(path)
|
83
|
-
remove_empty_directories(path) # Recursively call the method if the entry is a directory
|
84
|
-
# Remove the directory if it's empty after processing its contents
|
85
|
-
Dir.rmdir(path) if Dir.empty?(path)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
rescue Errno::ENOENT
|
89
|
-
# Handle the case where the directory doesn't exist or is removed before rmdir is called
|
90
|
-
puts "Directory not found: #{dir}"
|
91
|
-
end
|
92
|
-
|
93
|
-
# Example usage:
|
94
|
-
# remove_empty_directories('/path/to/directory')
|
95
|
-
|
96
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "tmpdir"
|
4
|
+
require "find"
|
5
|
+
require_relative "./environment"
|
6
|
+
|
7
|
+
class Dir
|
8
|
+
def self.get_text(dir, relative_name)
|
9
|
+
File.read("#{dir}/#{relative_name}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.set_text(dir, relative_name, text)
|
13
|
+
File.open("#{dir}/#{relative_name}", "w") { |f| f.write text }
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.directory_size(directory)
|
17
|
+
total_size = 0
|
18
|
+
Find.find(directory) do |path|
|
19
|
+
if File.file?(path)
|
20
|
+
total_size += File.size(path)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
total_size
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.humanize_size(size_in_bytes)
|
27
|
+
units = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB"]
|
28
|
+
|
29
|
+
return "0 Bytes" if size_in_bytes == 0
|
30
|
+
|
31
|
+
exponent = (Math.log(size_in_bytes) / Math.log(1024)).to_i
|
32
|
+
exponent = units.size - 1 if exponent > units.size - 1 # Cap at the largest known unit
|
33
|
+
|
34
|
+
size = size_in_bytes.to_f / (1024 ** exponent)
|
35
|
+
format("%.2f %s", size, units[exponent])
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.get_git_directories(dir)
|
39
|
+
git_dirs = []
|
40
|
+
Dir.chdir(dir) do
|
41
|
+
Dir.glob("**/.git/index") do |f|
|
42
|
+
git_dir = File.dirname(File.dirname(f))
|
43
|
+
git_dirs << git_dir
|
44
|
+
end
|
45
|
+
end
|
46
|
+
git_dirs
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.get_git_urls(dir)
|
50
|
+
urls = Set.new
|
51
|
+
Dir.chdir(dir) do
|
52
|
+
get_git_directories(dir).each do |git_dir|
|
53
|
+
Dir.chdir(git_dir) do
|
54
|
+
url = `git config --get remote.origin.url`.strip
|
55
|
+
urls.add(url)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
urls
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.get_data_dir
|
63
|
+
unless ENV["DATA_DIR"].nil?
|
64
|
+
data_dir = ENV["DATA_DIR"]
|
65
|
+
return data_dir if Dir.exist?(data_dir)
|
66
|
+
end
|
67
|
+
home_dir = Raykit::Environment.home_dir
|
68
|
+
return home_dir if Dir.exist?(home_dir)
|
69
|
+
|
70
|
+
Dir.tmpdir
|
71
|
+
end
|
72
|
+
|
73
|
+
require "fileutils"
|
74
|
+
|
75
|
+
def self.remove_empty_directories(dir)
|
76
|
+
# List all entries in the directory except for '.' and '..'
|
77
|
+
Dir.entries(dir).each do |entry|
|
78
|
+
next if entry == "." || entry == ".." # Skip the current and parent directory entries
|
79
|
+
|
80
|
+
path = File.join(dir, entry) # Construct the full path
|
81
|
+
|
82
|
+
if File.directory?(path)
|
83
|
+
remove_empty_directories(path) # Recursively call the method if the entry is a directory
|
84
|
+
# Remove the directory if it's empty after processing its contents
|
85
|
+
Dir.rmdir(path) if Dir.empty?(path)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
rescue Errno::ENOENT
|
89
|
+
# Handle the case where the directory doesn't exist or is removed before rmdir is called
|
90
|
+
puts "Directory not found: #{dir}"
|
91
|
+
end
|
92
|
+
|
93
|
+
# Example usage:
|
94
|
+
# remove_empty_directories('/path/to/directory')
|
95
|
+
|
96
|
+
end
|