# Path: quilt/cli/parser.py
# class Argument(object):
# 
#     """
#     A class to declare positional arguments at a class
# 
#     Usage:
#         class MyParser(Parser):
# 
#             arg1 = Argument(help="A first string argument")
#             arg2 = Argument(type=int)
#             arg3 = Argument(nargs=2)
#     """
# 
#     creation_counter = 0
# 
#     def __init__(self, *args, **kwargs):
#         """
#         Constructs an Argument instance
# 
#         args and kwargs are passed directly to
#         argparse.ArgumentParser.add_argument
#         """
#         self.args = args
#         self.kwargs = kwargs
#         self.creation_counter = Argument.creation_counter
#         Argument.creation_counter += 1
# 
#     def _get_kwargs(self):
#         if self.args:
#             return self.kwargs
# 
#         kwargs = {"dest": self.name}
#         kwargs.update(self.kwargs)
#         return kwargs
# 
#     def _get_args(self):
#         return self.args
# 
#     def add_to_parser(self, parser):
#         """
#         Adds the argument to an argparse.ArgumentParser instance
# 
#         @param parser An argparse.ArgumentParser instance
#         """
#         kwargs = self._get_kwargs()
#         args = self._get_args()
#         parser.add_argument(*args, **kwargs)
# 
#     def set_name(self, name):
#         """
#         Sets the name of this Argument.
#         Normally this method should not be called directly.
#         It is used by the ArgumentsCollectorMetaClass.
# 
#         @param name A string for a name
#         """
#         self.name = name
# 
# Path: quilt/new.py
# class New(Command):
# 
#     patch_created = Signal()
# 
#     """ Creates a new patch in the queue """
#     def __init__(self, cwd, quilt_pc, quilt_patches):
#         super(New, self).__init__(cwd)
#         self.quilt_pc = Directory(quilt_pc)
#         self.quilt_patches = Directory(quilt_patches)
#         self.db = Db(quilt_pc)
#         self.series = Series(quilt_patches)
# 
#     def create(self, patchname):
#         """ Adds a new patch with patchname to the queue
# 
#         The new patch will be added as the topmost applied patch.
#         """
#         patch = Patch(patchname)
#         if self.series.is_patch(patch):
#             raise PatchAlreadyExists(self.series, patchname)
# 
#         patch_dir = self.quilt_patches
#         patch_dir.create()
#         patchfile = patch_dir + File(patchname)
#         patchfile.touch()
# 
#         pc_dir = self.quilt_pc + patchname
#         if pc_dir.exists():
#             # be sure that the directory is clear
#             pc_dir.delete()
# 
#         # create empty .pc/<patchname> directory as quilt does too
#         pc_dir.create()
# 
#         top = self.db.top_patch()
#         # add new patch after the current topmost applied patch
#         self.series.add_patches([patch], top)
#         # "apply" patch
#         self.db.add_patch(patch)
# 
#         # create patches/series files
#         self.series.save()
#         # create .pc/.version and .pc/applied-patches files
#         self.db.save()
# 
#         self.patch_created(patch)


from quilt.cli.meta import Command
from quilt.cli.parser import Argument
from quilt.error import PatchAlreadyExists
from quilt.new import New
# vim: fileencoding=utf-8 et sw=4 ts=4 tw=80:

# python-quilt - A Python implementation of the quilt patch system
#
# Copyright (C) 2012 - 2017 Björn Ricks <bjoern.ricks@gmail.com>
#
# See LICENSE comming with the source of python-quilt for details.



class NewCommand(Command):

    name = "new"
    help = "Create a new patch with the specified file name, and insert it " \
           "as the topmost applied patch."

    patchname = Argument()

    def run(self, args):
        new = New(self.get_cwd(), self.get_pc_dir(), self.get_patches_dir())
        try:
            new.create(args.patchname)

# Path: quilt/cli/parser.py
# class Argument(object):
# 
#     """
#     A class to declare positional arguments at a class
# 
#     Usage:
#         class MyParser(Parser):
# 
#             arg1 = Argument(help="A first string argument")
#             arg2 = Argument(type=int)
#             arg3 = Argument(nargs=2)
#     """
# 
#     creation_counter = 0
# 
#     def __init__(self, *args, **kwargs):
#         """
#         Constructs an Argument instance
# 
#         args and kwargs are passed directly to
#         argparse.ArgumentParser.add_argument
#         """
#         self.args = args
#         self.kwargs = kwargs
#         self.creation_counter = Argument.creation_counter
#         Argument.creation_counter += 1
# 
#     def _get_kwargs(self):
#         if self.args:
#             return self.kwargs
# 
#         kwargs = {"dest": self.name}
#         kwargs.update(self.kwargs)
#         return kwargs
# 
#     def _get_args(self):
#         return self.args
# 
#     def add_to_parser(self, parser):
#         """
#         Adds the argument to an argparse.ArgumentParser instance
# 
#         @param parser An argparse.ArgumentParser instance
#         """
#         kwargs = self._get_kwargs()
#         args = self._get_args()
#         parser.add_argument(*args, **kwargs)
# 
#     def set_name(self, name):
#         """
#         Sets the name of this Argument.
#         Normally this method should not be called directly.
#         It is used by the ArgumentsCollectorMetaClass.
# 
#         @param name A string for a name
#         """
#         self.name = name
# 
# Path: quilt/new.py
# class New(Command):
# 
#     patch_created = Signal()
# 
#     """ Creates a new patch in the queue """
#     def __init__(self, cwd, quilt_pc, quilt_patches):
#         super(New, self).__init__(cwd)
#         self.quilt_pc = Directory(quilt_pc)
#         self.quilt_patches = Directory(quilt_patches)
#         self.db = Db(quilt_pc)
#         self.series = Series(quilt_patches)
# 
#     def create(self, patchname):
#         """ Adds a new patch with patchname to the queue
# 
#         The new patch will be added as the topmost applied patch.
#         """
#         patch = Patch(patchname)
#         if self.series.is_patch(patch):
#             raise PatchAlreadyExists(self.series, patchname)
# 
#         patch_dir = self.quilt_patches
#         patch_dir.create()
#         patchfile = patch_dir + File(patchname)
#         patchfile.touch()
# 
#         pc_dir = self.quilt_pc + patchname
#         if pc_dir.exists():
#             # be sure that the directory is clear
#             pc_dir.delete()
# 
#         # create empty .pc/<patchname> directory as quilt does too
#         pc_dir.create()
# 
#         top = self.db.top_patch()
#         # add new patch after the current topmost applied patch
#         self.series.add_patches([patch], top)
#         # "apply" patch
#         self.db.add_patch(patch)
# 
#         # create patches/series files
#         self.series.save()
#         # create .pc/.version and .pc/applied-patches files
#         self.db.save()
# 
#         self.patch_created(patch)


# Path: quilt/cli/new.py
from quilt.cli.meta import Command
from quilt.cli.parser import Argument
from quilt.error import PatchAlreadyExists
from quilt.new import New

# vim: fileencoding=utf-8 et sw=4 ts=4 tw=80:

# python-quilt - A Python implementation of the quilt patch system
#
# Copyright (C) 2012 - 2017 Björn Ricks <bjoern.ricks@gmail.com>
#
# See LICENSE comming with the source of python-quilt for details.



class NewCommand(Command):

    name = "new"
    help = "Create a new patch with the specified file name, and insert it " \
           "as the topmost applied patch."

    patchname = Argument()

    def run(self, args):
        new = New(self.get_cwd(), self.get_pc_dir(), self.get_patches_dir())
        try:
            new.create(args.patchname)

        except PatchAlreadyExists as e: