1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 14:31:46 +00:00

refactor folder to directory

This commit is contained in:
deadc0de6
2018-05-02 20:40:42 +02:00
parent b0847b2b4c
commit 927d76779f
7 changed files with 43 additions and 43 deletions

View File

@@ -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; }

View File

@@ -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 == '':

View File

@@ -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)))

View File

@@ -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}

View File

@@ -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)

View File

@@ -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))

View File

@@ -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)