Repository: physiopy/phys2bids

Issue:
Rename utils.writefile() to utils.write_file()
<!--- Provide a general summary of the issue in the Title above -->
<!--- Please label the issue with one of the following: Documentation, Outreach or Question -->

## Summary
<!--- Describe the motivation behind the issue -->
Most of the functions in `phys2bids.utils` are in PEP8-compatible snake case, but [`phys2bids.utils.writefile()`](https://github.com/physiopy/phys2bids/blob/da3a5306a91a046f3956f1d033b6f86b5c14611b/phys2bids/utils.py#L212) is not. We can rename it to `write_file()` to match convention.

## Next Steps
<!--- Provide possible steps to take in order to address the issue -->

    * Rename the function
    * Update tests
    * Update all uses of the function throughout the package
    * Update the API page of the docs


Discussion:

Patch:
diff --git a/phys2bids/bids.py b/phys2bids/bids.py
index 946007e..18a101b 100644
--- a/phys2bids/bids.py
+++ b/phys2bids/bids.py
@@ -289,4 +289,4 @@ def readme_file(outdir):
         text = 'Empty README, please fill in describing the dataset in more detail.'
         LGR.warning('phys2bids could not find README,'
                     'generating it EMPTY, please fill in the necessary info')
-        utils.writefile(file_path, '', text)
+        utils.write_file(file_path, '', text)
diff --git a/phys2bids/phys2bids.py b/phys2bids/phys2bids.py
index 1710fe5..8b5cbc8 100644
--- a/phys2bids/phys2bids.py
+++ b/phys2bids/phys2bids.py
@@ -84,7 +84,7 @@ def print_summary(filename, ntp_expected, ntp_found, samp_freq, time_offset, out
                f'Tip: Time 0 is the time of first trigger\n'
                f'------------------------------------------------\n')
     LGR.info(summary)
-    utils.writefile(outfile, '.log', summary)
+    utils.write_file(outfile, '.log', summary)
 
 
 def print_json(outfile, samp_freq, time_offset, ch_name):
diff --git a/phys2bids/utils.py b/phys2bids/utils.py
index 8c3c1e3..710eacf 100644
--- a/phys2bids/utils.py
+++ b/phys2bids/utils.py
@@ -149,6 +149,35 @@ def check_file_exists(filename):
         raise FileNotFoundError(f'The file {filename} does not exist!')
 
 
+def move_file(oldpath, newpath, ext=''):
+    """
+    Move file from oldpath to newpath.
+
+    If file already exists, removes it first.
+
+    Parameters
+    ----------
+    oldpath: str or path
+        A string or a fullpath to a file that has to be moved
+    newpath: str or path
+        A string or a fullpath to the new destination of the file
+    ext: str
+        Possible extension to add to the oldpath and newpath. Not necessary.
+
+    Notes
+    -----
+    Outcome:
+    newpath + ext:
+        Moves file to new destination
+    """
+    check_file_exists(oldpath + ext)
+
+    if os.path.isfile(newpath + ext):
+        os.remove(newpath + ext)
+
+    os.rename(oldpath + ext, newpath + ext)
+
+
 def copy_file(oldpath, newpath, ext=''):
     """
     Copy file from oldpath to newpath.
@@ -180,7 +209,7 @@ def copy_file(oldpath, newpath, ext=''):
     cp(oldpath + ext, newpath + ext)
 
 
-def writefile(filename, ext, text):
+def write_file(filename, ext, text):
     """
     Produce a textfile of the specified extension `ext`.
 


Test patch:
diff --git a/phys2bids/tests/test_utils.py b/phys2bids/tests/test_utils.py
index 98c6731..03b9e02 100644
--- a/phys2bids/tests/test_utils.py
+++ b/phys2bids/tests/test_utils.py
@@ -58,6 +58,17 @@ def test_check_file_exists(samefreq_full_acq_file):
     assert 'does not exist' in str(errorinfo.value)
 
 
+# Tests move_file
+def test_move_file(tmpdir):
+    ext = '.txt'
+    test_old_path = tmpdir.join('foo.txt')
+    with open(test_old_path, 'a'):
+        pass
+    test_old_path = str(test_old_path)[:-4]
+    test_new_path = tmpdir.join('mrmeeseeks')
+    utils.move_file(test_old_path, test_new_path, ext)
+
+
 # Tests copy_file
 def test_copy_file(tmpdir):
     ext = '.txt'
@@ -67,12 +78,12 @@ def test_copy_file(tmpdir):
     utils.copy_file(test_old_path, test_new_path, ext)
 
 
-# Tests writefile
-def test_writefile(tmpdir):
+# Tests write_file
+def test_write_file(tmpdir):
     ext = '.txt'
     test_old_path = tmpdir.join('foo.txt')
     test_text = 'Wubba lubba dub dub!'
-    utils.writefile(test_old_path, ext, test_text)
+    utils.write_file(test_old_path, ext, test_text)
 
 
 # Tests writejson