Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added mkdir command. Also added some examples to helps.

  • Loading branch information...
commit e652ccef934353ab101fc6fdea05dbaf40a05f45 1 parent fcb7d23
Joshua Roesslein joshthecoder authored

Showing 1 changed file with 28 additions and 0 deletions. Show diff stats Hide diff stats

  1. +28 0 baconfile.py
28 baconfile.py
@@ -8,6 +8,7 @@
8 8 import base64
9 9 import os, sys
10 10 from datetime import datetime
  11 +from getpass import getpass
11 12
12 13 if sys.version_info < (2,6,):
13 14 import simplejson as json
@@ -85,17 +86,25 @@ def show_help(page=''):
85 86 print ' user - owner of file being fetched'
86 87 print ' path - path to file'
87 88 print ' dest - where to save file [optional]'
  89 + print 'Example: baconfile fetch john pictures/tree.jpg /home/me/pictures'
88 90 print ''
89 91 elif page == 'ls':
90 92 print 'List infomation about files/folders'
91 93 print 'Usage: ls <user> [folder]'
92 94 print ' user - owner of files/folders to list'
93 95 print ' folder - folder to list [default: user\'s root folder]'
  96 + print 'Example: baconfile ls john music'
94 97 print ''
95 98 elif page == 'recent':
96 99 print 'Get listing of most recently added files'
97 100 print 'Usage: recent'
98 101 print ''
  102 + elif page == 'mkdir':
  103 + print 'Create a new folder on baconfile.com'
  104 + print 'Usage: mkdir <folder>'
  105 + print ' folder - path + folder name'
  106 + print 'Example: baconfile mkdir docs/papers'
  107 + print ''
99 108 else:
100 109 print 'Baconfile commandline tool'
101 110 print 'Usage: <command> [options]...'
@@ -105,6 +114,14 @@ def show_help(page=''):
105 114 print ' recent - list most recently added files'
106 115 print 'Type just the command name to get more infomation.'
107 116
  117 +# query user for username and password
  118 +def get_credentials():
  119 + print 'Baconfile.com login credentials required.:'
  120 + print 'Username: ',
  121 + username = raw_input()
  122 + password = getpass()
  123 + return username, password
  124 +
108 125 def print_items(items):
109 126 for i in items:
110 127 if i.size is None:
@@ -140,6 +157,13 @@ def cmd_recent():
140 157 print 'Failed to fetch recent files: %s' % e
141 158 exit(1)
142 159
  160 +def cmd_mkdir(folder_name):
  161 + try:
  162 + new_folder(get_credentials(), folder_name)
  163 + except urllib2.HTTPError, e:
  164 + print 'Failed to create new folder: %s' % e
  165 + exit(1)
  166 +
143 167 if __name__ == '__main__':
144 168 # Get command and args
145 169 if len(sys.argv) < 2:
@@ -156,6 +180,8 @@ def cmd_recent():
156 180 cmd_ls(*args)
157 181 elif command == 'recent':
158 182 cmd_recent()
  183 + elif command == 'mkdir':
  184 + cmd_mkdir(*args)
159 185 else:
160 186 print '%s invalid command!' % command
161 187 show_help()
@@ -164,4 +190,6 @@ def cmd_recent():
164 190 if len(args) > 0:
165 191 print 'Missing required parameters!'
166 192 show_help(command)
  193 + except KeyboardInterrupt:
  194 + print ''
167 195

0 comments on commit e652cce

Please sign in to comment.
Something went wrong with that request. Please try again.