# Path: quilt/patch.py
# class Patch(_EqBase):
# 
#     """ Wrapper around the patch util """
# 
#     def __init__(self, patch_name, strip=1, reverse=False):
#         self.patch_name = patch_name
#         self.strip = strip
#         self.reverse = reverse
# 
#     @DirectoryParam(["patch_dir", "work_dir"])
#     def run(self, cwd, patch_dir=None, backup=False, prefix=None,
#             reverse=False, work_dir=None, force=False, dry_run=False,
#             no_backup_if_mismatch=False, remove_empty_files=False,
#             quiet=False, suppress_output=False):
#         cmd = ["patch"]
#         cmd.append("-p" + str(self.strip))
# 
#         if backup:
#             cmd.append("--backup")
# 
#         if prefix:
#             cmd.append("--prefix")
#             if not prefix[-1] == os.sep:
#                 prefix += os.sep
#             cmd.append(prefix)
# 
#         reverse = reverse != self.reverse
#         if reverse:
#             cmd.append("-R")
# 
#         if work_dir:
#             cmd.append("-d")
#             cmd.append(work_dir.get_name())
# 
#         if no_backup_if_mismatch:
#             cmd.append("--no-backup-if-mismatch")
# 
#         if remove_empty_files:
#             cmd.append("--remove-empty-files")
# 
#         if force:
#             cmd.append("-f")
# 
#         cmd.append("-i")
#         if patch_dir:
#             dir = patch_dir + self.get_name()
#             name = dir.get_name()
#         else:
#             name = self.get_name()
#         cmd.append(name)
# 
#         if quiet:
#             cmd.append("-s")
# 
#         if dry_run:
#             cmd.append("--dry-run")
# 
#         Process(cmd).run(cwd=cwd, suppress_output=suppress_output)
# 
#     def get_name(self):
#         return self.patch_name
# 
#     @DirectoryParam(["patch_dir"])
#     def get_header(self, patch_dir=None):
#         """ Returns bytes """
#         lines = []
# 
#         if patch_dir:
#             file = patch_dir + File(self.get_name())
#             name = file.get_name()
#         else:
#             name = self.get_name()
#         with open(name, "rb") as f:
#             for line in f:
#                 if line.startswith(b"---") or line.startswith(b"Index:"):
#                     break
#                 lines.append(line)
# 
#         return b"".join(lines)
# 
#     def __eq__(self, other):
#         return (isinstance(other, Patch) and self.get_name() ==
#                 other.get_name())
# 
#     def __hash__(self):
#         return hash(self.get_name())
# 
#     def __str__(self):
#         return self.get_name()
# 
#     def __repr__(self):
#         return "<Patch(%r, %r, %r) id=0x%0x>" % (self.get_name(), self.strip,
#                                                  self.reverse, id(self))
# 
# Path: quilt/utils.py
# def _encode_str(s):
#     return s


import getopt
import os.path
import six
import sys
from quilt.error import QuiltError, UnknownPatch
from quilt.patch import Patch
from quilt.utils import _encode_str
            patchline, self.comment = line.split("#", 1)
        else:
            patchline = line

        patchline = patchline.strip()
        if not patchline:
            return

        patch_args = None
        strip = 1
        reverse = False

        if " " in patchline:
            patch_name, patch_args = patchline.split(" ", 1)
        else:
            patch_name = patchline

        if patch_args:
            patch_args = patch_args.split()
            try:
                opts, args = getopt.getopt(patch_args, "p:R", ["strip=",
                                                               "reverse"])
                for o, a in opts:
                    if o in ["-p", "--strip"]:
                        strip = a
                    elif o in ["-R", "--reverse"]:
                        reverse = True
            except getopt.GetoptError as err:
                print(err, file=sys.stderr)


# Path: quilt/patch.py
# class Patch(_EqBase):
# 
#     """ Wrapper around the patch util """
# 
#     def __init__(self, patch_name, strip=1, reverse=False):
#         self.patch_name = patch_name
#         self.strip = strip
#         self.reverse = reverse
# 
#     @DirectoryParam(["patch_dir", "work_dir"])
#     def run(self, cwd, patch_dir=None, backup=False, prefix=None,
#             reverse=False, work_dir=None, force=False, dry_run=False,
#             no_backup_if_mismatch=False, remove_empty_files=False,
#             quiet=False, suppress_output=False):
#         cmd = ["patch"]
#         cmd.append("-p" + str(self.strip))
# 
#         if backup:
#             cmd.append("--backup")
# 
#         if prefix:
#             cmd.append("--prefix")
#             if not prefix[-1] == os.sep:
#                 prefix += os.sep
#             cmd.append(prefix)
# 
#         reverse = reverse != self.reverse
#         if reverse:
#             cmd.append("-R")
# 
#         if work_dir:
#             cmd.append("-d")
#             cmd.append(work_dir.get_name())
# 
#         if no_backup_if_mismatch:
#             cmd.append("--no-backup-if-mismatch")
# 
#         if remove_empty_files:
#             cmd.append("--remove-empty-files")
# 
#         if force:
#             cmd.append("-f")
# 
#         cmd.append("-i")
#         if patch_dir:
#             dir = patch_dir + self.get_name()
#             name = dir.get_name()
#         else:
#             name = self.get_name()
#         cmd.append(name)
# 
#         if quiet:
#             cmd.append("-s")
# 
#         if dry_run:
#             cmd.append("--dry-run")
# 
#         Process(cmd).run(cwd=cwd, suppress_output=suppress_output)
# 
#     def get_name(self):
#         return self.patch_name
# 
#     @DirectoryParam(["patch_dir"])
#     def get_header(self, patch_dir=None):
#         """ Returns bytes """
#         lines = []
# 
#         if patch_dir:
#             file = patch_dir + File(self.get_name())
#             name = file.get_name()
#         else:
#             name = self.get_name()
#         with open(name, "rb") as f:
#             for line in f:
#                 if line.startswith(b"---") or line.startswith(b"Index:"):
#                     break
#                 lines.append(line)
# 
#         return b"".join(lines)
# 
#     def __eq__(self, other):
#         return (isinstance(other, Patch) and self.get_name() ==
#                 other.get_name())
# 
#     def __hash__(self):
#         return hash(self.get_name())
# 
#     def __str__(self):
#         return self.get_name()
# 
#     def __repr__(self):
#         return "<Patch(%r, %r, %r) id=0x%0x>" % (self.get_name(), self.strip,
#                                                  self.reverse, id(self))
# 
# Path: quilt/utils.py
# def _encode_str(s):
#     return s


# Path: quilt/db.py
import getopt
import os.path
import six
import sys
from quilt.error import QuiltError, UnknownPatch
from quilt.patch import Patch
from quilt.utils import _encode_str

            patchline, self.comment = line.split("#", 1)
        else:
            patchline = line

        patchline = patchline.strip()
        if not patchline:
            return

        patch_args = None
        strip = 1
        reverse = False

        if " " in patchline:
            patch_name, patch_args = patchline.split(" ", 1)
        else:
            patch_name = patchline

        if patch_args:
            patch_args = patch_args.split()
            try:
                opts, args = getopt.getopt(patch_args, "p:R", ["strip=",
                                                               "reverse"])
                for o, a in opts:
                    if o in ["-p", "--strip"]:
                        strip = a
                    elif o in ["-R", "--reverse"]:
                        reverse = True
            except getopt.GetoptError as err:
                print(err, file=sys.stderr)


        self.patch = Patch(patch_name, strip, reverse)