Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions quail/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ class Constants:
ARGUMENT_RM = "--quail_rm"
CHECKSUMS_FILE = ".integrity.json"
INTEGRITY_IGNORE_FILE = ".integrity_ignore"
UPDATE_IGNORE_FILE = ".quailignore"

38 changes: 35 additions & 3 deletions quail/solution/solutioner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import shutil
import os
import glob
from quail.helper.file_ignore import FileIgnore
from quail.constants import Constants


class Solutioner:
Expand Down Expand Up @@ -35,10 +38,39 @@ def install(self):
def installed(self):
return os.path.exists(self.dest())

"""
This function makes sure that all the files defined in the file with path=Constants.UPDATE_IGNORE_FILE
are not deleted when the software is updating

First parameter is the root path for the solution. We could have used self.dest() but is not
an acceptable solution for tests.
TODO: Make sure that we set up the solution properly during the test, this problem should'nt happen
"""
def _clear_non_ignored_files(self, path):
fi = FileIgnore(os.path.join(path, Constants.UPDATE_IGNORE_FILE))
result = [os.path.join(dp, f) for dp, dn, filenames in os.walk(path) for f in filenames]
files_to_remove = [item for item in result if fi.accept(item) and not item.endswith(Constants.UPDATE_IGNORE_FILE)]
for file in files_to_remove:
if os.path.exists(file):
os.remove(file)

def __update_solution_files(self):
self._solution.open()
try:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get .quailignore

if not os.path.exists(self.dest()):
os.makedirs(self.dest(), 0o777, True)
for root, dirs, files in self._solution.walk():
for dir in dirs:
if not os.path.exists(dir):
os.makedirs(self.dest(root, dir), 0o777, True)
for file in files:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore ici

self._retrieve_file(os.path.join(root, file))
finally:
self._solution.close()

def update(self):
# TODO: uninstall will be a waste of time on future solution types
self.uninstall()
self.install()
self._clear_non_ignored_files(self.dest())
self.__update_solution_files()

def uninstall(self):
if self.installed():
Expand Down
27 changes: 27 additions & 0 deletions tests/test_ignore_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
from .base_test_case import BaseTestCase
from quail.constants import Constants
from quail.solution.solutioner import Solutioner


class TestUpdateFileIgnore(BaseTestCase):

def setUp(self):
super().setUp()
self.solutioner = Solutioner(None, os.path.curdir)

def test_basic_ignore(self):
os.mkdir(self.tmp("test"))
with open(self.tmp("test", "1.txt"), "a+"):
pass
with open(self.tmp("test", "2.txt"), "a+"):
pass
with open(self.tmp("test", Constants.UPDATE_IGNORE_FILE), "a+") as f:
f.write("*1.txt")
self.solutioner._clear_non_ignored_files(self.tmp("test"))

assert os.path.exists(self.tmp("test", Constants.UPDATE_IGNORE_FILE))
assert not os.path.exists(self.tmp("test", "2.txt"))


#TODO: Add multiple test with edge case