Ignore:
Timestamp:
24 Nov 2011, 11:31:04 (13 years ago)
Author:
Henrik Bettermann
Message:

Rename functions according to the WAeUP style guide:

functions and methods with property decorator with underscore

methods with CamelCase

Location:
main/waeup.sirp/trunk/src/waeup/sirp/utils
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/helpers.py

    r7175 r7186  
    1919BUFSIZE = 8 * 1024
    2020
    21 def removeFileOrDirectory(filepath):
     21def remove_file_or_directory(filepath):
    2222    """Remove a file or directory.
    2323
     
    3535    return
    3636
    37 def copyFileSystemTree(src, dst, overwrite=False, del_old=False):
     37def copy_filesystem_tree(src, dst, overwrite=False, del_old=False):
    3838    """Copy contents of directory src to directory dst.
    3939
     
    6868        if os.path.exists(itemdst):
    6969            if overwrite is True:
    70                 removeFileOrDirectory(itemdst)
     70                remove_file_or_directory(itemdst)
    7171            else:
    7272                not_copied.append(item)
     
    7878            shutil.copy2(itemsrc, itemdst)
    7979        if del_old:
    80             removeFileOrDirectory(itemsrc)
     80            remove_file_or_directory(itemsrc)
    8181    return not_copied
    8282
    8383
    84 def getInnerHTMLPart(html_code):
     84def get_inner_HTML_part(html_code):
    8585    """Return the 'inner' part of a complete HTML snippet.
    8686
     
    9595
    9696       >>> doc = '<html><form>My Form</form>Outside the form</html>'
    97        >>> getInnerHTMLPart(doc)
     97       >>> get_inner_HTML_part(doc)
    9898       '<form>My Form</form>'
    9999
     
    101101
    102102       >>> doc = '<html><body>My Body</body>Trailing Trash</html>'
    103        >>> getInnerHTMLPart(doc)
     103       >>> get_inner_HTML_part(doc)
    104104       'My Body'
    105105
     
    107107
    108108       >>> doc = '<html>without body nor form</html>'
    109        >>> getInnerHTMLPart(doc)
     109       >>> get_inner_HTML_part(doc)
    110110       '<html>without body nor form</html>'
    111111
     
    309309    if warning_msgs == '':
    310310        warning_msgs = None
    311     result = getInnerHTMLPart(fulldoc).strip()
     311    result = get_inner_HTML_part(fulldoc).strip()
    312312    if not isinstance(result, unicode):
    313313        result = result.decode('utf-8')
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/helpers.txt

    r5140 r7186  
    88.. :doctest:
    99
    10 :func:`removeFileOrDirectory`
    11 =============================
    12 
    13 .. function:: removeFileOrDirectory(path)
     10:func:`remove_file_or_directory`
     11================================
     12
     13.. function:: remove_file_or_directory(path)
    1414
    1515   Removes a file or directory given by a path. We can remove files:
    1616
    1717     >>> import os
    18      >>> from waeup.sirp.utils.helpers import removeFileOrDirectory
     18     >>> from waeup.sirp.utils.helpers import remove_file_or_directory
    1919     >>> open('blah', 'wb').write('nonsense')
    2020     >>> 'blah' in os.listdir('.')
    2121     True
    2222
    23      >>> removeFileOrDirectory('blah')
     23     >>> remove_file_or_directory('blah')
    2424     >>> 'blah' in os.listdir('.')
    2525     False
     
    3131     True
    3232
    33      >>> removeFileOrDirectory('blah')
     33     >>> remove_file_or_directory('blah')
    3434     >>> 'blah' in os.listdir('.')
    3535     False
    3636
    3737
    38 :func:`copyFileSystemTree`
    39 ==========================
    40 
    41 .. function:: copyFileSystemTree(src_path, dst_path[, overwrite=False[, del_old=False]])
     38:func:`copy_filesystem_tree`
     39============================
     40
     41.. function:: ccopy_filesystem_tree(src_path, dst_path[, overwrite=False[, del_old=False]])
    4242
    4343   Copies the contents of an (existing) directory to another
     
    6767     >>> open(os.path.join('src', 'blah'), 'wb').write('nonsense')
    6868
    69      >>> from waeup.sirp.utils.helpers import copyFileSystemTree
    70      >>> result = copyFileSystemTree('src', 'dst')
     69     >>> from waeup.sirp.utils.helpers import copy_filesystem_tree
     70     >>> result = copy_filesystem_tree('src', 'dst')
    7171
    7272   As a result we get a list of non-copied files:
     
    8383
    8484     >>> open(os.path.join('src', '.blah'), 'wb').write('nonsense')
    85      >>> result = copyFileSystemTree('src', 'dst')
     85     >>> result = copy_filesystem_tree('src', 'dst')
    8686     >>> '.blah' in os.listdir('dst')
    8787     False
     
    100100
    101101    >>> open(os.path.join('src', 'blah'), 'wb').write('newnonsense')
    102     >>> result = copyFileSystemTree('src', 'dst')
     102    >>> result = copy_filesystem_tree('src', 'dst')
    103103    >>> open(os.path.join('dst', 'blah'), 'rb').read()
    104104    'nonsense'
     
    113113overwritten:
    114114
    115     >>> result = copyFileSystemTree('src', 'dst', overwrite=True)
     115    >>> result = copy_filesystem_tree('src', 'dst', overwrite=True)
    116116    >>> open(os.path.join('dst', 'blah'), 'rb').read()
    117117    'newnonsense'
     
    129129    ...   'dst', 'mydir', 'blah'), 'wb').write('dstblah')
    130130
    131     >>> result = copyFileSystemTree('src', 'dst', overwrite=True)
     131    >>> result = copy_filesystem_tree('src', 'dst', overwrite=True)
    132132    >>> open(os.path.join('dst', 'mydir', 'blah'), 'rb').read()
    133133    'srcblah'
     
    140140removed from the src dir. Default is `False`.
    141141
    142     >>> result = copyFileSystemTree('src', 'dst', overwrite=True,
     142    >>> result = copy_filesystem_tree('src', 'dst', overwrite=True,
    143143    ...                                           del_old=True)
    144144    >>> os.listdir('src')
     
    151151Clean up:
    152152
    153     >>> removeFileOrDirectory('src')
    154     >>> removeFileOrDirectory('dst')
    155 
    156 
    157 :func:`getInnerHTMLPart()`
    158 ==========================
    159 
    160 .. function:: getInnerHTMLPart(html_code)
     153    >>> remove_file_or_directory('src')
     154    >>> remove_file_or_directory('dst')
     155
     156
     157:func:`get_inner_HTML_part()`
     158=============================
     159
     160.. function:: get_inner_HTML_part(html_code)
    161161
    162162   Get the 'inner' part out of a piece of HTML code.
     
    172172   returned with all preceeding/following stuff stripped:
    173173
    174      >>> from waeup.sirp.utils.helpers import getInnerHTMLPart
    175      >>> print getInnerHTMLPart("""<html>
     174     >>> from waeup.sirp.utils.helpers import get_inner_HTML_part
     175     >>> print get_inner_HTML_part("""<html>
    176176     ... <head>
    177177     ... </head>
     
    198198   If there is no ``<form>`` part, try to find any ``<body>`` part:
    199199
    200      >>> print getInnerHTMLPart("""<html>
     200     >>> print get_inner_HTML_part("""<html>
    201201     ... <head>
    202202     ... </head>
     
    213213   If there is also no ``<body>`` tag, we return the input as-is:
    214214
    215      >>> print getInnerHTMLPart("""<div>
     215     >>> print get_inner_HTML_part("""<div>
    216216     ...  <div>Some content</div>
    217217     ... </div>
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/tests/test_helpers.py

    r7137 r7186  
    5454
    5555    def test_handle_not_existing_path(self):
    56         result = helpers.removeFileOrDirectory(self.non_file)
     56        result = helpers.remove_file_or_directory(self.non_file)
    5757        self.assertTrue(result is None)
    5858        return
    5959
    6060    def test_handle_dir(self):
    61         helpers.removeFileOrDirectory(self.dirpath)
     61        helpers.remove_file_or_directory(self.dirpath)
    6262        self.assertFalse(
    6363            os.path.exists(self.dirpath)
     
    6666
    6767    def test_handle_file(self):
    68         helpers.removeFileOrDirectory(self.filepath)
     68        helpers.remove_file_or_directory(self.filepath)
    6969        self.assertFalse(
    7070            os.path.exists(self.filepath)
     
    7373
    7474class CopyFileSystemTreeTestCase(unittest.TestCase):
    75     # Test edge cases of copyFileSystemTree().
     75    # Test edge cases of copy_filesystem_tree().
    7676    #
    7777    # This is a typical case of tests not written as doctest as it is
     
    9494
    9595    def test_source_and_dst_existing(self):
    96         helpers.copyFileSystemTree(self.existing_src, self.existing_dst)
     96        helpers.copy_filesystem_tree(self.existing_src, self.existing_dst)
    9797        self.assertTrue(
    9898            os.path.exists(
     
    105105        self.assertRaises(
    106106            ValueError,
    107             helpers.copyFileSystemTree,
     107            helpers.copy_filesystem_tree,
    108108            self.not_existing_dir,
    109109            self.existing_dst
     
    114114        self.assertRaises(
    115115            ValueError,
    116             helpers.copyFileSystemTree,
     116            helpers.copy_filesystem_tree,
    117117            self.existing_src,
    118118            self.not_existing_dir
     
    123123        self.assertRaises(
    124124            ValueError,
    125             helpers.copyFileSystemTree,
     125            helpers.copy_filesystem_tree,
    126126            self.filepath,
    127127            self.existing_dst
     
    132132        self.assertRaises(
    133133            ValueError,
    134             helpers.copyFileSystemTree,
     134            helpers.copy_filesystem_tree,
    135135            self.existing_src,
    136136            self.filepath
Note: See TracChangeset for help on using the changeset viewer.