Skip to content

Commit

Permalink
Improved exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMetcalfe committed May 13, 2017
1 parent 108afca commit c9fa8c5
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions Chrome_Bookmarks_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
destination = os.path.dirname(os.path.realpath(__file__))
cmd = "python Chrome_Bookmarks_Parser.py"


def osWalk():
for dirname, dirnames, filenames in os.walk('C:\\'):
for filename in filenames:
if "Bookmarks.bak" in filename and "Chrome" in dirname:
return os.path.join(dirname, filename)


def findChrome():

# Directory references for Chrome pulled from Chromium docs.
Expand All @@ -38,7 +40,8 @@ def findChrome():
else:
try:
copy(osWalk(), destination)
except:
except Exception as e:
print("{}".format(e.message))
sys.exit("Cannot find Bookmarks.bak file.")

# Else, assume OS is 10 / 8 / 7 / Vista.
Expand All @@ -53,7 +56,8 @@ def findChrome():
else:
try:
copy(osWalk(), destination)
except:
except Exception as e:
print("{}".format(e.message))
sys.exit("Cannot find Bookmarks.bak file.")

# Check if platform is Mac OS X.
Expand All @@ -65,7 +69,11 @@ def findChrome():
if os.path.exists(filePath):
copy(filePath, destination)
else:
sys.exit("Cannot find Bookmarks.bak file.")
try:
copy(osWalk(), destination)
except Exception as e:
print("{}".format(e.message))
sys.exit("Cannot find Bookmarks.bak file.")

# Check if platform is Linux.
elif useros is 'Linux':
Expand All @@ -76,10 +84,16 @@ def findChrome():
if os.path.exists(filePath):
copy(filePath, destination)
else:
sys.exit("Cannot find Bookmarks.bak file.")
try:
copy(osWalk(), destination)
except Exception as e:
print("{}".format(e.message))
sys.exit("Cannot find Bookmarks.bak file.")


try:
findChrome()
subprocess.Popen(cmd)
except:
sys.exit("Oops. Something went wrong.")
except Exception as e:
print("{}".format(e.message))
sys.exit("Oops. Something went wrong.")

0 comments on commit c9fa8c5

Please sign in to comment.