phper 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.5.0
data/lib/phper/agent.rb CHANGED
@@ -107,6 +107,21 @@ class Phper::Agent
107
107
  count
108
108
  end
109
109
 
110
+ def hosts project
111
+ get("/projects/%s/hosts" % project)
112
+ end
113
+
114
+ def files project,host,name = nil
115
+ if name
116
+ get("/projects/%s/hosts/%s/files/%s" % [project,host,encode(name)])
117
+ else
118
+ get("/projects/%s/hosts/%s/files" % [project,host])
119
+ end
120
+ end
121
+
122
+
123
+
124
+
110
125
 
111
126
  def post(url,data = {},format=:json)
112
127
  call(:post,url,data,format)
data/lib/phper/cli.rb CHANGED
@@ -9,7 +9,8 @@ class Phper::CLI < CommandLineUtils::CLI
9
9
  yield self if block_given?
10
10
  end
11
11
  def dispatch(cmd,cmd_argv)
12
- @commands.send(cmd.sub(/:/,"_"))
12
+ raise "Unknown command. #{cmd}" unless @commands.commands.include?(cmd)
13
+ @commands.send(cmd.gsub(/:/,"_"))
13
14
  end
14
15
  def version
15
16
  File.open(File.join(File.dirname(__FILE__) ,
@@ -1,15 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
3
  require 'phper'
4
+ require "parsedate"
5
+ require "time"
4
6
 
5
7
  class Phper::Commands < CommandLineUtils::Commands
6
8
  include Phper
9
+ attr_reader :commands
7
10
  def initialize
8
11
  super
9
12
  @commands += ["login","logout","list","create","destroy","info"]
10
13
  @commands += ["keys","keys:add","keys:remove","keys:clear"]
11
14
  @commands += ["servers","servers:add","servers:remove"]
12
15
  @commands += ["open","db:init","deploy"]
16
+ @commands += ["hosts"]
17
+ @commands += ["files","files:dump","files:get"]
18
+ @commands += ["files:modified","files:modified:get"]
13
19
 
14
20
  @agent = Agent.new
15
21
  # @cache_file = homedir + "/.phper.cache"
@@ -341,10 +347,147 @@ class Phper::Commands < CommandLineUtils::Commands
341
347
  project["project"]["dbname"]]
342
348
  end
343
349
 
350
+ def hosts
351
+ project = nil
352
+ OptionParser.new { |opt|
353
+ project = extract_project(opt)
354
+ @summery = "list project hosts"
355
+ return opt if @help
356
+ }
357
+ raise "project is not specified." unless project
358
+ start
359
+ @agent.hosts(project).each { |host|
360
+ puts "%s" % [host["host"]["id"]]
361
+ }
344
362
 
363
+ end
364
+
365
+ def files
366
+ project = nil
367
+ params = {}
368
+ OptionParser.new { |opt|
369
+ opt.on('-h HOST','--host=HOST', 'host') { |v|
370
+ params[:host] = v
371
+ }
372
+ project = extract_project(opt)
373
+ @summery = "list project files"
374
+ return opt if @help
375
+ }
376
+ raise "project is not specified." unless project
377
+ start
378
+ unless params[:host]
379
+ host = @agent.hosts(project).first
380
+ params[:host] = host["host"]["id"]
381
+ end
382
+ raise "project has no hosts" unless params[:host]
383
+
384
+ @agent.files(project,params[:host]).each { |file|
385
+ puts "%s" % [file["file"]["name"]]
386
+ }
387
+ end
388
+
389
+ def files_get
390
+ @summery = "get and put file."
391
+ return files_get_one if @help
392
+ file = files_get_one
393
+ file_put(file)
394
+ end
395
+
396
+ def files_dump
397
+ @summery = "dump file."
398
+ return files_get_one if @help
399
+ file = files_get_one
400
+ puts file["file"]["contents"]
401
+ end
402
+
403
+ def files_modified
404
+ @summery = "list modified files since last deploy."
405
+ return file_get_modified if @help
406
+ file_get_modified.each { |file|
407
+ puts "%s" % [file["file"]["name"]]
408
+ }
409
+ end
410
+
411
+ def files_modified_get
412
+ @summery = "get modified files since last deploy."
413
+ return file_get_modified if @help
414
+ file_get_modified.each { |file|
415
+ file = @agent.files(@project,@params[:host],file["file"]["name"])
416
+ file_put(file)
417
+ }
418
+ end
419
+
345
420
 
346
421
  private
347
422
 
423
+ def file_get_modified
424
+ @params ||= {}
425
+ OptionParser.new { |opt|
426
+ opt.on('-h HOST','--host=HOST', 'host') { |v|
427
+ @params[:host] = v
428
+ }
429
+ @project = extract_project(opt)
430
+ return opt if @help
431
+ }
432
+ raise "project is not specified." unless @project
433
+ start
434
+ unless @params[:host]
435
+ host = @agent.hosts(@project).first
436
+ @params[:host] = host["host"]["id"]
437
+ end
438
+ raise "project has no hosts" unless @params[:host]
439
+ files = @agent.files(@project,@params[:host])
440
+ modified(files)
441
+ end
442
+
443
+ def file_put file
444
+ name = file["file"]["name"]
445
+ raise "Not in under git." unless in_git?
446
+
447
+ name = File.join(git_root,name)
448
+ FileUtils.mkdir_p(File.dirname(name))
449
+ File.open(name,"w"){ |f|
450
+ f.write file["file"]["contents"]
451
+ }
452
+ puts "--> " + file["file"]["name"]
453
+ end
454
+
455
+
456
+ def files_get_one
457
+ project = nil
458
+ params = {}
459
+ OptionParser.new { |opt|
460
+ opt.on('-h HOST','--host=HOST', 'host') { |v|
461
+ params[:host] = v
462
+ }
463
+ @banner = "<filename>"
464
+ project = extract_project(opt)
465
+ return opt if @help
466
+ }
467
+ raise "project is not specified." unless project
468
+ file = @command_options.shift
469
+ raise "file is not specified." unless project
470
+
471
+ start
472
+ unless params[:host]
473
+ host = @agent.hosts(project).first
474
+ params[:host] = host["host"]["id"]
475
+ end
476
+ raise "project has no hosts" unless params[:host]
477
+ @agent.files(project,params[:host],file)
478
+ end
479
+
480
+ def modified files
481
+ marker = files.find { |file|
482
+ file["file"]["name"] == ".phper.deployed"
483
+ }
484
+ "missing marker .phper.deployed file in this host" unless marker
485
+ marker_mtime = Time.parse(marker["file"]["mtime"])
486
+ files.collect { |file|
487
+ file if Time.parse(file["file"]["mtime"]) > marker_mtime
488
+ }.compact
489
+ end
490
+
348
491
  def extract_project opt
349
492
  @banner = [@banner,"[--project=<project>]"].join(" ")
350
493
  project = nil
data/lib/phper.rb CHANGED
@@ -50,6 +50,17 @@ module Phper
50
50
  return root
51
51
  end
52
52
 
53
+ def encode(str,salt=".")
54
+ enc = OpenSSL::Cipher::Cipher.new('aes256')
55
+ enc.encrypt.pkcs5_keyivgen(salt)
56
+ ((enc.update(str) + enc.final).unpack("H*")).to_s
57
+ end
58
+
59
+ def decode(str,salt=".")
60
+ dec = OpenSSL::Cipher::Cipher.new('aes256')
61
+ dec.decrypt.pkcs5_keyivgen(salt)
62
+ (dec.update(Array.new([str]).pack("H*")) + dec.final)
63
+ end
53
64
 
54
65
  end
55
66
  require "rubygems"
data/phper.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{phper}
8
- s.version = "0.4.1"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Yoshihiro TAKAHARA"]
12
- s.date = %q{2011-02-25}
12
+ s.date = %q{2011-02-28}
13
13
  s.default_executable = %q{phper}
14
14
  s.description = %q{phper}
15
15
  s.email = %q{y.takahara@gmail.com}
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 1
10
- version: 0.4.1
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Yoshihiro TAKAHARA
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-25 00:00:00 +09:00
18
+ date: 2011-02-28 00:00:00 +09:00
19
19
  default_executable: phper
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency