mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-06 23:35:38 +00:00
docstring
This commit is contained in:
@@ -18,7 +18,7 @@ TMPSUFFIX = '.dotdrop'
|
||||
|
||||
|
||||
def clean(path):
|
||||
'''Delete file or directory.'''
|
||||
"""Delete file or directory"""
|
||||
if not os.path.exists(path):
|
||||
return
|
||||
if os.path.islink(path):
|
||||
@@ -30,19 +30,19 @@ def clean(path):
|
||||
|
||||
|
||||
def get_string(length):
|
||||
'''Get a random string of length "length".'''
|
||||
"""Get a random string of length 'length'"""
|
||||
alpha = string.ascii_uppercase + string.digits
|
||||
return ''.join(random.choice(alpha) for _ in range(length))
|
||||
|
||||
|
||||
def get_tempdir():
|
||||
'''Get a temporary directory'''
|
||||
"""Get a temporary directory"""
|
||||
return tempfile.mkdtemp(suffix=TMPSUFFIX)
|
||||
|
||||
|
||||
def create_random_file(directory, content=None,
|
||||
binary=False, template=False):
|
||||
'''Create a new file in directory with random content.'''
|
||||
"""Create a new file in directory with random content"""
|
||||
fname = get_string(8)
|
||||
mode = 'w'
|
||||
if binary:
|
||||
@@ -65,7 +65,7 @@ def create_random_file(directory, content=None,
|
||||
|
||||
|
||||
def edit_content(path, newcontent, binary=False):
|
||||
'''edit file content'''
|
||||
"""edit file content"""
|
||||
mode = 'w'
|
||||
if binary:
|
||||
mode = 'wb'
|
||||
@@ -74,14 +74,14 @@ def edit_content(path, newcontent, binary=False):
|
||||
|
||||
|
||||
def create_dir(path):
|
||||
'''Create a directory'''
|
||||
"""Create a directory"""
|
||||
if not os.path.exists(path):
|
||||
os.mkdir(path)
|
||||
return path
|
||||
|
||||
|
||||
def load_config(confpath, profile):
|
||||
'''Load the config file from path'''
|
||||
"""Load the config file from path"""
|
||||
conf = Cfg(confpath)
|
||||
opts = conf.get_settings()
|
||||
opts['dry'] = False
|
||||
@@ -97,14 +97,14 @@ def load_config(confpath, profile):
|
||||
|
||||
|
||||
def get_path_strip_version(path):
|
||||
'''Return the path of a file as stored in yaml config'''
|
||||
"""Return the path of a file as stored in yaml config"""
|
||||
path = strip_home(path)
|
||||
path = path.lstrip('.' + os.sep)
|
||||
return path
|
||||
|
||||
|
||||
def get_dotfile_from_yaml(dic, path):
|
||||
'''Return the dotfile from the yaml dictionary'''
|
||||
"""Return the dotfile from the yaml dictionary"""
|
||||
# path is not the file in dotpath but on the FS
|
||||
dotfiles = dic['dotfiles']
|
||||
src = get_path_strip_version(path)
|
||||
@@ -113,7 +113,7 @@ def get_dotfile_from_yaml(dic, path):
|
||||
|
||||
def create_fake_config(directory, configname='config.yaml',
|
||||
dotpath='dotfiles', backup=True, create=True):
|
||||
'''Create a fake config file'''
|
||||
"""Create a fake config file"""
|
||||
path = os.path.join(directory, configname)
|
||||
workdir = os.path.join(directory, 'workdir')
|
||||
with open(path, 'w') as f:
|
||||
|
||||
@@ -50,7 +50,7 @@ class TestCompare(unittest.TestCase):
|
||||
return results
|
||||
|
||||
def test_compare(self):
|
||||
'''Test the compare function'''
|
||||
"""Test the compare function"""
|
||||
# setup some directories
|
||||
fold_config = os.path.join(os.path.expanduser('~'), '.config')
|
||||
create_dir(fold_config)
|
||||
|
||||
@@ -24,7 +24,7 @@ class TestConfig(unittest.TestCase):
|
||||
CONFIG_NAME = 'config.yaml'
|
||||
|
||||
def test_config(self):
|
||||
'''Test the config class'''
|
||||
"""Test the config class"""
|
||||
tmp = get_tempdir()
|
||||
self.assertTrue(os.path.exists(tmp))
|
||||
self.addCleanup(clean, tmp)
|
||||
|
||||
@@ -27,7 +27,7 @@ class TestImport(unittest.TestCase):
|
||||
CONFIG_NAME = 'config.yaml'
|
||||
|
||||
def load_yaml(self, path):
|
||||
'''Load yaml to dict'''
|
||||
"""Load yaml to dict"""
|
||||
self.assertTrue(os.path.exists(path))
|
||||
content = ''
|
||||
with open(path, 'r') as f:
|
||||
@@ -35,14 +35,14 @@ class TestImport(unittest.TestCase):
|
||||
return content
|
||||
|
||||
def assert_file(self, path, conf, profile):
|
||||
'''Make sure "path" has been inserted in "conf" for "profile"'''
|
||||
"""Make sure path has been inserted in conf for profile"""
|
||||
strip = get_path_strip_version(path)
|
||||
self.assertTrue(strip in [x.src for x in conf.get_dotfiles(profile)])
|
||||
dsts = [os.path.expanduser(x.dst) for x in conf.get_dotfiles(profile)]
|
||||
self.assertTrue(path in dsts)
|
||||
|
||||
def assert_in_yaml(self, path, dic, link=False):
|
||||
'''Make sure "path" is in the "dic" representing the yaml file'''
|
||||
"""Make sure "path" is in the "dic" representing the yaml file"""
|
||||
strip = get_path_strip_version(path)
|
||||
self.assertTrue(strip in [x['src'] for x in dic['dotfiles'].values()])
|
||||
dsts = [os.path.expanduser(x['dst']) for x in dic['dotfiles'].values()]
|
||||
@@ -51,7 +51,7 @@ class TestImport(unittest.TestCase):
|
||||
self.assertTrue(path in dsts)
|
||||
|
||||
def test_import(self):
|
||||
'''Test the import function'''
|
||||
"""Test the import function"""
|
||||
# on filesystem
|
||||
src = get_tempdir()
|
||||
self.assertTrue(os.path.exists(src))
|
||||
|
||||
@@ -39,7 +39,7 @@ exec bspwm
|
||||
|
||||
def fake_config(self, path, dotfiles, profile,
|
||||
dotpath, actions, trans):
|
||||
'''Create a fake config file'''
|
||||
"""Create a fake config file"""
|
||||
with open(path, 'w') as f:
|
||||
f.write('actions:\n')
|
||||
for action in actions:
|
||||
@@ -74,7 +74,7 @@ exec bspwm
|
||||
return path
|
||||
|
||||
def test_install(self):
|
||||
'''Test the install function'''
|
||||
"""Test the install function"""
|
||||
|
||||
# dotpath location
|
||||
tmp = get_tempdir()
|
||||
|
||||
@@ -26,7 +26,7 @@ class TestListings(unittest.TestCase):
|
||||
CONFIG_NAME = 'config.yaml'
|
||||
|
||||
def test_listings(self):
|
||||
'''Test the compare function'''
|
||||
"""Test the compare function"""
|
||||
# setup some directories
|
||||
fold_config = os.path.join(os.path.expanduser('~'), '.config')
|
||||
create_dir(fold_config)
|
||||
|
||||
@@ -23,7 +23,7 @@ class TestUpdate(unittest.TestCase):
|
||||
CONFIG_NAME = 'config.yaml'
|
||||
|
||||
def test_update(self):
|
||||
'''Test the update function'''
|
||||
"""Test the update function"""
|
||||
# setup some directories
|
||||
fold_config = os.path.join(os.path.expanduser('~'), '.config')
|
||||
create_dir(fold_config)
|
||||
|
||||
Reference in New Issue
Block a user