示例#1
0
 def test_edit_document_no_no(self, mock_launch):
     """Verify 'doorstop edit' can be called with a document (no, no)."""
     path = "TUT-456.yml"
     self.assertIs(None, main(['edit', 'tut', '-T', 'my_editor']))
     common.delete(path)
     mock_launch.assert_called_once_with(os.path.normpath(path),
                                         tool='my_editor')
示例#2
0
def _export_import(args, cwd, error, document, ext):
    """Edit a document by calling export followed by import.

    :param args: Namespace of CLI arguments
    :param cwd: current working directory
    :param error: function to call for CLI errors
    :param document: :class:`~doorstop.core.document.Document` to edit
    :param ext: extension for export format

    """
    # Export the document to file
    args.prefix = document.prefix
    path = "{}-{}{}".format(args.prefix, int(time.time()), ext)
    args.path = path
    get('export')(args, cwd, error, catch=False, auto=True,
                  _tree=document.tree)

    # Open the exported file
    editor.edit(path, tool=args.tool)

    # Import the file to the same document
    if utilities.ask("import from '{}'?".format(path)):
        args.attrs = {}
        args.map = {}
        get('import')(args, cwd, error, catch=False, _tree=document.tree)
        common.delete(path)
    else:
        utilities.show("import canceled")
        if utilities.ask("delete '{}'?".format(path)):
            common.delete(path)
        else:
            msg = "to manually import: doorstop import {0}".format(path)
            utilities.show(msg)
示例#3
0
 def delete(self, path):
     """Delete the object's file from the file system."""
     if self._exists:
         log.info("deleting {}...".format(self))
         common.delete(path)
         self._loaded = False  # force the object to reload
         self._exists = False  # but, prevent future access
     else:
         log.warning("already deleted: {}".format(self))
示例#4
0
 def delete(self, path=None):
     """Delete the document and its items."""
     prefix = Prefix(str(self.prefix))
     for item in self:
         item.delete()
     super().delete(self.config)
     common.delete(self.path)
     if settings.CACHE_DOCUMENTS and self.tree:
         self.tree._document_cache[prefix] = None  # pylint: disable=W0212
         log.trace("expunged document: {}".format(prefix))
示例#5
0
 def delete(self, path=None):
     """Delete the document and its items."""
     prefix = Prefix(str(self.prefix))
     for item in self:
         item.delete()
     super().delete(self.config)
     common.delete(self.path)
     if settings.CACHE_DOCUMENTS and self.tree:
         self.tree._document_cache[prefix] = None  # pylint: disable=W0212
         log.trace("expunged document: {}".format(prefix))
示例#6
0
def _export_import(args, cwd, error, document, ext):
    """Edit a document by calling export followed by import.

    :param args: Namespace of CLI arguments
    :param cwd: current working directory
    :param error: function to call for CLI errors
    :param document: :class:`~doorstop.core.document.Document` to edit
    :param ext: extension for export format

    """
    # Export the document to file
    args.prefix = document.prefix
    path = "{}-{}{}".format(args.prefix, int(time.time()), ext)
    args.path = path
    get('export')(args,
                  cwd,
                  error,
                  catch=False,
                  auto=True,
                  _tree=document.tree)

    # Open the exported file
    editor.edit(path, tool=args.tool)

    # Import the file to the same document
    if utilities.ask("import from '{}'?".format(path)):
        args.attrs = {}
        args.map = {}
        get('import')(args, cwd, error, catch=False, _tree=document.tree)
        common.delete(path)
    else:
        utilities.show("import canceled")
        if utilities.ask("delete '{}'?".format(path)):
            common.delete(path)
        else:
            msg = "to manually import: doorstop import {0}".format(path)
            utilities.show(msg)
示例#7
0
 def tearDown(self):
     common.delete(os.path.join(ROOT, 'tmp'))
     common.delete(os.path.join(REQS, 'REQ099.yml'))
示例#8
0
 def tearDown(self):
     """Clean up temporary files."""
     for filename in os.listdir(EMPTY):
         path = os.path.join(EMPTY, filename)
         common.delete(path)
示例#9
0
def move_file(src, dst):
    """Move a file from one path to another."""
    common.delete(dst)
    shutil.move(src, dst)
示例#10
0
 def index(self):
     """Delete the document's index if it exists."""
     log.info("deleting {} index...".format(self))
     common.delete(self.index)
示例#11
0
 def tearDown(self):
     """Clean up temporary files."""
     for filename in os.listdir(EMPTY):
         path = os.path.join(EMPTY, filename)
         common.delete(path)
示例#12
0
def move_file(src, dst):
    """Move a file from one path to another."""
    common.delete(dst)
    shutil.move(src, dst)
示例#13
0
 def index(self):
     """Delete the document's index if it exists."""
     log.info("deleting {} index...".format(self))
     common.delete(self.index)
示例#14
0
 def tearDown(self):
     common.delete(self.path)
示例#15
0
 def tearDown(self):
     common.delete(os.path.join(ROOT, "tmp"))
     common.delete(os.path.join(REQS, "REQ099.yml"))
示例#16
0
 def tearDown(self):
     common.delete(self.path)
示例#17
0
 def test_edit_document_no_no(self, mock_launch):
     """Verify 'doorstop edit' can be called with a document (no, no)."""
     path = "TUT-456.yml"
     self.assertIs(None, main(['edit', 'tut']))
     common.delete(path)
     mock_launch.assert_called_once_with(os.path.normpath(path), tool=None)
示例#18
0
 def tearDown(self):
     common.delete(os.path.join(ROOT, 'tmp'))
     common.delete(os.path.join(REQS, 'REQ099.yml'))