Skip to content

Instantly share code, notes, and snippets.

@brandonsturgeon
Created November 24, 2015 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonsturgeon/808695b33d704cfb5ab6 to your computer and use it in GitHub Desktop.
Save brandonsturgeon/808695b33d704cfb5ab6 to your computer and use it in GitHub Desktop.
import os
import logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
class Main():
def __init__(self):
if self.prelim_checks() is False:
logging.critical("Preliminary checks show problems in configuration. Shutting down.")
return
else:
logging.debug("Preliminary checks show no problems in configuration. Continuing.")
self.files = {}
# Size limit set at 10mb by default
self.file_size_limit = 1000000
self.build_files_dict()
self.upload_oversized_files()
# This function returns false if anything
# isn't set up properly
def prelim_checks(self):
# Check if lib/ folder exists
logging.debug("Checking if lib/ directory exists..")
if not os.path.isdir("lib"):
logging.critical("No lib/ directory found!")
return False
else:
logging.debug("lib/ directory exists!")
# Check that the lib folder isn't empty
logging.debug("Checking if lib/ directory is empty..")
if not os.listdir("lib"):
logging.critical("lib/ directory is empty!")
return False
else:
logging.debug("lib/ directory is not empty!")
# Check to make sure lib/csfiles/home_dir exists
logging.debug("Checking if lib/csfiles/home_dir exists..")
if not os.path.isdir("lib/csfiles/home_dir"):
logging.critical("No lib/csfiles/home_dir found!")
return False
return True
def build_files_dict(self):
logging.debug("Generating self.files..")
file_list = []
for (dirpath, dirnames, filenames) in os.walk("lib/csfiles/home_dir"):
file_list.extend(filenames)
break
for filename in file_list:
path = "lib/csfiles/home_dir/"+filename
size = os.path.getsize(path)
self.files[path] = size
logging.debug("Finished generating self.files")
def get_oversized_files(self):
""" Returns all files over the set size """
for path, size in self.files.iteritems():
if size > self.file_size_limit:
yield path
def upload_oversized_file(self, filename):
""" Uploads a singular file to the Box account """
def upload_oversized_files(self):
""" Uploads all oversized files in a given list """
oversized_files = self.get_oversized_files()
print ""
print "-- Oversized Files | Limit: {} bytes --".format(self.file_size_limit)
for path in oversized_files:
size = self.files[path]
print "{} -- {} bytes".format(path, size)
print ""
if __name__ == "__main__":
Main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment