rgl 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/ruby1.8
2
+ #
3
+ # dpkg.rb - ruby script dpkg compatible interfaces
4
+ # Copyright (c) 2001 Fumitoshi UKAI <ukai@debian.or.jp>
5
+ #
6
+ # This program is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program; if not, write to the Free Software
18
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ #
20
+ require 'debian'
21
+ require 'getoptlong'
22
+ include Debian
23
+
24
+ require 'rubygems' rescue nil
25
+ require 'rgl/adjacency'
26
+ require 'rgl/implicit'
27
+
28
+ opts = GetoptLong.new(
29
+ ["--list", "-l", GetoptLong::NO_ARGUMENT],
30
+ ["--status", "-s", GetoptLong::NO_ARGUMENT],
31
+ ["--get-selections", GetoptLong::NO_ARGUMENT],
32
+ ["--print-avail", GetoptLong::NO_ARGUMENT],
33
+ ["--listfiles", "-L", GetoptLong::NO_ARGUMENT],
34
+ ["--search", "-S", GetoptLong::NO_ARGUMENT],
35
+ ["--help", "-h", GetoptLong::NO_ARGUMENT])
36
+ opts.ordering = GetoptLong::REQUIRE_ORDER
37
+
38
+ def usage
39
+ puts "Usage:"
40
+ puts " #{$0} --list [<package> ...]"
41
+ puts " #{$0} --status [<package> ...]"
42
+ puts " #{$0} --get-selections [<pattern> ...]"
43
+ puts " #{$0} --print-avail [<package> ...]"
44
+ puts " #{$0} --listfiles [<package> ...]"
45
+ puts " #{$0} --search [<pattern> ...]"
46
+ puts " #{$0} --help"
47
+ end
48
+
49
+ class Debian::Deb
50
+ def each_dependend
51
+ Dpkg.status(["kmail"])
52
+ end
53
+ end
54
+
55
+ def dependency_graph(pattern)
56
+ RGL::ImplicitGraph.new { |g|
57
+ g.vertex_iterator do
58
+ Dpkg.selections(pattern).each_package do |deb|
59
+ b.call(deb.package)
60
+ end
61
+ end
62
+ g.adjacent_iterator do |p, b|
63
+ b.call((x+1)%n)
64
+ end
65
+ g.directed = true
66
+ }
67
+ end
68
+
69
+
70
+
71
+ func = Proc.new {|args| $stderr.puts "#{$0}: need an action option"}
72
+ begin
73
+ opts.each {|opt, arg|
74
+ case opt
75
+ when "--list" then func = Proc.new {|args|
76
+ Dpkg.status(args).each_package {|deb|
77
+ puts [Deb::SELECTION_ID[deb.selection] +
78
+ Deb::STATUS_ID[deb.status] +
79
+ Deb::EFLAG_ID[deb.ok],
80
+ deb.package,
81
+ deb.version,
82
+ deb.description].join(" ")
83
+ }
84
+ }
85
+ when "--status" then func = Proc.new {|args|
86
+ Dpkg.status(args).each_package {|deb|
87
+ puts deb.info_s
88
+ }
89
+ }
90
+ when "--get-selections" then func = Proc.new {|args|
91
+ Dpkg.selections(args).each_package {|deb|
92
+ puts [deb.package, deb.selection].join("\t")
93
+ }
94
+ }
95
+ when "--print-avail" then func = Proc.new {|args|
96
+ Dpkg.avail(args).each_package {|deb|
97
+ puts deb.info_s
98
+ }
99
+ }
100
+ when "--listfiles" then func = Proc.new {|args|
101
+ Dpkg.listfiles(args).each {|dlist|
102
+ puts dlist
103
+ puts
104
+ }
105
+ }
106
+ when "--search" then func = Proc.new {|args|
107
+ Dpkg.search(args).each {|m|
108
+ puts "#{m[0]}: #{m[1]}"
109
+ }
110
+ }
111
+ when "--help" then usage; exit 0
112
+ else raise GetoptLong::InvalidOption
113
+ end
114
+ }
115
+ rescue GetoptLong::InvalidOption
116
+ usage; exit 1
117
+ end
118
+ func.call(ARGV)
@@ -1,6 +1,5 @@
1
1
  # Some graph examples
