Class: CloudDoor::Console
- Inherits:
-
Object
- Object
- CloudDoor::Console
- Defined in:
- lib/cloud_door/console.rb
Instance Attribute Summary collapse
-
#drive ⇒ Object
Returns the value of attribute drive.
-
#storage_name ⇒ Object
readonly
Returns the value of attribute storage_name.
Instance Method Summary collapse
- #account(show = false) ⇒ Object
- #cd(file_name) ⇒ Object
- #config(show = false) ⇒ Object
- #download(file_name) ⇒ Object
- #info(file_name) ⇒ Object
-
#initialize(drive, session_id = nil) ⇒ Console
constructor
A new instance of Console.
- #login(default = false) ⇒ Object
- #ls(file_name) ⇒ Object
- #mkdir(mkdir_name) ⇒ Object
- #pwd ⇒ Object
- #rm(file_name) ⇒ Object
- #upload(file_name) ⇒ Object
Constructor Details
Instance Attribute Details
#drive ⇒ Object
Returns the value of attribute drive.
7 8 9 |
# File 'lib/cloud_door/console.rb', line 7 def drive @drive end |
#storage_name ⇒ Object (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 account(show = false) if show show_account(@drive.show_account) exit end accounts = ask_account result = @drive.update_account(accounts) (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((:wrong_parameter, 'file name')) exit end @drive.load_token fullname = make_fullname(file_name) unless @drive.file_exist?(file_name) say((:file_not_exists, fullname, @storage_name)) exit end say((: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) (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((:wrong_parameter, 'file name')) exit end @drive.load_token fullname = make_fullname(file_name) unless @drive.file_exist?(file_name) say((:file_not_exists, fullname, @storage_name)) exit end if File.exist?(file_name) say((:same_file_exist, file_name, 'local')) exit unless agree((:agree_overwrite, file_name)) end result = @drive.download_file(file_name) (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((:wrong_parameter, 'file name')) exit end @drive.load_token fullname = make_fullname(file_name) unless @drive.file_exist?(file_name) say((:file_not_exists, fullname, @storage_name)) exit end info = @drive.show_property(file_name) unless (info.empty?) say((: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 login(default = false) unless @drive.configuration_init? say((:not_configuration, @storage_name.downcase)) exit end exit unless agree((:agree_access, @storage_name)) account = login_set_account(default) say((:start_connection, @storage_name)) if @drive.login(account['login_account'], account['login_password']) user = @drive.show_user user_name = user['name'] || user['display_name'] say((:result_success, 'login')) say((:login_as, user_name)) say("\n") pwd = @drive.show_current_directory list = @drive.show_files show_file_list(pwd, list) else say((: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((: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((:wrong_parameter, 'file name')) exit end @drive.load_token fullname = make_fullname(mkdir_name) if @drive.file_exist?(mkdir_name) say((:same_file_exist, fullname, @storage_name)) exit end result = @drive.make_directory(mkdir_name) (result, "make '#{fullname}' directory") rescue => e show_exception(e) end |
#pwd ⇒ Object
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((:wrong_parameter, 'file name')) exit end @drive.load_token fullname = make_fullname(file_name) exit unless agree((:agree_delete, fullname)) unless @drive.file_exist?(file_name) say((:file_not_exists, fullname, @storage_name)) exit end if @drive.has_file?(file_name) say((:has_files, fullname)) # exit unless agree("Do you want to delete these files (Y/N)?") exit end result = @drive.delete_file(file_name) (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((:wrong_parameter, 'file name')) exit end @drive.load_token unless File.exists?(file_name) say((:file_not_exists, file_name, 'local')) exit end if File.directory?(file_name) say((:is_directory, file_name)) say((: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((:same_file_exist, fullname, @storage_name)) exit unless agree((:agree_overwrite, fullname)) end result = @drive.upload_file(file_name) (result, "'#{fullname}' upload") rescue => e show_exception(e) end |