kit 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ CREATE TABLE clones (
2
+ "site" INTEGER NOT NULL,
3
+ "status" TEXT NOT NULL DEFAULT ('pending'),
4
+ "src" INTEGER NOT NULL
5
+ );
6
+ CREATE TABLE upgrades (
7
+ "site" INTEGER NOT NULL,
8
+ "status" TEXT NOT NULL DEFAULT ('pending'),
9
+ "component" TEXT NOT NULL,
10
+ "file" TEXT NOT NULL
11
+ );
12
+ CREATE TABLE commits (
13
+ "site" INTEGER NOT NULL,
14
+ "status" TEXT NOT NULL DEFAULT ('pending'),
15
+ "requested_commit" TEXT
16
+ );
@@ -0,0 +1,17 @@
1
+ module Actions
2
+
3
+ private
4
+ def rsync
5
+ # puts "rsync go!"
6
+ end
7
+
8
+ def clones options
9
+ src = Site.new options[:src]
10
+ # fail ProjectMismatch unless @project_id == src.project_id
11
+
12
+ puts "cloning #{src.project_name}.#{src.name} to #{@project_name}.#{@name}"
13
+
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,7 @@
1
+ module Actions
2
+
3
+ def commits options
4
+ puts "commiting"
5
+ end
6
+
7
+ end
@@ -0,0 +1,8 @@
1
+ module Actions
2
+
3
+ def upgrades options
4
+ puts "upgrading"
5
+
6
+ end
7
+
8
+ end
@@ -0,0 +1,16 @@
1
+ DB_BACKEND = :sqlite3
2
+ DB_CONFIG = {
3
+ :info => "info.db",
4
+ :actions => "actions.db"
5
+ }
6
+ INFO = {
7
+ :sites => [ :rowid, :name, :project, :root, :commit, :commit_time ],
8
+ :projects => [ :rowid, :name, :git ]
9
+ }
10
+ ACTIONS = {
11
+ :clones => [ :rowid, :status, :src, :site ],
12
+ :upgrades => [ :rowid, :status, :site, :component, :file ],
13
+ :commits => [ :rowid, :status, :site, :requested_commit ]
14
+ }
15
+ ACTIONS_PATH = "./actions"
16
+ NAME = "devel"
@@ -0,0 +1,111 @@
1
+ require 'sqlite3'
2
+
3
+ module SQLite3Tools
4
+ class ::Array
5
+ def sqlite3_to_str
6
+ self.map { |sym| "`" + sym.to_s + "`" }.join(", ")
7
+ end
8
+ end
9
+
10
+ class ::Array
11
+ def to_hash other
12
+ Hash[ *( 0...self.size() ).inject( [] ) { |arr, ix| arr.push( other[ix], self[ix] ) } ]
13
+ end
14
+ end
15
+
16
+ class SQLite3::Database
17
+ def select columns, query
18
+ result = [];
19
+ self.execute "SELECT #{columns.sqlite3_to_str} #{query}" do |row|
20
+ result.push ( row.to_hash columns )
21
+ end
22
+ result
23
+ end
24
+ end
25
+ end
26
+
27
+ class Backend < SiteManager
28
+
29
+ include SQLite3Tools
30
+
31
+ def initialize db_paths
32
+ dbs = db_prepare db_paths
33
+ @info_db = dbs[:info]
34
+ @action_db = dbs[:actions]
35
+ end
36
+
37
+ private
38
+ def db_prepare db_paths
39
+
40
+ def db_initialize type, db
41
+ sql = File.read "#{type}.sql"
42
+ db.execute_batch sql
43
+ end
44
+
45
+ dbs = {}
46
+ db_paths.each do |type, path|
47
+ dbs[type] = [ ( File.exists? path ), ( SQLite3::Database.new path ) ]
48
+ end
49
+
50
+ # Set sqlite3 options here
51
+ dbs.each do |type, db|
52
+ db[1].type_translation = true
53
+ end
54
+
55
+ dbs.each do |type, db|
56
+ begin
57
+ ( db_initialize type, db[1] ) unless db[0]
58
+ rescue
59
+ File.delete db_paths[type]
60
+ end
61
+ end
62
+
63
+ dbs.each do |type, db|
64
+ dbs[type] = db[1]
65
+ end
66
+
67
+ return dbs
68
+
69
+ end
70
+
71
+ private
72
+ def make_placeholders n
73
+ n = n - 1
74
+ placeholders = "?"
75
+ n.times { placeholders << ", ?" }
76
+ placeholders
77
+ end
78
+
79
+ public
80
+ def select_all_actions_by_status action, fields, status
81
+ query = "FROM `#{action}` WHERE `status` = '#{status}'"
82
+ rows = @action_db.select fields, query
83
+
84
+ h = { :action => action }
85
+ rows.map { |t| t.merge h }
86
+ end
87
+
88
+ def insert_action table, data
89
+ @action_db.execute "INSERT INTO #{table} VALUES ( ?, #{make_placeholders data.length} )", ( data.values.insert 1, "pending" )
90
+ @action_db.last_insert_row_id
91
+ end
92
+
93
+ def delete_action_by_id action, id
94
+ # puts "DELETE FROM `#{action}` WHERE `rowid` = #{id}"
95
+ end
96
+
97
+ def select_info_by_id table, fields, id
98
+ info = @info_db.select fields, "FROM `#{table}` WHERE `rowid` = '#{id}'"
99
+ info.first
100
+ end
101
+
102
+ def select_info_by_name table, fields, name
103
+ info = @info_db.select fields, "FROM `#{table}` WHERE `name` = '#{name}'"
104
+ info.first
105
+ end
106
+
107
+ def insert_info table, data
108
+ @info_db.execute "INSERT INTO #{table} VALUES ( #{make_placeholders data.length} )", data.values
109
+ @info_db.last_insert_row_id
110
+ end
111
+ end
@@ -0,0 +1,15 @@
1
+ CREATE TABLE "permissions" (
2
+ "name" INTEGER NOT NULL,
3
+ "site" INTEGER NOT NULL
4
+ );
5
+ CREATE TABLE projects (
6
+ "name" TEXT NOT NULL,
7
+ "git" TEXT NOT NULL
8
+ );
9
+ CREATE TABLE sites (
10
+ "name" TEXT NOT NULL,
11
+ "project" INTEGER NOT NULL,
12
+ "root" TEXT NOT NULL,
13
+ "commit" TEXT,
14
+ "commit_time" INTEGER
15
+ );
@@ -0,0 +1,35 @@
1
+ class Site
2
+
3
+ def insert_new
4
+ @project_id = insert_new_project unless @project_id
5
+
6
+ data = { :name => @name, :project => @project_id, :root => @root, :commit => nil, :commit_time => nil }
7
+ @@db.insert_info :sites, data
8
+ end
9
+
10
+ def insert_new_project
11
+
12
+ fail DuplicateAttr if @@db.select_info_by_name :projects, [ :name ], @project_name
13
+
14
+ data = { :project => @project_name, :git => @git }
15
+ @@db.insert_info :projects, data
16
+ end
17
+
18
+ def load_info
19
+
20
+ info = @@db.select_info_by_id :sites, @@info[:sites], @id
21
+
22
+ @name = info[:name]
23
+ @project_id = info[:project]
24
+
25
+ project_info = @@db.select_info_by_id :projects, @@info[:projects], @project_id
26
+ info.merge! project_info
27
+
28
+ @project_name = info[:name]
29
+ @root = info[:root]
30
+ @git = info[:git_path]
31
+ @commit = { :name => info[:commit], :time => info[:commit_time] }
32
+
33
+ end
34
+
35
+ end
data/site.rb ADDED
@@ -0,0 +1,80 @@
1
+ class Site < SiteManager
2
+
3
+ attr_reader :id
4
+
5
+ def initialize info
6
+
7
+ if info.is_a? Integer
8
+ @id = info
9
+ else
10
+ make_ivars info
11
+ @id = insert_new
12
+ end
13
+
14
+ load_info
15
+
16
+ end
17
+
18
+ def make_ivars hash
19
+ hash.each do |ivar, val|
20
+ self.class.send :attr_accessor, ivar unless respond_to? ivar
21
+ send "#{ivar}=", val
22
+ end
23
+ end
24
+
25
+ # Add a task to the array of pending tasks in @tasks.
26
+ #
27
+ # ==== Attributes
28
+ #
29
+ # * +task+ - Hash that describes the task. Must contain the keys :rowid and :action.
30
+ #
31
+ # ==== Examples
32
+ #
33
+ # Adding a task to clone site 2 from site 1
34
+ #
35
+ # s = Site.new 42
36
+ # t = {:rowid=>1, :src=>1, :site=>2, :action=>:clones}
37
+ # s.add_task t
38
+ def add_task task
39
+ @tasks = [] unless @tasks
40
+ @tasks << task
41
+ end
42
+
43
+ # Removes a task from list of pending tasks in @tasks
44
+ #
45
+ # ==== Attributes
46
+ #
47
+ # * +task+ - Hash that describes the task. Must contain the keys :rowid and :action.
48
+ #
49
+ # ==== Examples
50
+ #
51
+ # Removing a task to clone site 2 from site 1
52
+ #
53
+ # s = Site.new 42
54
+ # t = {:rowid=>1, :src=>1, :site=>2, :action=>:clones}
55
+ # s.clear_task t
56
+ def clear_task task
57
+
58
+ action = task[:action]
59
+ id = task[:rowid]
60
+
61
+ @@db.delete_action_by_id action, id
62
+ end
63
+
64
+ # Runs all tasks in the list of pending tasks in @tasks. Removes the task on sucess or BadTask.
65
+ def run_all
66
+
67
+ tasks = @tasks
68
+
69
+
70
+ tasks.each do |t|
71
+ self.send t[:action], t
72
+ clear_task t
73
+ end
74
+ end
75
+
76
+ class DuplicateAttr < RuntimeError
77
+ end
78
+
79
+ end
80
+
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Evan Boyd Sosenko
@@ -27,7 +27,20 @@ extensions: []
27
27
  extra_rdoc_files: []
28
28
 
29
29
  files:
30
+ - info.sql
31
+ - actions.sql
32
+ - ./info/devel.rb
33
+ - ./site_manager.rb
34
+ - ./actions/commits/otr.rb
35
+ - ./actions/clones/otr.rb
36
+ - ./actions/upgrades/otr.rb
37
+ - ./config.rb
38
+ - ./db_sqlite3.rb
39
+ - ./site.rb
30
40
  - site_manager.rb
41
+ - config.rb
42
+ - db_sqlite3.rb
43
+ - site.rb
31
44
  has_rdoc: true
32
45
  homepage:
33
46
  licenses: