monofile 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e88cadf8ec729be545293368f620f16c44ceac5f
4
- data.tar.gz: 966d876e5864c7573dae3c97978ec9a14b94f34f
3
+ metadata.gz: 460899daff3c93d15ae49ed3163f2c56bb7e15e9
4
+ data.tar.gz: 7b3e215fe00027e3f4b85e107f30029e048b6e35
5
5
  SHA512:
6
- metadata.gz: d74e05bce8932503f5a524d7dde003226ff6798f2406085b0011de019f21809cb926c5e36b33df06fb89af647e48c8bf105168ca34df9b4a175c29a0af7fe2dc
7
- data.tar.gz: e97ef22bd907e3cf08f60eb9d25dd8a1f9180bda845daed17d2312cd88e46659d0b8ec63d218c5fcbbf54903cd9a5f4c5e90e98ea6d23c9cc58ae4f701711faa
6
+ metadata.gz: 6aa5bf5125f770f42d2063d62991779cf7cde8ed06c5752dcd8cd1a3f84556e438b638246884e826951e56219125fafda1e2f00bcb7525fa405f8cc4608996ab
7
+ data.tar.gz: 4b1452d92bd1e7104fe8f918596978661bdbf3997ab9121327e7ed4527269bdc1ac04d3db4007408582710fdaf74a50691cebda387c645127ac3d9f5f983321c
@@ -2,4 +2,6 @@ CHANGELOG.md
2
2
  Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
+ bin/monofile
5
6
  lib/monofile.rb
7
+ lib/monofile/version.rb
data/Rakefile CHANGED
@@ -1,8 +1,10 @@
1
1
  require 'hoe'
2
+ require './lib/monofile/version.rb'
3
+
2
4
 
3
5
  Hoe.spec 'monofile' do
4
6
 
5
- self.version = '0.0.1' # note: for now add version inline
7
+ self.version = Mono::Module::Monofile::VERSION
6
8
 
7
9
  self.summary = "monofile - read in/ parse mono (source) tree defintions with git (and github) projects, and more"
