Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added mkdir command. Also added some examples to helps.

  • Loading branch information...
commit e652ccef934353ab101fc6fdea05dbaf40a05f45 1 parent fcb7d23
@joshthecoder joshthecoder authored
Showing with 28 additions and 0 deletions.
  1. +28 −0 baconfile.py
View
28 baconfile.py
@@ -8,6 +8,7 @@
import base64
import os, sys
from datetime import datetime
+from getpass import getpass
if sys.version_info < (2,6,):
import simplejson as json
@@ -85,17 +86,25 @@ def show_help(page=''):
print ' user - owner of file being fetched'
print ' path - path to file'
print ' dest - where to save file [optional]'
+ print 'Example: baconfile fetch john pictures/tree.jpg /home/me/pictures'
print ''
elif page == 'ls':
print 'List infomation about files/folders'
print 'Usage: ls <user> [folder]'
print ' user - owner of files/folders to list'
print ' folder - folder to list [default: user\'s root folder]'
+ print 'Example: baconfile ls john music'
print ''
elif page == 'recent':
print 'Get listing of most recently added files'
print 'Usage: recent'
print ''
+ elif page == 'mkdir':
+ print 'Create a new folder on baconfile.com'
+ print 'Usage: mkdir <folder>'
+ print ' folder - path + folder name'
+ print 'Example: baconfile mkdir docs/papers'
+ print ''
else:
print 'Baconfile commandline tool'
print 'Usage: <command> [options]...'
@@ -105,6 +114,14 @@ def show_help(page=''):
print ' recent - list most recently added files'
print 'Type just the command name to get more infomation.'
+# query user for username and password
+def get_credentials():
+ print 'Baconfile.com login credentials required.:'
+ print 'Username: ',
+ username = raw_input()
+ password = getpass()
+ return username, password
+
def print_items(items):
for i in items:
if i.size is None:
@@ -140,6 +157,13 @@ def cmd_recent():
print 'Failed to fetch recent files: %s' % e
exit(1)
+def cmd_mkdir(folder_name):
+ try:
+ new_folder(get_credentials(), folder_name)
+ except urllib2.HTTPError, e:
+ print 'Failed to create new folder: %s' % e
+ exit(1)
+
if __name__ == '__main__':
# Get command and args
if len(sys.argv) < 2:
@@ -156,6 +180,8 @@ def cmd_recent():
cmd_ls(*args)
elif command == 'recent':
cmd_recent()
+ elif command == 'mkdir':
+ cmd_mkdir(*args)
else:
print '%s invalid command!' % command
show_help()
@@ -164,4 +190,6 @@ def cmd_recent():
if len(args) > 0:
print 'Missing required parameters!'
show_help(command)
+ except KeyboardInterrupt:
+ print ''
Please sign in to comment.
Something went wrong with that request. Please try again.