sakai-info 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,18 @@
1
- sakai-info Change History
2
- =========================
1
+ # sakai-info Change History #
3
2
 
4
- 0.0.0
5
- -----
3
+ ## 0.2.0 ##
6
4
 
7
- *Released 2012-02-??*
5
+ *Released 2012-02-24*
6
+
7
+ * Sequel now used as the database driver, enabling MySQL and Sqlite support
8
+ * Simplified configuration file format
9
+ * CLI tool now provides details on user and site objects
10
+
11
+ ## 0.1.0 ##
12
+
13
+ *Released 2012-02-19*
8
14
 
9
15
  * Initial release
10
16
  * Oracle-only support
11
- * Limited CLI functionality
17
+ * Extremely limited CLI functionality
12
18
 
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
- sakai-info
2
- ==========
1
+ # sakai-info #
3
2
 
4
3
  *sakai-info* is a command line tool and a suite of Ruby libraries which enable
5
4
  the exploration of a Sakai database without the intermediation of a Java VM or
@@ -9,34 +8,31 @@ Because the primary goal of this tool is to assist in information gathering
9
8
  and troubleshooting, no capability to change the database is included in the
10
9
  tool or the libraries.
11
10
 
12
- Meta
13
- ----
14
- last updated: 2012-02-19
15
- author: David Adams (daveadams@gmail.com)
11
+ ## Meta ##
12
+
13
+ last updated: 2012-02-24
14
+ author: David Adams (daveadams@gmail.com)
16
15
  github url: https://github.com/daveadams/sakai-info
17
16
 
18
- Testing
19
- -------
17
+ ## Testing ##
20
18
 
21
19
  Tests are defined in ./test using Test::Unit. The default `rake` action is to
22
20
  run all tests.
23
21
 
24
- Building
25
- --------
22
+ ## Building ##
26
23
 
27
24
  Use `rake` to test and build the gem:
28
25
 
29
26
  $ rake gem:build
30
-
27
+
31
28
  The resulting gem will be saved to the working directory as
32
- `sakai-info-0.1.0.gem`.
29
+ `sakai-info-0.2.0.gem`.
33
30
 
34
31
  Cleanup built gems using:
35
32
 
36
33
  $ rake clean
37
34
 
38
- Installing
39
- ----------
35
+ ## Installing ##
40
36
 
41
37
  Install the *sakai-info* gem locally with:
42
38
 
@@ -46,78 +42,56 @@ Uninstall with:
46
42
 
47
43
  $ rake gem:uninstall
48
44
 
49
- Supported Databases
50
- -------------------
51
-
52
- For this release, only Oracle databases are supported. MySQL support is planned
53
- as soon as possible. Support for SQLite or some other lightweight database may
54
- be implemented for unit testing purposes.
55
-
56
- System Requirements
57
- -------------------
45
+ ## Database Connectivity ##
58
46
 
