From 927d76779f0003ce11eefa65936b83153c1285be Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Wed, 2 May 2018 20:40:42 +0200 Subject: [PATCH] refactor folder to directory --- dotdrop.sh | 4 ++-- dotdrop/installer.py | 24 ++++++++++++------------ tests/helpers.py | 18 +++++++++--------- tests/test_compare.py | 14 +++++++------- tests/test_config.py | 4 ++-- tests/test_import.py | 14 +++++++------- tests/test_install.py | 8 ++++---- 7 files changed, 43 insertions(+), 43 deletions(-) diff --git a/dotdrop.sh b/dotdrop.sh index 19bc6e5..50d17c0 100755 --- a/dotdrop.sh +++ b/dotdrop.sh @@ -22,10 +22,10 @@ cfg="${cur}/config.yaml" sub="dotdrop" # pivot -cd "${cur}" || { echo "Folder \"${cur}\" doesn't exist, aborting." && exit; } +cd "${cur}" || { echo "Directory \"${cur}\" doesn't exist, aborting." && exit; } # init/update the submodule git submodule update --init --recursive # launch dotdrop PYTHONPATH=dotdrop python3 -m dotdrop.dotdrop --cfg="${cfg}" "${args[@]}" # pivot back -cd "${opwd}" || { echo "Folder \"${opwd}\" doesn't exist, aborting." && exit; } +cd "${opwd}" || { echo "Directory \"${opwd}\" doesn't exist, aborting." && exit; } diff --git a/dotdrop/installer.py b/dotdrop/installer.py index 382de9f..fc83655 100644 --- a/dotdrop/installer.py +++ b/dotdrop/installer.py @@ -92,7 +92,7 @@ class Installer: return [] def _handle_dir(self, templater, profile, src, dst): - '''Install a folder using templater for "profile"''' + '''Install a directory using templater for "profile"''' ret = [] for entry in os.listdir(src): f = os.path.join(src, entry) @@ -143,14 +143,14 @@ class Installer: os.chmod(dst, rights) return 0 - def _create_dirs(self, folder): - '''mkdir -p "folder"''' - if not self.create and not os.path.exists(folder): + def _create_dirs(self, directory): + '''mkdir -p "directory"''' + if not self.create and not os.path.exists(directory): return False - if os.path.exists(folder): + if os.path.exists(directory): return True - os.makedirs(folder) - return os.path.exists(folder) + os.makedirs(directory) + return os.path.exists(directory) def _backup(self, path): '''Backup the file''' @@ -160,15 +160,15 @@ class Installer: self.log.log('backup %s to %s' % (path, dst)) os.rename(path, dst) - def _install_to_temp(self, templater, profile, src, dst, tmpfolder): - '''Install a dotfile to a tempfolder for comparing''' + def _install_to_temp(self, templater, profile, src, dst, tmpdir): + '''Install a dotfile to a tempdir for comparing''' sub = dst if dst[0] == os.sep: sub = dst[1:] - tmpdst = os.path.join(tmpfolder, sub) + tmpdst = os.path.join(tmpdir, sub) return self.install(templater, profile, src, tmpdst), tmpdst - def compare(self, templater, tmpfolder, profile, src, dst, opts=''): + def compare(self, templater, tmpdir, profile, src, dst, opts=''): '''Compare temporary generated dotfile with local one''' self.comparing = True retval = False, '' @@ -186,7 +186,7 @@ class Installer: ret, tmpdst = self._install_to_temp(templater, profile, src, dst, - tmpfolder) + tmpdir) if ret: diff = utils.diff(tmpdst, dst, raw=False, opts=opts) if diff == '': diff --git a/tests/helpers.py b/tests/helpers.py index 301d954..567ab57 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -16,7 +16,7 @@ TMPSUFFIX = '.dotdrop' def clean(path): - '''Delete file or folder.''' + '''Delete file or directory.''' if not os.path.exists(path): return if os.path.islink(path): @@ -33,13 +33,13 @@ def get_string(length): return ''.join(random.choice(alpha) for _ in range(length)) -def get_tempfolder(): - '''Get a temporary folder''' +def get_tempdir(): + '''Get a temporary directory''' return tempfile.mkdtemp(suffix=TMPSUFFIX) -def create_random_file(folder, content=None, binary=False): - '''Create a new file in folder with random content.''' +def create_random_file(directory, content=None, binary=False): + '''Create a new file in directory with random content.''' fname = get_string(8) mode = 'w' if binary: @@ -49,14 +49,14 @@ def create_random_file(folder, content=None, binary=False): content = bytes(get_string(100), 'ascii') else: content = get_string(100) - path = os.path.join(folder, fname) + path = os.path.join(directory, fname) with open(path, mode) as f: f.write(content) return path, content def create_dir(path): - '''Create a folder''' + '''Create a directory''' if not os.path.exists(path): os.mkdir(path) return path @@ -93,10 +93,10 @@ def get_dotfile_from_yaml(dic, path): return [d for d in dotfiles.values() if d['src'] == src][0] -def create_fake_config(folder, configname='config.yaml', +def create_fake_config(directory, configname='config.yaml', dotpath='dotfiles', backup=True, create=True): '''Create a fake config file''' - path = os.path.join(folder, configname) + path = os.path.join(directory, configname) with open(path, 'w') as f: f.write('config:\n') f.write(' backup: %s\n' % (str(backup))) diff --git a/tests/test_compare.py b/tests/test_compare.py index 25e82b9..c61d81c 100644 --- a/tests/test_compare.py +++ b/tests/test_compare.py @@ -49,23 +49,23 @@ class TestCompare(unittest.TestCase): def test_compare(self): '''Test the compare function''' - # setup some folders + # setup some directories fold_config = os.path.join(os.path.expanduser('~'), '.config') create_dir(fold_config) fold_subcfg = os.path.join(os.path.expanduser('~'), '.config', get_string(5)) create_dir(fold_subcfg) self.addCleanup(clean, fold_subcfg) - fold_tmp = get_tempfolder() + fold_tmp = get_tempdir() create_dir(fold_tmp) self.addCleanup(clean, fold_tmp) - # create the folders - tmp = get_tempfolder() + # create the directories + tmp = get_tempdir() self.assertTrue(os.path.exists(tmp)) self.addCleanup(clean, tmp) - dotfilespath = get_tempfolder() + dotfilespath = get_tempdir() self.assertTrue(os.path.exists(dotfilespath)) self.addCleanup(clean, dotfilespath) @@ -82,7 +82,7 @@ class TestCompare(unittest.TestCase): d4, c4 = create_random_file(fold_tmp, binary=True) self.assertTrue(os.path.exists(d4)) self.addCleanup(clean, d4) - d5 = get_tempfolder() + d5 = get_tempdir() self.assertTrue(os.path.exists(d5)) self.addCleanup(clean, d5) d6, _ = create_random_file(d5) @@ -120,7 +120,7 @@ class TestCompare(unittest.TestCase): results = self.compare(opts, conf, tmp, len(dfiles)) self.assertTrue(results == expected) - # add file in folder + # add file in directory d7, _ = create_random_file(d5) self.assertTrue(os.path.exists(d7)) expected = {d1: False, d2: True, d3: True, d4: False, d5: False} diff --git a/tests/test_config.py b/tests/test_config.py index bbaeb0b..f0a2310 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -25,7 +25,7 @@ class TestConfig(unittest.TestCase): def test_config(self): '''Test the config class''' - tmp = get_tempfolder() + tmp = get_tempdir() self.assertTrue(os.path.exists(tmp)) self.addCleanup(clean, tmp) @@ -48,7 +48,7 @@ class TestConfig(unittest.TestCase): self.assertTrue(conf.dump() != '') def test_include(self): - tmp = get_tempfolder() + tmp = get_tempdir() self.assertTrue(os.path.exists(tmp)) self.addCleanup(clean, tmp) diff --git a/tests/test_import.py b/tests/test_import.py index b1d70c3..b60ec1f 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -53,12 +53,12 @@ class TestImport(unittest.TestCase): def test_import(self): '''Test the import function''' # on filesystem - src = get_tempfolder() + src = get_tempdir() self.assertTrue(os.path.exists(src)) self.addCleanup(clean, src) # in dotdrop - dotfilespath = get_tempfolder() + dotfilespath = get_tempdir() self.assertTrue(os.path.exists(dotfilespath)) self.addCleanup(clean, dotfilespath) @@ -87,8 +87,8 @@ class TestImport(unittest.TestCase): dotfile4, content3 = create_random_file(homeconf) self.addCleanup(clean, dotfile4) - # fake a folder containing dotfiles - dotfile5 = get_tempfolder() + # fake a directory containing dotfiles + dotfile5 = get_tempdir() self.assertTrue(os.path.exists(dotfile5)) self.addCleanup(clean, dotfile5) sub1, _ = create_random_file(dotfile5) @@ -98,8 +98,8 @@ class TestImport(unittest.TestCase): dotfile6, content6 = create_random_file(dotconfig) self.addCleanup(clean, dotfile6) - # fake a folder for symlink - dotfile7 = get_tempfolder() + # fake a directory for symlink + dotfile7 = get_tempdir() self.assertTrue(os.path.exists(dotfile7)) self.addCleanup(clean, dotfile7) sub3, _ = create_random_file(dotfile7) @@ -137,7 +137,7 @@ class TestImport(unittest.TestCase): self.assert_in_yaml(dotfile6, y, link=True) self.assert_in_yaml(dotfile7, y, link=True) - # test have been imported in dotdrop dotpath folder + # test have been imported in dotdrop dotpath directory indt1 = os.path.join(dotfilespath, self.CONFIG_DOTPATH, get_path_strip_version(dotfile1)) diff --git a/tests/test_install.py b/tests/test_install.py index c2cd5d1..0af92fd 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -69,12 +69,12 @@ exec bspwm '''Test the install function''' # dotpath location - tmp = get_tempfolder() + tmp = get_tempdir() self.assertTrue(os.path.exists(tmp)) self.addCleanup(clean, tmp) # where dotfiles will be installed - dst = get_tempfolder() + dst = get_tempdir() self.assertTrue(os.path.exists(dst)) self.addCleanup(clean, dst) @@ -106,7 +106,7 @@ exec bspwm self.addCleanup(clean, dst5) d5 = Dotfile(get_string(6), dst5, os.path.basename(f5), link=True) - # create the dotfile folders in dotdrop + # create the dotfile directories in dotdrop dir1 = create_dir(os.path.join(tmp, get_string(6))) self.assertTrue(os.path.exists(dir1)) self.addCleanup(clean, dir1) @@ -119,7 +119,7 @@ exec bspwm # make up the dotfile d6 = Dotfile(get_string(6), dst6, os.path.basename(dir1)) - # to test symlink folders + # to test symlink directories dir2 = create_dir(os.path.join(tmp, get_string(6))) self.assertTrue(os.path.exists(dir2)) self.addCleanup(clean, dir2)