2
2
 
3
- require 'rubygems' rescue nil
4
3
  require 'rgl/adjacency'
5
4
  require 'rgl/implicit'
6
5
 
@@ -25,6 +24,7 @@ def modulo (n, m)
25
24
  result
26
25
  end
27
26
 
27
+ # Cyclic graph with _n_ vertices
28
28
  def cycle (n)
29
29
  RGL::ImplicitGraph.new { |g|
30
30
  g.vertex_iterator { |b| 0.upto(n-1,&b) }
@@ -33,6 +33,7 @@ def cycle (n)
33
33
  }
34
34
  end
35
35
 
36
+ # Complete Graph with _n_ vertices
36
37
  def complete (n)
37
38
  set = n.integer? ? (1..n) : n
38
39
  RGL::ImplicitGraph.new { |g|
@@ -43,6 +44,7 @@ def complete (n)
43
44
  }
44
45
  end
45
46
 
47
+ # Directed graph of ruby modules. Edges are defined by the method _ancestors_
46
48
  def module_graph
47
49
  RGL::ImplicitGraph.new { |g|
48
50
  g.vertex_iterator { |b|
@@ -57,8 +59,8 @@ def module_graph
57
59
  }
58
60
  end
59
61
 
60
- # divisors(100).dotty
61
- def divisors (n)
62
+ # Shows graph of divisors of all integers from 2 to _n_.
63
+ def divisors(n)
62
64
  RGL::ImplicitGraph.new { |g|
63
65
  g.vertex_iterator { |b| 2.upto(n,&b) }
64
66
  g.adjacent_iterator { |x, b|
@@ -1,52 +1,766 @@
1
1
  digraph RGL__DirectedAdjacencyGraph {
2
2
  label = "RGL__DirectedAdjacencyGraph"
3
- "5" [
3
+ "85" [
4
4
  fontsize = 8,
5
- label = "5"
5
+ label = "85"
6
6
  ]
7
7
 
8
- "6" [
8
+ "9" [
9
9
  fontsize = 8,
10
- label = "6"
10
+ label = "9"
11
11
  ]
12
12
 
13
- "1" [
13
+ "47" [
14
14
  fontsize = 8,
15
- label = "1"
15
+ label = "47"
16
16
  ]
17
17
 
18
- "2" [
18
+ "28" [
19
19
  fontsize = 8,
20
- label = "2"
20
+ label = "28"
21
21
  ]
22
22
 
23
- "3" [
23
+ "66" [
24
24
  fontsize = 8,
25
- label = "3"
25
+ label = "66"
26
26
  ]
27
27
 
28
- "4" [
28
+ "76" [
29
29
  fontsize = 8,
30
- label = "4"
30
+ label = "76"
31
31
  ]
32
32
 
33
- "6" -> "4" [
33
+ "19" [
34
+ fontsize = 8,
35
+ label = "19"
36
+ ]
37
+
38
+ "57" [
39
+ fontsize = 8,
40
+ label = "57"
41
+ ]
42
+
43
+ "38" [
44
+ fontsize = 8,
45
+ label = "38"
46
+ ]
47
+
48
+ "86" [
49
+ fontsize = 8,
50
+ label = "86"
51
+ ]
52
+
53
+ "10" [
54
+ fontsize = 8,
55
+ label = "10"
56
+ ]
57
+
58
+ "48" [
59
+ fontsize = 8,
60
+ label = "48"
61
+ ]
62
+
63
+ "29" [
64
+ fontsize = 8,
65
+ label = "29"
66
+ ]
67
+
68
+ "67" [
69
+ fontsize = 8,
70
+ label = "67"
71
+ ]
72
+
73
+ "77" [
74
+ fontsize = 8,
75
+ label = "77"
76
+ ]
77
+
78
+ "20" [
79
+ fontsize = 8,
80
+ label = "20"
81
+ ]
82
+
83
+ "58" [
84
+ fontsize = 8,
85
+ label = "58"
86
+ ]
87
+
88
+ "39" [
89
+ fontsize = 8,
90
+ label = "39"
91
+ ]
92
+
93
+ "87" [
94
+ fontsize = 8,
95
+ label = "87"
96
+ ]
97
+
98
+ "30" [
99
+ fontsize = 8,
100
+ label = "30"
101
+ ]
102
+
103
+ "68" [
104
+ fontsize = 8,
105
+ label = "68"
106
+ ]
107
+
108
+ "11" [
109
+ fontsize = 8,
110
+ label = "11"
111
+ ]
112
+
113
+ "49" [
114
+ fontsize = 8,
115
+ label = "49"
116
+ ]
117
+
118
+ "78" [
119
+ fontsize = 8,
120
+ label = "78"
121
+ ]
122
+
123
+ "21" [
124
+ fontsize = 8,
125
+ label = "21"
126
+ ]
127
+
128
+ "59" [
129
+ fontsize = 8,
130
+ label = "59"
131
+ ]
132
+
133
+ "40" [
134
+ fontsize = 8,
135
+ label = "40"
136
+ ]
137
+
138
+ "31" [
139
+ fontsize = 8,
140
+ label = "31"
141
+ ]
142
+
143
+ "69" [
144
+ fontsize = 8,
145
+ label = "69"
146
+ ]
147
+
148
+ "12" [
149
+ fontsize = 8,
150
+ label = "12"
151
+ ]
152
+
153
+ "50" [
154
+ fontsize = 8,
155
+ label = "50"
156
+ ]
157
+
158
+ "79" [
159
+ fontsize = 8,
160
+ label = "79"
161
+ ]
162
+
163
+ "41" [
164
+ fontsize = 8,
165
+ label = "41"
166
+ ]
167
+
168
+ "22" [
169
+ fontsize = 8,
170
+ label = "22"
171
+ ]
172
+
173
+ "60" [
174
+ fontsize = 8,
175
+ label = "60"
176
+ ]
177
+
178
+ "32" [
179
+ fontsize = 8,
180
+ label = "32"
181
+ ]
182
+
183
+ "70" [
184
+ fontsize = 8,
185
+ label = "70"
186
+ ]
187
+
188
+ "13" [
189
+ fontsize = 8,
190
+ label = "13"
191
+ ]
192
+
193
+ "51" [
194
+ fontsize = 8,
195
+ label = "51"
196
+ ]
197
+
198
+ "80" [
199
+ fontsize = 8,
200
+ label = "80"
201
+ ]
202
+
203
+ "42" [
204
+ fontsize = 8,
205
+ label = "42"
206
+ ]
207
+
208
+ "23" [
209
+ fontsize = 8,
210
+ label = "23"
211
+ ]
212
+
213
+ "61" [
214
+ fontsize = 8,
215
+ label = "61"
216
+ ]
217
+
218
+ "90" [
219
+ fontsize = 8,
220
+ label = "90"
221
+ ]
222
+
223
+ "14" [
224
+ fontsize = 8,
225
+ label = "14"
226
+ ]
227
+
228
+ "52" [
229
+ fontsize = 8,
230
+ label = "52"
231
+ ]
232
+
233
+ "33" [
234
+ fontsize = 8,
235
+ label = "33"
236
+ ]
237
+
238
+ "71" [
239
+ fontsize = 8,
240
+ label = "71"
241
+ ]
242
+
243
+ "81" [
244
+ fontsize = 8,
245
+ label = "81"
246
+ ]
247
+
248
+ "43" [
249
+ fontsize = 8,
250
+ label = "43"
251
+ ]
252
+
253
+ "24" [
254
+ fontsize = 8,
255
+ label = "24"
256
+ ]
257
+
258
+ "62" [
259
+ fontsize = 8,
260
+ label = "62"
261
+ ]
262
+
263
+ "91" [
264
+ fontsize = 8,
265
+ label = "91"
266
+ ]
267
+
268
+ "15" [
269
+ fontsize = 8,
270
+ label = "15"
271
+ ]
272
+
273
+ "53" [
274
+ fontsize = 8,
275
+ label = "53"
276
+ ]
277
+
278
+ "34" [
279
+ fontsize = 8,
280
+ label = "34"
281
+ ]
282
+
283
+ "72" [
284
+ fontsize = 8,
285
+ label = "72"
286
+ ]
287
+
288
+ "82" [
289
+ fontsize = 8,
290
+ label = "82"
291
+ ]
292
+
293
+ "25" [
294
+ fontsize = 8,
295
+ label = "25"
296
+ ]
297
+
298
+ "63" [
299
+ fontsize = 8,
300
+ label = "63"
301
+ ]
302
+
303
+ "44" [
304
+ fontsize = 8,
305
+ label = "44"
306
+ ]
307
+
308
+ "54" [
309
+ fontsize = 8,
310
+ label = "54"
311
+ ]
312
+
313
+ "35" [
314
+ fontsize = 8,
315
+ label = "35"
316
+ ]
317
+
318
+ "73" [
319
+ fontsize = 8,
320
+ label = "73"
321
+ ]
322
+
323
+ "16" [
324
+ fontsize = 8,
325
+ label = "16"
326
+ ]
327
+
328
+ "83" [
329
+ fontsize = 8,
330
+ label = "83"
331
+ ]
332
+
333
+ "26" [
334
+ fontsize = 8,
335
+ label = "26"
336
+ ]
337
+
338
+ "64" [
339
+ fontsize = 8,
340
+ label = "64"
341
+ ]
342
+
343
+ "45" [
344
+ fontsize = 8,
345
+ label = "45"
346
+ ]
347
+
348
+ "93" [
349
+ fontsize = 8,
350
+ label = "93"
351
+ ]
352
+
353
+ "74" [
354
+ fontsize = 8,
355
+ label = "74"
356
+ ]
357
+
358
+ "36" [
359
+ fontsize = 8,
360
+ label = "36"
361
+ ]
362
+
363
+ "17" [
364
+ fontsize = 8,
365
+ label = "17"
366
+ ]
367
+
368
+ "55" [
369
+ fontsize = 8,
370
+ label = "55"
371
+ ]
372
+
373
+ "84" [
374
+ fontsize = 8,
375
+ label = "84"
376
+ ]
377
+
378
+ "65" [
379
+ fontsize = 8,
380
+ label = "65"
381
+ ]
382
+
383
+ "8" [
384
+ fontsize = 8,
385
+ label = "8"
386
+ ]
387
+
388
+ "46" [
389
+ fontsize = 8,
390
+ label = "46"
391
+ ]
392
+
393
+ "27" [
394
+ fontsize = 8,
395
+ label = "27"
396
+ ]
397
+
398
+ "94" [
399
+ fontsize = 8,
400
+ label = "94"
401
+ ]
402
+
403
+ "75" [
404
+ fontsize = 8,
405
+ label = "75"
406
+ ]
407
+
408
+ "37" [
409
+ fontsize = 8,
410
+ label = "37"
411
+ ]
412
+
413
+ "18" [
414
+ fontsize = 8,
415
+ label = "18"
416
+ ]
417
+
418
+ "56" [
419
+ fontsize = 8,
420
+ label = "56"
421
+ ]
422
+
423
+ "9" -> "11" [
424
+ fontsize = 8
425
+ ]
426
+
427
+ "9" -> "12" [
428
+ fontsize = 8
429
+ ]
430
+
431
+ "47" -> "80" [
432
+ fontsize = 8
433
+ ]
434
+
435
+ "47" -> "81" [
436
+ fontsize = 8
437
+ ]
438
+
439
+ "28" -> "49" [
440
+ fontsize = 8
441
+ ]
442
+
443
+ "28" -> "50" [
444
+ fontsize = 8
445
+ ]
446
+
447
+ "19" -> "31" [
448
+ fontsize = 8
449
+ ]
450
+
451
+ "19" -> "32" [
452
+ fontsize = 8
453
+ ]
454
+
455
+ "38" -> "13" [
456
+ fontsize = 8
457
+ ]
458
+
459
+ "10" -> "13" [
460
+ fontsize = 8
461
+ ]
462
+
463
+ "10" -> "14" [
464
+ fontsize = 8
465
+ ]
466
+
467
+ "48" -> "82" [
468
+ fontsize = 8
469
+ ]
470
+
471
+ "48" -> "83" [
472
+ fontsize = 8
473
+ ]
474
+
475
+ "29" -> "51" [
476
+ fontsize = 8
477
+ ]
478
+
479
+ "29" -> "52" [
480
+ fontsize = 8
481
+ ]
482
+
483
+ "20" -> "33" [
484
+ fontsize = 8
485
+ ]
486
+
487
+ "20" -> "34" [
488
+ fontsize = 8
489
+ ]
490
+
491
+ "39" -> "68" [
492
+ fontsize = 8
493
+ ]
494
+
495
+ "39" -> "69" [
496
+ fontsize = 8
497
+ ]
498
+
499
+ "30" -> "53" [
500
+ fontsize = 8
501
+ ]
502
+
503
+ "30" -> "54" [
504
+ fontsize = 8
505
+ ]
506
+
507
+ "11" -> "16" [
508
+ fontsize = 8
509
+ ]
510
+
511
+ "11" -> "15" [
512
+ fontsize = 8
513
+ ]
514
+
515
+ "21" -> "35" [
516
+ fontsize = 8
517
+ ]
518
+
519
+ "21" -> "36" [
520
+ fontsize = 8
521
+ ]
522
+
523
+ "40" -> "71" [
524
+ fontsize = 8
525
+ ]
526
+
527
+ "40" -> "70" [
528
+ fontsize = 8
529
+ ]
530
+
531
+ "31" -> "55" [
532
+ fontsize = 8
533
+ ]
534
+
535
+ "31" -> "56" [
536
+ fontsize = 8
537
+ ]
538
+
539
+ "12" -> "17" [
540
+ fontsize = 8
541
+ ]
542
+
543
+ "12" -> "18" [
544
+ fontsize = 8
545
+ ]
546
+
547
+ "50" -> "84" [
548
+ fontsize = 8
549
+ ]
550
+
551
+ "50" -> "85" [
552
+ fontsize = 8
553
+ ]
554
+
555
+ "22" -> "38" [
556
+ fontsize = 8
557
+ ]
558
+
559
+ "22" -> "37" [
560
+ fontsize = 8
561
+ ]
562
+
563
+ "32" -> "57" [
564
+ fontsize = 8
565
+ ]
566
+
567
+ "32" -> "58" [
568
+ fontsize = 8
569
+ ]
570
+
571
+ "13" -> "19" [
572
+ fontsize = 8
573
+ ]
574
+
575
+ "13" -> "20" [
576
+ fontsize = 8
577
+ ]
578
+
579
+ "51" -> "86" [
580
+ fontsize = 8
581
+ ]
582
+
583
+ "51" -> "87" [
584
+ fontsize = 8
585
+ ]
586
+
587
+ "42" -> "72" [
588
+ fontsize = 8
589
+ ]
590
+
591
+ "42" -> "73" [
592
+ fontsize = 8
593
+ ]
594
+
595
+ "23" -> "39" [
596
+ fontsize = 8
597
+ ]
598
+
599
+ "23" -> "40" [
600
+ fontsize = 8
601
+ ]
602
+
603
+ "14" -> "22" [
604
+ fontsize = 8
605
+ ]
606
+
607
+ "14" -> "21" [
608
+ fontsize = 8
609
+ ]
610
+
611
+ "33" -> "60" [
612
+ fontsize = 8
613
+ ]
614
+
615
+ "33" -> "59" [
616
+ fontsize = 8
617
+ ]
618
+
619
+ "43" -> "74" [
620
+ fontsize = 8
621
+ ]
622
+
623
+ "43" -> "75" [
624
+ fontsize = 8
625
+ ]
626
+
627
+ "24" -> "41" [
628
+ fontsize = 8
629
+ ]
630
+
631
+ "24" -> "42" [
632
+ fontsize = 8
633
+ ]
634
+
635
+ "15" -> "23" [
636
+ fontsize = 8
637
+ ]
638
+
639
+ "15" -> "24" [
640
+ fontsize = 8
641
+ ]
642
+
643
+ "53" -> "90" [
644
+ fontsize = 8
645
+ ]
646
+
647
+ "53" -> "91" [
648
+ fontsize = 8
649
+ ]
650
+
651
+ "34" -> "61" [
652
+ fontsize = 8
653
+ ]
654
+
655
+ "34" -> "62" [
656
+ fontsize = 8
657
+ ]
658
+
659
+ "25" -> "44" [
660
+ fontsize = 8
661
+ ]
662
+
663
+ "25" -> "43" [
664
+ fontsize = 8
665
+ ]
666
+
667
+ "44" -> "77" [
668
+ fontsize = 8
669
+ ]
670
+
671
+ "44" -> "76" [
672
+ fontsize = 8
673
+ ]
674
+
675
+ "35" -> "63" [
676
+ fontsize = 8
677
+ ]
678
+
679
+ "35" -> "64" [
680
+ fontsize = 8
681
+ ]
682
+
683
+ "16" -> "25" [
684
+ fontsize = 8
685
+ ]
686
+
687
+ "16" -> "26" [
688
+ fontsize = 8
689
+ ]
690
+
691
+ "26" -> "45" [
692
+ fontsize = 8
693
+ ]
694
+
695
+ "26" -> "46" [
696
+ fontsize = 8
697
+ ]
698
+
699
+ "36" -> "66" [
700
+ fontsize = 8
701
+ ]
702
+
703
+ "36" -> "65" [
704
+ fontsize = 8
705
+ ]
706
+
707
+ "17" -> "27" [
708
+ fontsize = 8
709
+ ]
710
+
711
+ "17" -> "28" [
712
+ fontsize = 8
713
+ ]
714
+
715
+ "55" -> "93" [
716
+ fontsize = 8
717
+ ]
718
+
719
+ "55" -> "94" [
720
+ fontsize = 8
721
+ ]
722
+
723
+ "8" -> "9" [
724
+ fontsize = 8
725
+ ]
726
+
727
+ "8" -> "10" [
728
+ fontsize = 8
729
+ ]
730
+
731
+ "46" -> "78" [
732
+ fontsize = 8
733
+ ]
734
+
735
+ "46" -> "79" [
736
+ fontsize = 8
737
+ ]
738
+
739
+ "27" -> "47" [
740
+ fontsize = 8
741
+ ]
742
+
743
+ "27" -> "48" [
744
+ fontsize = 8
745
+ ]
746
+
747
+ "37" -> "67" [
34
748
  fontsize = 8
35
749
  ]
36
750
 
37
- "1" -> "6" [
751
+ "18" -> "29" [
38
752
  fontsize = 8
39
753
  ]
40
754
 
41
- "1" -> "2" [
755
+ "18" -> "30" [
42
756
  fontsize = 8
43
757
  ]
44
758
 
45
- "2" -> "3" [
759
+ "18" -> "31" [
46
760
  fontsize = 8
47
761
  ]
48
762
 
49
- "4" -> "5" [
763
+ "18" -> "32" [
50
764
  fontsize = 8
51
765
  ]
52
766