Class: CloudDoor::Console

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud_door/console.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(drive, session_id = nil) ⇒ Console

Returns a new instance of Console.



10
11
12
13
# File 'lib/cloud_door/console.rb', line 10

def initialize(drive, session_id = nil)
  @drive = CloudDoor.new(drive, session_id)
  @storage_name = @drive.show_storage_name
end

Instance Attribute Details

#driveObject

Returns the value of attribute drive.



7
8
9
# File 'lib/cloud_door/console.rb', line 7

def drive
  @drive
end

#storage_nameObject (readonly)

Returns the value of attribute storage_name.



8
9
10
# File 'lib/cloud_door/console.rb', line 8

def storage_name
  @storage_name
end

Instance Method Details

#account(show = false) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/cloud_door/console.rb', line 25

def (show = false)
  if show
    (@drive.)
    exit
  end
  accounts = 
  result   = @drive.(accounts)
  show_result_message(result, 'update account')
end

#cd(file_name) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/cloud_door/console.rb', line 74

def cd(file_name)
  if (file_name.nil? || file_name.empty?)
    say(make_message(:wrong_parameter, 'file name'))
    exit
  end
  @drive.load_token
  fullname = make_fullname(file_name)
  unless @drive.file_exist?(file_name)
    say(make_message(:file_not_exists, fullname, @storage_name))
    exit
  end
  say(make_message(:move_to, fullname))
  list = @drive.change_directory(file_name)
  show_file_list(fullname, list)
rescue => e
  show_exception(e)
end

#config(show = false) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/cloud_door/console.rb', line 15

def config(show = false)
  if show
    show_configuration(@drive.show_configuration)
    exit
  end
  configs = ask_configuration
  result  = @drive.update_configuration(configs)
  show_result_message(result, 'update configuration')
end

#download(file_name) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/cloud_door/console.rb', line 121

def download(file_name)
  if (file_name.nil? || file_name.empty?)
    say(make_message(:wrong_parameter, 'file name'))
    exit
  end
  @drive.load_token
  fullname = make_fullname(file_name)
  unless @drive.file_exist?(file_name)
    say(make_message(:file_not_exists, fullname, @storage_name))
    exit
  end
  if File.exist?(file_name)
    say(make_message(:same_file_exist, file_name, 'local'))
    exit unless agree(make_message(:agree_overwrite, file_name))
  end
  result = @drive.download_file(file_name)
  show_result_message(result, "'#{file_name}' download")
rescue => e
  show_exception(e)
end

#info(file_name) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/cloud_door/console.rb', line 92

def info(file_name)
  if (file_name.nil? || file_name.empty?)
    say(make_message(:wrong_parameter, 'file name'))
    exit
  end
  @drive.load_token
  fullname = make_fullname(file_name)
  unless @drive.file_exist?(file_name)
    say(make_message(:file_not_exists, fullname, @storage_name))
    exit
  end
  info = @drive.show_property(file_name)
  unless (info.empty?)
    say(make_message(:show_information, fullname))
    max = info.max { |a, b| a[0].length <=> b[0].length }
    max_len = max[0].length
    info.each do |key, value|
      say("  #{key.ljust(max_len)} : #{value}")
    end
  end
rescue => e
  show_exception(e)
end

#login(default = false) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cloud_door/console.rb', line 35

def (default = false)
  unless @drive.configuration_init?
    say(make_message(:not_configuration, @storage_name.downcase))
    exit
  end
  exit unless agree(make_message(:agree_access, @storage_name))
   = (default)
  say(make_message(:start_connection, @storage_name))
  if @drive.(['login_account'], ['login_password'])
    user      = @drive.show_user
    user_name = user['name'] || user['display_name']
    say(make_message(:result_success, 'login'))
    say(make_message(:login_as, user_name))
    say("\n")
    pwd  = @drive.show_current_directory
    list = @drive.show_files
    show_file_list(pwd, list)
  else
    say(make_message(:result_fail, 'login'))
  end
rescue => e
  show_exception(e)
end

#ls(file_name) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/cloud_door/console.rb', line 59

def ls(file_name)
  @drive.load_token
  fullname = make_fullname(file_name)
  if !file_name.nil? && !file_name.empty?
    unless @drive.file_exist?(file_name)
      say(make_message(:file_not_exists, fullname, @storage_name))
      exit
    end
  end
  list = @drive.show_files(file_name)
  show_file_list(fullname, list)
rescue => e
  show_exception(e)
end

#mkdir(mkdir_name) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/cloud_door/console.rb', line 192

def mkdir(mkdir_name)
  if (mkdir_name.nil? || mkdir_name.empty?)
    say(make_message(:wrong_parameter, 'file name'))
    exit
  end
  @drive.load_token
  fullname = make_fullname(mkdir_name)
  if @drive.file_exist?(mkdir_name)
    say(make_message(:same_file_exist, fullname, @storage_name))
    exit
  end
  result = @drive.make_directory(mkdir_name)
  show_result_message(result, "make '#{fullname}' directory")
rescue => e
  show_exception(e)
end

#pwdObject



116
117
118
119
# File 'lib/cloud_door/console.rb', line 116

def pwd
  @drive.load_token
  say(@drive.show_current_directory)
end

#rm(file_name) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/cloud_door/console.rb', line 169

def rm(file_name)
  if (file_name.nil? || file_name.empty?)
    say(make_message(:wrong_parameter, 'file name'))
    exit
  end
  @drive.load_token
  fullname = make_fullname(file_name)
  exit unless agree(make_message(:agree_delete, fullname))
  unless @drive.file_exist?(file_name)
    say(make_message(:file_not_exists, fullname, @storage_name))
    exit
  end
  if @drive.has_file?(file_name)
    say(make_message(:has_files, fullname))
    # exit unless agree("Do you want to delete these files (Y/N)?")
    exit
  end
  result = @drive.delete_file(file_name)
  show_result_message(result, "'#{fullname}' delete")
rescue => e
  show_exception(e)
end

#upload(file_name) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/cloud_door/console.rb', line 142

def upload(file_name)
  if (file_name.nil? || file_name.empty?)
    say(make_message(:wrong_parameter, 'file name'))
    exit
  end
  @drive.load_token
  unless File.exists?(file_name)
    say(make_message(:file_not_exists, file_name, 'local'))
    exit
  end
  if File.directory?(file_name)
    say(make_message(:is_directory, file_name))
    say(make_message(:compress_to, file_name))
    say("\n")
  end
  up_file  = @drive.assign_upload_file_name(file_name)
  fullname = make_fullname(up_file)
  if @drive.file_exist?(up_file)
    say(make_message(:same_file_exist, fullname, @storage_name))
    exit unless agree(make_message(:agree_overwrite, fullname))
  end
  result = @drive.upload_file(file_name)
  show_result_message(result, "'#{fullname}' upload")
rescue => e
  show_exception(e)
end