59
- For Oracle support, the `ruby-oci8` gem is required.
47
+ [Sequel](http://sequel.rubyforge.org) is used for database connectivity. Driver
48
+ gems must also be installed to support whatever database or databases you use.
60
49
 
61
- So far, testing has occurred using Ruby 1.9.1p376 and Ruby 1.9.2p290, with
62
- version 2.0.6 of the `ruby-oci8` gem, on Ubuntu 10.04, against Oracle 11g
63
- R2 versions 11.2.0.1 and 11.2.0.3, using the Oracle Instant Client version
64
- 11.2.0.3.
50
+ Oracle support requires the `ruby-oci8` gem, and MySQL support requires the
51
+ `mysql` gem. Some unit tests make use of the `sqlite3` gem.
65
52
 
66
- Configuration
67
- -------------
53
+ ## Configuration ##
68
54
 
69
55
  To run, *sakai-info* needs to be able to connect to your Sakai database server.
70
56
  It is possible to specify multiple instances to choose from at runtime.
71
57
 
72
58
  In this release, *sakai-info* expects a to find the config in a file located at
73
59
  `$HOME/.sakai-info`. The file must be in YAML format and can contain one or
74
- more Sakai database connection definitions. To define a single database
75
- connection, specify the file like this:
76
-
77
- dbtype: oracle
78
- username: sakai
79
- password: <password>
80
- service: SAKAIPROD
81
- host: oracle.db
82
- port: 1521
83
-
84
- The `port` value is optional, with a default of 1521. If your Oracle setup uses
85
- a `tnsnames.ora` file, then both `host` and `port` can be excluded, and
86
- `service` will be used to find the corresponding `tnsnames.ora` entry.
87
-
88
- Multiple instances may be specified by using the following format:
89
-
90
- default: production
91
- instances:
92
- production:
93
- dbtype: oracle
94
- username: sakai
95
- password: <password>
96
- service: SAKAIPROD
97
- host: oracle.db
98
- port: 1521
99
- test:
100
- dbtype: oracle
101
- username: sakai
102
- password: <password>
103
- service: SAKAITEST
104
-
105
- The `default` key identifies which of the connections under `instances` you
106
- wish to be used in the absence of any explicit specification. Other instances
107
- will be referenced by the corresponding YAML key (eg, `production` and `test`
108
- in the example above).
109
-
110
- Command Line Usage
111
- ------------------
60
+ more Sakai database connection nicknames and connection strings, for example:
61
+
62
+ prod: oracle://sakai:password@SAKAIPROD
63
+ test: mysql://test:password@mysql.host:3307/db_name
64
+
65
+ The first connection in the list is the default connection. Other connections
66
+ may be specified using the corresponding YAML key, which functions as a
67
+ nickname for the connection.
68
+
69
+ [More information on how to specify a Sequel connection string.](http://sequel.rubyforge.org/rdoc/files/doc/opening_databases_rdoc.html)
70
+
71
+ ## Command Line Usage ##
112
72
 
113
73
  After installing the gem, the `sakai-info` program should be found in your
114
- PATH. For this release, very limited functionality is included. For usage
115
- details, run:
74
+ PATH. For usage details, run:
116
75
 
117
76
  $ sakai-info help
118
77
 
119
- Library Usage
120
- -------------
78
+ To look up information about a user, run:
79
+
80
+ $ sakai-info user id
81
+
82
+ For users, `id` can be either the user_id or the eid of the user you want
83
+ details on.
84
+
85
+ Similarly to look up information about a site, run:
86
+
87
+ $ sakai-info site id
88
+
89
+ For sites, `id` is the `site_id` of the desired site.
90
+
91
+ Further details are available for both object types, see the corresponding
92
+ help pages for more information.
93
+
94
+ ## Library Usage ##
121
95
 
122
96
  To use the library in your own Ruby programs, simply specify:
123
97
 
@@ -131,18 +105,16 @@ program.
131
105
  Full RDoc documentation for each class is not available in this release, but is
132
106
  planned for a future release.
133
107
 
134
- Change History
135
- --------------
108
+ ## Change History ##
136
109
 
137
110
  See CHANGELOG.md
138
111
 
139
- Future Plans
140
- ------------
112
+ ## Future Plans ##
141
113
 
142
114
  See ROADMAP.md
143
115
 
144
- License
145
- -------
116
+ ## License ##
117
+
146
118
  This work is dedicated to the public domain. No rights are reserved. See
147
119
  LICENSE for more information.
148
120
 
data/ROADMAP.md CHANGED
@@ -1,14 +1,18 @@
1
- sakai-info Roadmap
2
- ==================
1
+ # sakai-info Roadmap #
3
2
 
4
- *Last updated 2012-02-18 by daveadams@gmail.com*
3
+ *Last updated 2012-02-24*
5
4
 
6
- The most important things to get to after the initial release are:
5
+ ### 0.3 ###
7
6
 
8
- * MySQL support
9
- * Command-line access to all object types, properties, and relationships
10
- understood by the library.
11
- * Full RDoc documentation of the library classes, properties, and methods
7
+ * CLI access to more objects, eg quizzes, tools, assignments, and groups
8
+ * Sqlite test infrastructure for a few basic objects
9
+
10
+ ### 0.5 ###
11
+
12
+ * Test fixtures and basic unit tests for all represented objects
13
+ * RDoc coverage for every class
14
+
15
+ ------
12
16
 
13
17
  Other things on the wishlist for future releases:
14
18
 
@@ -25,13 +29,11 @@ Other things on the wishlist for future releases:
25
29
  * Generalized reporting capabilities
26
30
  * Storage utilization per-site
27
31
  * Session and event statistics
28
- * Metrics on various elements, eg:
29
- * Typical quiz duration
30
- * Quiz/assignment completion rates
31
- * Forum post rates, post length
32
- * etc
33
-
34
- The ultimate dream:
35
-
36
- * A web interface for searching and exploring the database
32
+ * Metrics on various elements
33
+ * Typical quiz duration
34
+ * Quiz/assignment completion rates
35
+ * Forum post rates, post length
36
+ * Additional tools
37
+ * httpd log analysis helper
38
+ * RPC client for Sakai-monitoring servlet
37
39
 
@@ -5,7 +5,7 @@
5
5
  # sakai-info library
6
6
  #
7
7
  # Created 2012-02-15 daveadams@gmail.com
8
- # Last updated 2012-02-19 daveadams@gmail.com
8
+ # Last updated 2012-02-24 daveadams@gmail.com
9
9
  #
10
10
  # https://github.com/daveadams/sakai-info
11
11
  #
@@ -17,63 +17,114 @@ include SakaiInfo
17
17
 
18
18
  require 'sakai-info/cli'
19
19
 
20
- ObjectModes = %w(site user)
20
+ ObjectModes = {
21
+ "site" => Site,
22
+ "user" => User
23
+ }
21
24
 
22
- if ARGV.length > 0
23
- case ARGV[0]
25
+ flags = []
26
+ args = []
27
+ db_name = nil
24
28
 
25
- when "help" then
26
- if ARGV.length > 1
27
- CLI::Help.help ARGV[1]
29
+ while arg = ARGV.shift
30
+ if arg =~ /^-/
31
+ if arg == "-D"
32
+ db_name = ARGV.shift
33
+ elsif arg =~ /^--database=/
34
+ db_name = arg.split("=")[1]
28
35
  else
29
- CLI::Help.help
36
+ flags << arg
30
37
  end
31
- exit
38
+ else
39
+ args << arg
40
+ end
41
+ end
32
42
 
33
- when "version" then
34
- puts VERSION
35
- exit
43
+ if args.length < 1
44
+ STDERR.puts "ERROR: No command was given."
45
+ STDERR.puts "Run '#{File.basename($0)} help' for a list of commands."
46
+ exit 1
47
+ end
36
48
 
37
- when "validate" then
38
- if CLI.validate_config
39
- puts "Configuration OK"
40
- exit
41
- else
42
- exit 1
43
- end
49
+ case args[0]
50
+ when "help" then
51
+ if not args[1].nil?
52
+ CLI::Help.help args[1]
53
+ else
54
+ CLI::Help.help
55
+ end
56
+ exit
44
57
 
45
- when "test" then
46
- STDERR.puts "PENDING: test mode unimplemented"
47
- exit 1
58
+ when "version" then
59
+ puts VERSION
60
+ exit
48
61
 
62
+ when "test" then
63
+ DB.load_config
64
+ success = 0
65
+ failure = 0
66
+ dbs = nil
67
+
68
+ if db_name.nil?
69
+ dbs = DB.databases
49
70
  else
50
- # test to see if it's an accepted object mode
51
- if ObjectModes.include? ARGV[0]
52
- mode = ARGV[0]
53
- ARGV.shift
54
- # continue on
71
+ dbs = { db_name => DB.databases[db_name] }
72
+ end
55
73
 
56
- else
57
- STDERR.puts "ERROR: Command '#{ARGV[0]}' was not recognized."
58
- STDERR.puts "Run 'sakai-info help' for a list of commands."
59
- exit 1
74
+ dbs.each do |nickname, connection_string|
75
+ begin
76
+ print "Trying #{nickname}... "; STDOUT.flush
77
+ db = Sequel.connect(connection_string)
78
+ if db.test_connection
79
+ puts "OK"
80
+ success += 1
81
+ else
82
+ puts "FAIL"
83
+ failure += 1
84
+ end
85
+ rescue => e
86
+ puts "FAIL"
87
+ puts " #{e}"
88
+ failure += 1
60
89
  end
61
90
  end
62
- else
63
- STDERR.puts "ERROR: No command was given."
64
- STDERR.puts "Run 'sakai-info help' for a list of commands."
65
- exit 1
66
- end
67
91
 
68
- exit 1 if not CLI.validate_config
92
+ if failure > 0
93
+ puts "WARNING: Some connections failed"
94
+ exit 1
95
+ else
96
+ puts "OK: All connection tests succeeded"
97
+ exit
98
+ end
69
99
 
70
- if mode == "user"
71
- print "Total users: "; STDOUT.flush
72
- puts User.count
100
+ else
101
+ # test to see if it's an accepted object mode
102
+ if ObjectModes.keys.include? args[0]
103
+ mode = args.shift
104
+ id = args.shift
73
105
 
74
- elsif mode == "site"
75
- print "Total sites: "; STDOUT.flush
76
- puts Site.count
106
+ else
107
+ STDERR.puts "ERROR: Command '#{args[0]}' was not recognized."
108
+ STDERR.puts "Run '#{File.basename($0)} help' for a list of commands."
109
+ exit 1
110
+ end
111
+ end
112
+
113
+ # load database config and set instance to the instance given on the command line
114
+ DB.load_config
115
+ if not db_name.nil?
116
+ DB.default_database = db_name
117
+ end
77
118
 
119
+ if flags.include? "--all"
120
+ serials = ObjectModes[mode].all_serializations
121
+ else
122
+ serials = [:default] + flags.collect{|flag|flag.gsub(/^--/,'').to_sym}
123
+ end
124
+ begin
125
+ puts ObjectModes[mode].find(id).to_yaml(serials)
126
+ rescue ObjectNotFoundException
127
+ STDERR.puts "ERROR: Could not find #{mode} with an ID of '#{id}'"
128
+ exit 1
78
129
  end
79
130
 
@@ -2,7 +2,7 @@
2
2
  # Base library file
3
3
  #
4
4
  # Created 2012-02-15 daveadams@gmail.com
5
- # Last updated 2012-02-19 daveadams@gmail.com
5
+ # Last updated 2012-02-24 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -13,6 +13,7 @@ require 'yaml'
13
13
  require 'json'
14
14
  require 'rexml/document'
15
15
  require 'base64'
16
+ require 'sequel'
16
17
 
17
18
  require 'sakai-info/version'
18
19
 
@@ -30,6 +31,34 @@ module SakaiInfo
30
31
  super("Could not find a #{@classname} object for '#{@identifier}'")
31
32
  end
32
33
  end
34
+
35
+ class Util
36
+ # misc support functions
37
+ FILESIZE_LABELS = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
38
+ def self.format_filesize(i_size)
39
+ size = i_size.to_f
40
+ negative = false
41
+
42
+ if size < 0
43
+ negative = true
44
+ size = -size
45
+ end
46
+
47
+ label = 0
48
+ (FILESIZE_LABELS.size - 1).times do
49
+ if size >= 1024.0
50
+ size = size / 1024.0
51
+ label += 1
52
+ end
53
+ end
54
+
55
+ if size >= 100.0 or label == 0
56
+ "#{negative ? "-" : ""}#{size.to_i.to_s} #{FILESIZE_LABELS[label]}"
57
+ else
58
+ "#{negative ? "-" : ""}#{sprintf("%.1f", size)} #{FILESIZE_LABELS[label]}"
59
+ end
60
+ end
61
+ end
33
62
  end
34
63
 
35
64
  # extensions to other objects
@@ -39,10 +68,8 @@ class String
39
68
  end
40
69
  end
41
70
 
42
- # baseline config and connectivity
43
- require 'sakai-info/instance'
44
- require 'sakai-info/db'
45
- require 'sakai-info/configuration'
71
+ # baseline db connectivity
72
+ require 'sakai-info/database'
46
73
 
47
74
  # base objects
48
75
  require 'sakai-info/sakai_object'