1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-30 08:53:05 +00:00

translate Sync.rb

This commit is contained in:
nishiki 2014-01-15 23:09:57 +01:00
parent 0598ec134f
commit 1a9fb07950
3 changed files with 34 additions and 9 deletions

View file

@ -17,6 +17,10 @@ en:
read: "Can't import, unable to read %{file}!" read: "Can't import, unable to read %{file}!"
update: update:
name_empty: "You must define a name!" name_empty: "You must define a name!"
sync:
no_data: "Nothing data!"
not_authorized: "You haven't the access to remote file!"
unknown: "An unknown error is occured!"
cli: cli:
option: option:
usage: "Usage" usage: "Usage"

View file

@ -17,6 +17,10 @@ fr:
read: "Impossible d'importer le fichier %{file}, car il n'est pas lisible!" read: "Impossible d'importer le fichier %{file}, car il n'est pas lisible!"
update: update:
name_empty: "Vous devez définir un nom!" name_empty: "Vous devez définir un nom!"
sync:
no_data: "Aucune data!"
not_authorized: "Vous n'avez pas les autorisations d'accès au fichier distant!"
unknown: "Une erreur inconnue est survenue!"
cli: cli:
option: option:
usage: "Utilisation" usage: "Utilisation"

View file

@ -14,14 +14,23 @@ class Sync
attr_accessor :error_msg attr_accessor :error_msg
# Constructor
def initialize() def initialize()
@error_msg = nil @error_msg = nil
end end
# Disable the sync
def disable() def disable()
@sync = false @sync = false
end end
# Connect to server
# @args: host -> the server host
# port -> ther connection port
# gpg_key -> the gpg key
# password -> the remote password
# suffix -> the suffix file
# @rtrn: false if the connection fail
def connect(host, port, gpg_key, password, suffix=nil) def connect(host, port, gpg_key, password, suffix=nil)
@gpg_key = gpg_key @gpg_key = gpg_key
@password = password @password = password
@ -31,13 +40,16 @@ class Sync
@socket= TCPSocket.new(host, port) @socket= TCPSocket.new(host, port)
@sync = true @sync = true
rescue Exception => e rescue Exception => e
@error_msg = "ERROR: Connection impossible\n#{e}" @error_msg = "#{I18n.t('error.sync.connection')}\n#{e}"
@sync = false @sync = false
end end
return @sync return @sync
end end
# Get data on server
# @args: gpg_password -> the gpg password
# @rtrn: nil if nothing data or error
def get(gpg_password) def get(gpg_password)
if !@sync if !@sync
return nil return nil
@ -51,6 +63,7 @@ class Sync
@socket.puts send_msg.to_json @socket.puts send_msg.to_json
msg = JSON.parse(@socket.gets) msg = JSON.parse(@socket.gets)
puts msg
case msg['error'] case msg['error']
when nil, 'file_not_exist' when nil, 'file_not_exist'
tmp_file = "/tmp/mpw-#{MPW.generatePassword()}.gpg" tmp_file = "/tmp/mpw-#{MPW.generatePassword()}.gpg"
@ -67,14 +80,17 @@ class Sync
return @mpw.search() return @mpw.search()
when 'not_authorized' when 'not_authorized'
@error_msg = 'not authorized' @error_msg = "#{I18n.t('error.sync.not_authorized')}\n#{e}"
else else
@error_msg = 'error unknow' @error_msg = "#{I18n.t('error.sync.unknown')}\n#{e}"
end end
return nil return nil
end end
# Update the remote data
# @args: data -> the data to send on server
# @rtrn: false if there is a problem
def update(data) def update(data)
if !@sync if !@sync
return true return true
@ -93,11 +109,11 @@ class Sync
when nil when nil
return true return true
when 'not_authorized' when 'not_authorized'
@error_msg = 'not authorized' @error_msg = "#{I18n.t('error.sync.not_authorized')}\n#{e}"
when 'no_data' when 'no_data'
@error_msg = 'no data' @error_msg = "#{I18n.t('error.sync.no_data')}\n#{e}"
else else
@error_msg = 'error unknow' @error_msg = "#{I18n.t('error.sync.unknown')}\n#{e}"
end end
return false return false
@ -106,6 +122,7 @@ class Sync
def delete() def delete()
end end
# Close the connection
def close() def close()
if !@sync if !@sync
return return