def extractPackage(request, package, filename, existOk):
    """
    Create a new package consisting of the current node and export
    'existOk' means the user has been informed of existance and ok'd it
    """
    filename = Path(filename)
    saveDir = filename.dirname()
    if saveDir and not saveDir.exists():
        client.alert(
            _(u'Cannot access directory named ') + unicode(saveDir) +
            _(u'. Please use ASCII names.'))
        return

    # Add the extension if its not already there
    if not filename.lower().endswith('.elp'):
        filename += '.elp'

    if Path(filename).exists() and existOk != 'true':
        msg = _(
            u'"%s" already exists.\nPlease try again with a different filename'
        ) % filename
        client.alert(_(u'EXTRACT FAILED!\n%s' % msg))
        return

    try:
        # Create a new package for the extracted nodes
        newPackage = package.extractNode()

        # trigger a rename of all of the internal nodes and links,
        # and to remove any old anchors from the dest package,
        # and remove any zombie links via isExtract:
        newNode = newPackage.root
        if newNode:
            newNode.RenamedNodePath(isExtract=True)

        # Save the new package
        newPackage.save(filename)
    except Exception, e:
        client.alert(_('EXTRACT FAILED!\n%s' % str(e)))
        raise
Exemple #2
0
def extractPackage(request, package, filename, existOk):

    """
    Create a new package consisting of the current node and export
    'existOk' means the user has been informed of existance and ok'd it
    """
    filename = Path(filename)
    saveDir = filename.dirname()
    if saveDir and not saveDir.exists():
        client.alert(_(u"Cannot access directory named ") + unicode(saveDir) + _(u". Please use ASCII names."))
        return

    # Add the extension if its not already there
    if not filename.lower().endswith(".elp"):
        filename += ".elp"

    if Path(filename).exists() and existOk != "true":
        msg = _(u'"%s" already exists.\nPlease try again with a different filename') % filename
        client.alert(_(u"EXTRACT FAILED!\n%s" % msg))
        return

    try:
        # Create a new package for the extracted nodes
        newPackage = package.extractNode()

        # trigger a rename of all of the internal nodes and links,
        # and to remove any old anchors from the dest package,
        # and remove any zombie links via isExtract:
        newNode = newPackage.root
        if newNode:
            newNode.RenamedNodePath(isExtract=True)

        # Save the new package
        newPackage.save(filename)
    except Exception, e:
        client.alert(_("EXTRACT FAILED!\n%s" % str(e)))
        raise