Henrique Romano avatar Henrique Romano committed 1d83def

patches module isn't specific to trac package

Comments (0)

Files changed (3)

djangotriager/patches.py

+from subprocess import Popen, PIPE
+
+class Patch(object):
+    """A class to help working with patches.
+
+    You can use it to apply a patch on a directory, retrieve all files in 
+    the patch or the files that failed to apply. To use it, you just need
+    to supply the patch content.
+    """
+    MAX_APPLY_ATTEMPTS = 2
+    VALID_EXTENSIONS = ("diff", "patch")
+
+    def __init__(self, patch_id, content):
+        self._patch_id = patch_id
+        self._content = content
+
+    def __repr__(self):
+        return "<Patch %r>" % self._patch_id
+
+    @classmethod
+    def validate(self, filename):
+        # FIXME: don't try to guess file type through its extension
+        parts = filename.rsplit(".", 1)
+        return len(parts) == 2 and parts[1] in Patch.VALID_EXTENSIONS
+
+    def apply(self, where, prefix=0, logger=None):
+        proc = Popen(["patch", "-p%d" % prefix, "-f"], cwd=where, stdin=PIPE,
+                     stdout=PIPE, stderr=PIPE)
+        stdout, stderr = proc.communicate(self._content)
+        if proc.returncode != 0:
+            if logger:
+                logger.info("Patch could not be applied with prefix=%r" % prefix)
+            if prefix < Patch.MAX_APPLY_ATTEMPTS:
+                return self.apply(where, prefix=prefix + 1, logger=logger)
+            else:
+                return False
+        else:
+            logger.info("Patch applied successfully")
+        return True

djangotriager/trac/patches.py

-from subprocess import Popen, PIPE
-
-class Patch(object):
-    """A class to help working with patches.
-
-    You can use it to apply a patch on a directory, retrieve all files in 
-    the patch or the files that failed to apply. To use it, you just need
-    to supply the patch content.
-    """
-    MAX_APPLY_ATTEMPTS = 2
-    VALID_EXTENSIONS = ("diff", "patch")
-
-    def __init__(self, patch_id, content):
-        self._patch_id = patch_id
-        self._content = content
-
-    def __repr__(self):
-        return "<Patch %r>" % self._patch_id
-
-    @classmethod
-    def validate(self, filename):
-        # FIXME: don't try to guess file type through its extension
-        parts = filename.rsplit(".", 1)
-        return len(parts) == 2 and parts[1] in Patch.VALID_EXTENSIONS
-
-    def apply(self, where, prefix=0, logger=None):
-        proc = Popen(["patch", "-p%d" % prefix, "-f"], cwd=where, stdin=PIPE,
-                     stdout=PIPE, stderr=PIPE)
-        stdout, stderr = proc.communicate(self._content)
-        if proc.returncode != 0:
-            if logger:
-                logger.info("Patch could not be applied with prefix=%r" % prefix)
-            if prefix < Patch.MAX_APPLY_ATTEMPTS:
-                return self.apply(where, prefix=prefix + 1, logger=logger)
-            else:
-                return False
-        else:
-            logger.info("Patch applied successfully")
-        return True

djangotriager/trac/tickets.py

 from djangotriager.trac.server import get_proxy
-from djangotriager.trac.patches import Patch
+from djangotriager.patches import Patch
 
 from djangotriager.tests import TestRunner
 from djangotriager.reporter import Reporter
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.