8
10
  self.description = summary
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ###################
4
+ # DEV TIPS:
5
+ #
6
+ # For local testing run like:
7
+ #
8
+ # ruby -Ilib bin/monofile
9
+ #
10
+ # Set the executable bit in Linux. Example:
11
+ #
12
+ # % chmod a+x bin/monofile
13
+ #
14
+
15
+ require 'monofile'
16
+
17
+ Monofile::Tool.main
@@ -1,2 +1,336 @@
1
- # to be done
1
+ ##
2
+ ## "prelude / prolog " add some common used stdlibs
3
+ ## add more - why? why not?
4
+ require 'pp'
5
+ require 'time'
6
+ require 'date'
7
+ require 'json'
8
+ require 'yaml'
9
+ require 'fileutils'
10
+
11
+ require 'uri'
12
+ require 'net/http'
13
+ require 'net/https'
14
+
15
+
16
+ require 'optparse'
17
+
18
+
19
+
20
+ #####################
21
+ # our own code
22
+ require 'monofile/version' # note: let version always go first
23
+
24
+
25
+
26
+
27
+ module Mono
28
+
29
+ def self.root ## root of single (monorepo) source tree
30
+ @@root ||= begin
31
+ ## todo/fix:
32
+ ## check if windows - otherwise use /sites
33
+ ## check if root directory exists?
34
+ if ENV['MOPATH']
35
+ ## use expand path to make (assure) absolute path - why? why not?
36
+ File.expand_path( ENV['MOPATH'] )
37
+ elsif Dir.exist?( 'C:/Sites' )
38
+ 'C:/Sites'
39
+ else
40
+ '/sites'
41
+ end
42
+ end
43
+ end
44
+
45
+ def self.root=( path )
46
+ ## use expand path to make (assure) absolute path - why? why not?
47
+ @@root = File.expand_path( path )
48
+ end
49
+
50
+
51
+
52
+ def self.monofile
53
+ path = Monofile.find
54
+ Monofile.read( path )
55
+
56
+ # if path
57
+ # GitRepoSet.read( path )
58
+ # else
59
+ # puts "!! WARN: no mono configuration file found; looking for #{MONOFILES.join(', ')} in (#{Dir.getwd})"
60
+ # GitRepoSet.new( {} ) ## return empty set -todo/check: return nil - why? why not?
61
+ # end
62
+ end
63
+ end ## module Mono
64
+
65
+
66
+
67
+
68
+
69
+ class Monofile
70
+ ## holds a list of projects
71
+
72
+ ## nested class
73
+ class Project
74
+
75
+ ## use some different names / attributes ??
76
+ attr_reader :org, ## todo/check: find a different name (or add alias e.g. login/user/etc.)
77
+ :name
78
+
79
+ ## todo/fix:
80
+ ## - use *args and than split if args==2 or args==1 etc.
81
+ def initialize( *args )
82
+ if args.size == 2 && args[0].is_a?(String) && args[1].is_a?(String)
83
+ ## assume [org, name]
84
+ @org = args[0]
85
+ @name = args[1]
86
+ elsif args.size == 1 && args[0].is_a?( String )
87
+ ## todo/fix: use norm_name parser or such!!!!
88
+ parts = args[0].split( '/' )
89
+ @org = parts[0][1..-1] ## cut-off leading @ (always assume for now!!)
90
+ @name = parts[1]
91
+ else
92
+ raise ArgumentError, "[Monorepo::Project] one or two string args expected; got: #{args.pretty_inspect}"
93
+ end
94
+ end
95
+
96
+ def to_s() "@#{org}/#{name}"; end
97
+ def to_path() "#{org}/#{name}"; end
98
+
99
+ ## add clone_ssh_url or such too!!!!
100
+ end ## (nested) class Project
101
+
102
+
103
+
104
+ class Builder ## "clean room" pattern/spell - keep accessible methods to a minimum (by eval in "cleanroom")
105
+ def initialize( monofile )
106
+ @monofile = monofile
107
+ end
108
+
109
+ def project( *args )
110
+ project = Project.new( *args )
111
+ @monofile.projects << project
112
+ end
113
+ end # (nested) class Builder
114
+
115
+
116
+
117
+ RUBY_NAMES = ['monofile',
118
+ 'Monofile',
119
+ 'monofile.rb',
120
+ 'Monofile.rb',
121
+ ]
122
+
123
+ TXT_NAMES = ['monofile.txt',
124
+ 'monotree.txt', ## keep monotree - why? why not?
125
+ 'monorepo.txt',
126
+ 'repos.txt']
127
+
128
+ ## note: yaml always requires an extension
129
+ YML_NAMES = ['monofile.yml', 'monofile.yaml',
130
+ 'monotree.yml', 'monotree.yaml', ## keep monotree - why? why not?
131
+ 'monorepo.yml', 'monorepo.yaml',
132
+ 'repos.yml', 'repos.yaml',
133
+ ] ## todo/check: add mono.yml too - why? why not?
134
+
135
+ NAMES = RUBY_NAMES + TXT_NAMES + YML_NAMES
136
+
137
+
138
+ def self.find
139
+ RUBY_NAMES.each do |name|
140
+ return "./#{name}" if File.exist?( "./#{name}")
141
+ end
142
+
143
+ TXT_NAMES.each do |name|
144
+ return "./#{name}" if File.exist?( "./#{name}")
145
+ end
146
+
147
+ YML_NAMES.each do |name|
148
+ return "./#{name}" if File.exist?( "./#{name}")
149
+ end
150
+
151
+ nil ## no monofile found; return nil
152
+ end
153
+
154
+
155
+ def self.read( path )
156
+ txt = File.open( path, 'r:utf-8') { |f| f.read }
157
+
158
+ ## check for yml or yaml extension;
159
+ ## or for txt extension; otherwise assume ruby
160
+ extname = File.extname( path ).downcase
161
+ if ['.yml', '.yaml'].include?( extname )
162
+ hash = YAML.load( txt )
163
+ new( hash )
164
+ elsif ['.txt'].include?( extname )
165
+ new( txt )
166
+ else ## assume ruby code (as text in string)
167
+ new().load( txt )
168
+ end
169
+ end
170
+
171
+
172
+
173
+ def self.load( code )
174
+ monofile = new
175
+ monofile.load( code )
176
+ monofile
177
+ end
178
+
179
+ def self.load_file( path ) ## keep (or add load_yaml to or such) - why? why not?
180
+ code = File.open( path, 'r:utf-8') { |f| f.read }
181
+ load( code )
182
+ end
183
+
184
+
185
+ ### attr readers
186
+ def projects() @projects; end
187
+ def size() @projects.size; end
188
+
189
+
190
+ def initialize( obj={} ) ## todo/fix: change default to obj=[]
191
+ @projects = []
192
+
193
+ ## puts "[debug] obj.class=#{obj.class.name}"
194
+ add( obj )
195
+ end
196
+
197
+ def load( code ) ## note: code is text as a string
198
+ builder = Builder.new( self )
199
+ builder.instance_eval( code )
200
+ self ## note: for chaining always return self
201
+ end
202
+
203
+
204
+ def add( obj )
205
+ ## todo/check: check for proc too! and use load( proc/block ) - possible?
206
+ if obj.is_a?( String )
207
+ puts "sorry add String - to be done!!!"
208
+ exit 1
209
+ elsif obj.is_a?( Array )
210
+ puts "sorry add Array- to be done!!!"
211
+ exit 1
212
+ elsif obj.is_a?( Hash )
213
+ add_hash( obj )
214
+ else ## assume text (evaluate/parse)
215
+ puts "sorry add Text - to be done!!!"
216
+ exit 1
217
+ end
218
+ self ## note: return self for chaining
219
+ end
220
+
221
+
222
+ def add_hash( hash )
223
+ hash.each do |org_with_counter, names|
224
+
225
+ ## remove optional number from key e.g.
226
+ ## mrhydescripts (3) => mrhydescripts
227
+ ## footballjs (4) => footballjs
228
+ ## etc.
229
+
230
+ ## todo/check: warn about duplicates or such - why? why not?
231
+
232
+ org = org_with_counter.sub( /\([0-9]+\)/, '' ).strip.to_s
233
+
234
+ names.each do |name|
235
+ @projects << Project.new( org, name )
236
+ end
237
+ end
238
+
239
+ self ## note: return self for chaining
240
+ end
241
+
242
+
243
+
244
+ def each( &block )
245
+ ## puts "[debug] arity: #{block.arity}"
246
+
247
+ ## for backwards compatibility support "old" each with/by org & names
248
+ ## add deprecated warnings and use to_h or such - why? why not?
249
+ if block.arity == 2
250
+ puts "!! DEPRECATED - please, use Monofile#to_h or Monofile.each {|proj| ...}"
251
+ to_h.each do |org, names|
252
+ block.call( org, names )
253
+ end
254
+ else
255
+ ## assume just regular
256
+ @projects.each do |project|
257
+ block.call( project )
258
+ end
259
+ end
260
+ end # method each
261
+
262
+ def each_with_index( &block )
263
+ @projects.each_with_index do |project,i|
264
+ block.call( project, i )
265
+ end
266
+ end
267
+
268
+
269
+
270
+ ### for backward compat(ibility) add a hash in the form e.g:
271
+ ##
272
+ ## geraldb:
273
+ ## - austria
274
+ ## - catalog
275
+ ## - geraldb.github.io
276
+ ## - logos
277
+ ## yorobot:
278
+ ## - auto
279
+ ## - backup
280
+ ## - football.json
281
+ ## - logs
282
+ ##
283
+ def to_h
284
+ h = {}
285
+ @projects.each do |project|
286
+ h[ project.org ] ||= []
287
+ h[ project.org ] << project.name
288
+ end
289
+ h
290
+ end
291
+
292
+ def to_a
293
+ ## todo/check:
294
+ ## - sort all entries a-z - why? why not?
295
+ ## - always start name with @ marker - why? why not?
296
+ @projects.map {|project| project.to_s }
297
+ end
298
+ end # class Monofile
299
+
300
+
301
+
302
+
303
+
304
+ class Monofile
305
+ class Tool
306
+ def self.main( args=ARGV )
307
+
308
+ path = Monofile.find
309
+ if path.nil?
310
+ puts "!! ERROR: no mono configuration file found; looking for #{Monofile::NAMES.join(', ')} in (#{Dir.getwd})"
311
+ exit 1
312
+ end
313
+
314
+ ## add check for auto-require (e.g. ./config.rb)
315
+ config_path = "./config.rb"
316
+ if File.exist?( config )
317
+ puts "[monofile] auto-require >#{config_path}<..."
318
+ require( config_path )
319
+ end
320
+
321
+ puts "[monofile] reading >#{path}<..."
322
+ monofile=Monofile.read( path )
323
+ pp monofile
324
+
325
+ ## print one project per line
326
+ puts "---"
327
+ monofile.each do |proj|
328
+ puts proj.to_s
329
+ end
330
+ end
331
+ end # (nested) class Tool
332
+ end # class Monofile
333
+
334
+
335
+ Mono::Module::Monofile.banner
2
336
 
