Skip to content

Commit

Permalink
version 0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
reallistic authored and Michael Chase committed Nov 16, 2014
1 parent 68f24d1 commit 29c272f
Show file tree
Hide file tree
Showing 11 changed files with 745 additions and 398 deletions.
46 changes: 28 additions & 18 deletions BitcasaFileFetcher/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from bitcasa import BitcasaException

should_exit = threading.Event()

bitc = None
class Args(object):
"""
Argument parser wrapper class
Expand Down Expand Up @@ -121,7 +121,7 @@ def parse(self):
help="Runs through the program logging all skipped and downloaded files without actually downloading anything", default=False)
mainparser.add_argument(
'--version', help="Displays version and exits",
action='version', version='%(prog)s 0.6.3')
action='version', version='%(prog)s 0.7.0')

downparser = subparsers.add_parser("download", parents=[mainparser],
help="Program to download files from bitcasa to local/network storage")
Expand All @@ -131,27 +131,28 @@ def parse(self):

upparser = subparsers.add_parser("upload", parents=[mainparser],
help="Program to download files from bitcasa and upload to remote storage")
upparser.add_argument(
"-t", "--temp", help="The dir for temp files. (A local folder)", required=True)
upparser.add_argument(
"--provider", help="The remote storage provider in question (default is gdrive)",
choices=['gdrive'], default='gdrive')
upparser.add_argument(
"-t", "--temp", help="The dir for temp files. (A local folder)", required=True)
upparser.add_argument(
"--local", help="Upload local files", action="store_true", default=False)
upparser.set_defaults(func=self.run_upload)

self.args = parser.parse_args()
self.args.func()

return self.args

def run_download(self):
def run_download(self, upload=False):
"""Run the main program checks"""
self.run_level = Args.RUN_LEVEL_MAIN
self.args.upload = False
self.args.upload = upload
self.set_log_file()

def run_upload(self):
self.run_download()
self.args.upload = True
self.run_download(True)

def run_test(self):
"""run authentication tests on a specific provider"""
Expand All @@ -163,7 +164,7 @@ def run_oauth(self):


def main():
global log, utils
global log, utils, bitc
args = Args()
args.parse()
log = logger.create("BitcasaFileFetcher", args)
Expand All @@ -173,22 +174,25 @@ def main():
from lib.gdrive import GoogleDrive

if args.run_level == Args.RUN_LEVEL_MAIN:
bitcasa_utils = BitcasaUtils()
if bitcasa_utils.test_auth():
args.args.token = bitcasa_utils.token
else:
log.error("Bitcasa Access token not set or invalid. Use the following commands to get one.")
log.info("python BitcasaFileLister")
return
client = None
if not args.args.upload or not args.args.local:
bitcasa_utils = BitcasaUtils()
if bitcasa_utils.test_auth():
args.args.token = bitcasa_utils.token
else:
log.error("Bitcasa Access token not set or invalid. Use the following commands to get one.")
log.info("python BitcasaFileLister")
return
client = bitcasa_utils.create_client()
if args.args.upload:
if args.args.provider == "gdrive":
g = GoogleDrive()
if not g.test_auth():
log.error("Google Drive Access token not set or invalid. Use the following command to get one.")
log.info("python BitcasaFileFetcher oauth --provider gdrive")
return
log.debug("Initializing Bitcasa")
bitc = BitcasaDownload(args.args, bitcasa_utils.create_client(), should_exit)
log.debug("Initializing download")
bitc = BitcasaDownload(args.args, client, should_exit)
if should_exit.is_set():
log.info("Exiting")
return
Expand Down Expand Up @@ -242,15 +246,21 @@ def handle_input():
while not should_exit.is_set():
if answer.lower() in ["y", "q", "quit", "exit"]:
log.info("Received exit signal")
if bitc:
bitc.shutdown()
should_exit.set()
else:
answer = raw_input("Would you like to shutdown? [y/n]\n")
except (KeyboardInterrupt, IOError, EOFError):
log.info("Received exit signal")
if bitc:
bitc.shutdown()
should_exit.set()

def handle_exit_signal(signum, frame):
log.info("Received exit signal")
if bitc:
bitc.shutdown()
should_exit.set()

if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 29c272f

Please sign in to comment.