Skip to content

Commit

Permalink
Set Jekyll comands to only run if the selected directory exists
Browse files Browse the repository at this point in the history
Created a function to check if the selected directory exists, and set up each of the Jekyll functions to only run if the selected directory does exist.

Added several test cases for the new site directory check function.

Closes #27
  • Loading branch information
ExcaliburZero committed May 18, 2015
1 parent 9f82c46 commit b4926ff
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 13 deletions.
61 changes: 50 additions & 11 deletions jekyll_helper/JekyllHelperWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ def get_jekyll_version():
global settings
settings = Gio.Settings("net.launchpad.jekyll-helper")

# Function to check if the set site directory exists
def site_directory_exists(self, site_directory):
"""Check if the site directory that the user has chosen or not yet chosen exists."""
# If no site directory has been entered
if ( site_directory == "" ):
return 1;
# If the chosen site directory does not exist
elif ( os.path.exists(site_directory) == False ):
return 2;
# If the chosen site directory does exist
else:
return 0;

# Set directory that stores the Jekyll website
global site_directory
site_directory = ""
Expand All @@ -95,6 +108,11 @@ def set_website_directory(self, user_data):
global site_directory
site_directory = self.directoryChooser.get_current_folder()
print(site_directory)
# Check if the selected directory exists
if (self.site_directory_exists(site_directory) == 1):
print("No site directory has been entered.")
elif (self.site_directory_exists(site_directory) == 2):
print("The entered directory does not exist.")
return;

# Jekyll serve functions
Expand Down Expand Up @@ -134,13 +152,20 @@ def on_serveSwitch_stateset(self, widget, state):
"""Begin or end serving website through Jekyll based on the serveSwitch value."""
print("Serve: " + str(state))
global site_directory
if (state == True):
self.jekyll_serve_on(site_directory);
elif (state == False):
self.jekyll_serve_off(site_directory);
else:
print("Error triggering Jekyll Serve")
print("Is Serving: " + str(is_serving))

# Run the serve fuction if the site directory exists
if (self.site_directory_exists(site_directory) == 0):
if (state == True):
self.jekyll_serve_on(site_directory);
elif (state == False):
self.jekyll_serve_off(site_directory);
else:
print("Error triggering Jekyll Serve")
print("Is Serving: " + str(is_serving))
elif (self.site_directory_exists(site_directory) == 1):
print("No site directory has been entered.")
elif (self.site_directory_exists(site_directory) == 2):
print("The entered directory does not exist.")
return;

# Jekyll build functions
Expand All @@ -161,8 +186,15 @@ def on_buildButton_clicked(self, widget):
"""Build the website when the build button is clicked."""
global site_directory
print("Jekyll Build: " + site_directory)
self.jekyll_build(site_directory)
print("Sucessfully built website")

# Run the build fuction if the site directory exists
if (self.site_directory_exists(site_directory) == 0):
self.jekyll_build(site_directory)
print("Sucessfully built website")
elif (self.site_directory_exists(site_directory) == 1):
print("No site directory has been entered.")
elif (self.site_directory_exists(site_directory) == 2):
print("The entered directory does not exist.")
return;

# Push website functions
Expand All @@ -183,6 +215,13 @@ def on_pushButton_clicked(self, widget):
"""Push the website when the push button is clicked."""
global site_directory
print("Push: " + site_directory)
self.website_push(site_directory)
print("Sucessfully pushed website")

# Run the push fuction if the site directory exists
if (self.site_directory_exists(site_directory) == 0):
self.website_push(site_directory)
print("Sucessfully pushed website")
elif (self.site_directory_exists(site_directory) == 1):
print("No site directory has been entered.")
elif (self.site_directory_exists(site_directory) == 2):
print("The entered directory does not exist.")
return;
16 changes: 14 additions & 2 deletions tests/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -27,6 +27,7 @@
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), "..")))

from jekyll_helper import AboutJekyllHelperDialog
from jekyll_helper import JekyllHelperWindow

class TestExample(unittest.TestCase):
def setUp(self):
Expand All @@ -40,5 +41,16 @@ def test_AboutJekyllHelperDialog_members(self):
public_members.sort()
self.assertEqual(self.AboutJekyllHelperDialog_members, public_members)

# Test the site directory check function
class TestCheckSiteDirectory(unittest.TestCase):
"""Tests the site directory checking function to make sure that it works properly."""
def setUp(self):
self.prog_window = JekyllHelperWindow.JekyllHelperWindow()

def test_site_directory_exists(self):
self.assertEqual(self.prog_window.site_directory_exists(os.getcwd()), 0) # Check current directory
self.assertEqual(self.prog_window.site_directory_exists(""), 1) # Check a blank directory
self.assertEqual(self.prog_window.site_directory_exists(os.getcwd() + "htrjek"), 2) # Check a nonexistant directory

if __name__ == '__main__':
unittest.main()

0 comments on commit b4926ff

Please sign in to comment.