Changeset 7186 for main/waeup.sirp/trunk/src/waeup/sirp/utils
- Timestamp:
- 24 Nov 2011, 11:31:04 (13 years ago)
- 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 19 19 BUFSIZE = 8 * 1024 20 20 21 def remove FileOrDirectory(filepath):21 def remove_file_or_directory(filepath): 22 22 """Remove a file or directory. 23 23 … … 35 35 return 36 36 37 def copy FileSystemTree(src, dst, overwrite=False, del_old=False):37 def copy_filesystem_tree(src, dst, overwrite=False, del_old=False): 38 38 """Copy contents of directory src to directory dst. 39 39 … … 68 68 if os.path.exists(itemdst): 69 69 if overwrite is True: 70 remove FileOrDirectory(itemdst)70 remove_file_or_directory(itemdst) 71 71 else: 72 72 not_copied.append(item) … … 78 78 shutil.copy2(itemsrc, itemdst) 79 79 if del_old: 80 remove FileOrDirectory(itemsrc)80 remove_file_or_directory(itemsrc) 81 81 return not_copied 82 82 83 83 84 def get InnerHTMLPart(html_code):84 def get_inner_HTML_part(html_code): 85 85 """Return the 'inner' part of a complete HTML snippet. 86 86 … … 95 95 96 96 >>> doc = '<html><form>My Form</form>Outside the form</html>' 97 >>> get InnerHTMLPart(doc)97 >>> get_inner_HTML_part(doc) 98 98 '<form>My Form</form>' 99 99 … … 101 101 102 102 >>> doc = '<html><body>My Body</body>Trailing Trash</html>' 103 >>> get InnerHTMLPart(doc)103 >>> get_inner_HTML_part(doc) 104 104 'My Body' 105 105 … … 107 107 108 108 >>> doc = '<html>without body nor form</html>' 109 >>> get InnerHTMLPart(doc)109 >>> get_inner_HTML_part(doc) 110 110 '<html>without body nor form</html>' 111 111 … … 309 309 if warning_msgs == '': 310 310 warning_msgs = None 311 result = get InnerHTMLPart(fulldoc).strip()311 result = get_inner_HTML_part(fulldoc).strip() 312 312 if not isinstance(result, unicode): 313 313 result = result.decode('utf-8') -
main/waeup.sirp/trunk/src/waeup/sirp/utils/helpers.txt
r5140 r7186 8 8 .. :doctest: 9 9 10 :func:`remove FileOrDirectory`11 ============================= 12 13 .. function:: remove FileOrDirectory(path)10 :func:`remove_file_or_directory` 11 ================================ 12 13 .. function:: remove_file_or_directory(path) 14 14 15 15 Removes a file or directory given by a path. We can remove files: 16 16 17 17 >>> import os 18 >>> from waeup.sirp.utils.helpers import remove FileOrDirectory18 >>> from waeup.sirp.utils.helpers import remove_file_or_directory 19 19 >>> open('blah', 'wb').write('nonsense') 20 20 >>> 'blah' in os.listdir('.') 21 21 True 22 22 23 >>> remove FileOrDirectory('blah')23 >>> remove_file_or_directory('blah') 24 24 >>> 'blah' in os.listdir('.') 25 25 False … … 31 31 True 32 32 33 >>> remove FileOrDirectory('blah')33 >>> remove_file_or_directory('blah') 34 34 >>> 'blah' in os.listdir('.') 35 35 False 36 36 37 37 38 :func:`copy FileSystemTree`39 ========================== 40 41 .. function:: c opyFileSystemTree(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]]) 42 42 43 43 Copies the contents of an (existing) directory to another … … 67 67 >>> open(os.path.join('src', 'blah'), 'wb').write('nonsense') 68 68 69 >>> from waeup.sirp.utils.helpers import copy FileSystemTree70 >>> result = copy FileSystemTree('src', 'dst')69 >>> from waeup.sirp.utils.helpers import copy_filesystem_tree 70 >>> result = copy_filesystem_tree('src', 'dst') 71 71 72 72 As a result we get a list of non-copied files: … … 83 83 84 84 >>> open(os.path.join('src', '.blah'), 'wb').write('nonsense') 85 >>> result = copy FileSystemTree('src', 'dst')85 >>> result = copy_filesystem_tree('src', 'dst') 86 86 >>> '.blah' in os.listdir('dst') 87 87 False … … 100 100 101 101 >>> open(os.path.join('src', 'blah'), 'wb').write('newnonsense') 102 >>> result = copy FileSystemTree('src', 'dst')102 >>> result = copy_filesystem_tree('src', 'dst') 103 103 >>> open(os.path.join('dst', 'blah'), 'rb').read() 104 104 'nonsense' … … 113 113 overwritten: 114 114 115 >>> result = copy FileSystemTree('src', 'dst', overwrite=True)115 >>> result = copy_filesystem_tree('src', 'dst', overwrite=True) 116 116 >>> open(os.path.join('dst', 'blah'), 'rb').read() 117 117 'newnonsense' … … 129 129 ... 'dst', 'mydir', 'blah'), 'wb').write('dstblah') 130 130 131 >>> result = copy FileSystemTree('src', 'dst', overwrite=True)131 >>> result = copy_filesystem_tree('src', 'dst', overwrite=True) 132 132 >>> open(os.path.join('dst', 'mydir', 'blah'), 'rb').read() 133 133 'srcblah' … … 140 140 removed from the src dir. Default is `False`. 141 141 142 >>> result = copy FileSystemTree('src', 'dst', overwrite=True,142 >>> result = copy_filesystem_tree('src', 'dst', overwrite=True, 143 143 ... del_old=True) 144 144 >>> os.listdir('src') … … 151 151 Clean up: 152 152 153 >>> remove FileOrDirectory('src')154 >>> remove FileOrDirectory('dst')155 156 157 :func:`get InnerHTMLPart()`158 ========================== 159 160 .. function:: get InnerHTMLPart(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) 161 161 162 162 Get the 'inner' part out of a piece of HTML code. … … 172 172 returned with all preceeding/following stuff stripped: 173 173 174 >>> from waeup.sirp.utils.helpers import get InnerHTMLPart175 >>> print get InnerHTMLPart("""<html>174 >>> from waeup.sirp.utils.helpers import get_inner_HTML_part 175 >>> print get_inner_HTML_part("""<html> 176 176 ... <head> 177 177 ... </head> … … 198 198 If there is no ``<form>`` part, try to find any ``<body>`` part: 199 199 200 >>> print get InnerHTMLPart("""<html>200 >>> print get_inner_HTML_part("""<html> 201 201 ... <head> 202 202 ... </head> … … 213 213 If there is also no ``<body>`` tag, we return the input as-is: 214 214 215 >>> print get InnerHTMLPart("""<div>215 >>> print get_inner_HTML_part("""<div> 216 216 ... <div>Some content</div> 217 217 ... </div> -
main/waeup.sirp/trunk/src/waeup/sirp/utils/tests/test_helpers.py
r7137 r7186 54 54 55 55 def test_handle_not_existing_path(self): 56 result = helpers.remove FileOrDirectory(self.non_file)56 result = helpers.remove_file_or_directory(self.non_file) 57 57 self.assertTrue(result is None) 58 58 return 59 59 60 60 def test_handle_dir(self): 61 helpers.remove FileOrDirectory(self.dirpath)61 helpers.remove_file_or_directory(self.dirpath) 62 62 self.assertFalse( 63 63 os.path.exists(self.dirpath) … … 66 66 67 67 def test_handle_file(self): 68 helpers.remove FileOrDirectory(self.filepath)68 helpers.remove_file_or_directory(self.filepath) 69 69 self.assertFalse( 70 70 os.path.exists(self.filepath) … … 73 73 74 74 class CopyFileSystemTreeTestCase(unittest.TestCase): 75 # Test edge cases of copy FileSystemTree().75 # Test edge cases of copy_filesystem_tree(). 76 76 # 77 77 # This is a typical case of tests not written as doctest as it is … … 94 94 95 95 def test_source_and_dst_existing(self): 96 helpers.copy FileSystemTree(self.existing_src, self.existing_dst)96 helpers.copy_filesystem_tree(self.existing_src, self.existing_dst) 97 97 self.assertTrue( 98 98 os.path.exists( … … 105 105 self.assertRaises( 106 106 ValueError, 107 helpers.copy FileSystemTree,107 helpers.copy_filesystem_tree, 108 108 self.not_existing_dir, 109 109 self.existing_dst … … 114 114 self.assertRaises( 115 115 ValueError, 116 helpers.copy FileSystemTree,116 helpers.copy_filesystem_tree, 117 117 self.existing_src, 118 118 self.not_existing_dir … … 123 123 self.assertRaises( 124 124 ValueError, 125 helpers.copy FileSystemTree,125 helpers.copy_filesystem_tree, 126 126 self.filepath, 127 127 self.existing_dst … … 132 132 self.assertRaises( 133 133 ValueError, 134 helpers.copy FileSystemTree,134 helpers.copy_filesystem_tree, 135 135 self.existing_src, 136 136 self.filepath
Note: See TracChangeset for help on using the changeset viewer.