@@ -0,0 +1,28 @@
1
+
2
+ module Mono
3
+ module Module
4
+ module Monofile
5
+
6
+ MAJOR = 0 ## todo: namespace inside version or something - why? why not??
7
+ MINOR = 1
8
+ PATCH = 0
9
+ VERSION = [MAJOR,MINOR,PATCH].join('.')
10
+
11
+ def self.version
12
+ VERSION
13
+ end
14
+
15
+ def self.banner
16
+ "monofile/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
17
+ end
18
+
19
+ ## note: move root to its own namespace to avoid
20
+ ## conflict with Mono.root!!!!
21
+ def self.root
22
+ File.expand_path( File.dirname(File.dirname(__FILE__) ))
23
+ end
24
+
25
+ end # module Monofile
26
+ end # module Module
27
+ end # module Mono
28
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monofile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
@@ -47,7 +47,8 @@ dependencies:
47
47
  description: monofile - read in/ parse mono (source) tree defintions with git (and
48
48
  github) projects, and more
49
49
  email: opensport@googlegroups.com
50
- executables: []
50
+ executables:
51
+ - monofile
51
52
  extensions: []
52
53
  extra_rdoc_files:
53
54
  - CHANGELOG.md
@@ -58,7 +59,9 @@ files:
58
59
  - Manifest.txt
59
60
  - README.md
60
61
  - Rakefile
62
+ - bin/monofile
61
63
  - lib/monofile.rb
64
+ - lib/monofile/version.rb
62
65
  homepage: https://github.com/rubycoco/git
63
66
  licenses:
64
67
  - Public Domain