def export(from_dir, to_dir, blacklist=BASE_BLACKLIST, ignore_ext=IGNORED_EXTENSIONS, verbose=0): """Make a mirror of `from_dir` in `to_dir`, omitting directories and files listed in the black list or ending with one of the given extensions. :type from_dir: str :param from_dir: directory to export :type to_dir: str :param to_dir: destination directory :type blacklist: list or tuple :param blacklist: list of files or directories to ignore, default to the content of `BASE_BLACKLIST` :type ignore_ext: list or tuple :param ignore_ext: list of extensions to ignore, default to the content of `IGNORED_EXTENSIONS` :type verbose: bool :param verbose: flag indicating whether information about exported files should be printed to stderr, default to False """ try: mkdir(to_dir) except OSError: pass # FIXME we should use "exists" if the point is about existing dir # else (permission problems?) shouldn't return / raise ? for directory, dirnames, filenames in walk(from_dir): for norecurs in blacklist: try: dirnames.remove(norecurs) except ValueError: continue for dirname in dirnames: src = join(directory, dirname) dest = to_dir + src[len(from_dir):] if isdir(src): if not exists(dest): mkdir(dest) for filename in filenames: # don't include binary files # endswith does not accept tuple in 2.4 if any([filename.endswith(ext) for ext in ignore_ext]): continue src = join(directory, filename) dest = to_dir + src[len(from_dir):] if verbose: print >> sys.stderr, src, '->', dest if exists(dest): remove(dest) shutil.copy2(src, dest)
def visit_discard(self, node): """check for various kind of statements without effect""" expr = node.value if isinstance(expr, astng.Const) and isinstance(expr.value, basestring): # treat string statement in a separated message self.add_message('W0105', node=node) return # ignore if this is : # * a function call (can't predicate side effects) # * the unique children of a try/except body # * a yield (which are wrapped by a discard node in _ast XXX) if not (any(expr.nodes_of_class((astng.CallFunc, astng.Yield))) or isinstance(node.parent, astng.TryExcept) and node.parent.body == [node]): self.add_message('W0104', node=node)
def test_any(self): from logilab.common.compat import any testdata = ([], (), '', 'abc', range(0, 10), range(0, -10, -1)) self.assertEqual(any([]), False) self.assertEqual(any(()), False) self.assertEqual(any(''), False) self.assertEqual(any('abc'), True) self.assertEqual(any(range(10)), True) self.assertEqual(any(range(0, -10, -1)), True) # python2.5's any consumes iterables irange = iter(list(range(10))) self.assertEqual(any(irange), True) self.assertEqual(next(irange), 2)
def test_any(self): from logilab.common.compat import any testdata = ([], (), '', 'abc', xrange(0, 10), xrange(0, -10, -1)) self.assertEquals(any([]), False) self.assertEquals(any(()), False) self.assertEquals(any(''), False) self.assertEquals(any('abc'), True) self.assertEquals(any(xrange(10)), True) self.assertEquals(any(xrange(0, -10, -1)), True) # python2.5's any consumes iterables irange = iter(range(10)) self.assertEquals(any(irange), True) self.assertEquals(irange.next(), 2)
def test_any(self): from logilab.common.compat import any testdata = ([], (), "", "abc", range(0, 10), range(0, -10, -1)) self.assertEqual(any([]), False) self.assertEqual(any(()), False) self.assertEqual(any(""), False) self.assertEqual(any("abc"), True) self.assertEqual(any(range(10)), True) self.assertEqual(any(range(0, -10, -1)), True) # python2.5's any consumes iterables irange = iter(list(range(10))) self.assertEqual(any(irange), True) self.assertEqual(next(irange), 2)
def _this_is_skipped(self, testedname): return any([(pat in testedname) for pat in self.skipped_patterns])