Example #1
0
def _create_spouse_link(lnk, tgt, mklnk, absLink):
    lnk_suffix = getLinkSuffix(mklnk)
    lnk += lnk_suffix

    if not absLink:
        tgt = os.path.relpath(tgt, os.path.dirname(lnk))

    mklnk(tgt, lnk)
Example #2
0
    def __init__(self, treeRoot, linkMaker=makelink_url, absLinks=False):
        self.treeRoot = treeRoot
        self.mklnk = linkMaker
        self.absLinks = absLinks

        if self.mklnk is makelink_url:
            absLinks = True
        self.lnk_suffix = getLinkSuffix(self.mklnk)
Example #3
0
def makelink_withbck(newTgt, oldLnk, mklnk_fn, newLnkSuffix=None, dryrun=False):
    if newLnkSuffix is None:
        newLnkSuffix = getLinkSuffix(mklnk_fn)
    
    root, oldLink_bn = os.path.split(oldLnk)
    
    oldLink_bck = os.path.join(root, BCKf+oldLink_bn)
    
    oldLink_bn_extless = stripKnownSuffixes(oldLink_bn, SUFFIXES)
    
    # The new link is created as a temporary first
    newLink_tmp = os.path.join(root, TMPf+oldLink_bn_extless+newLnkSuffix)
    
    # and this is what the temp link will be moved to eventually
    newLink = os.path.join(root, oldLink_bn_extless+newLnkSuffix)
    
    if dryrun:     
        print("mklnk(%s,\n" \
              "      %s)" % (newTgt, newLink_tmp))
        if os.path.exists(oldLnk):
            print("rename(%s,\n" \
                  "       %s)" % (oldLnk, oldLink_bck))
        print("rename(%s,\n" \
              "       %s)" % (newLink_tmp, newLink))
    else:
        # We do try/excepts here rather than os.path.exists() this
        # is because linux symlinks that point to non-existent targets
        # return os.path.exists() -> False.
        
        # Try to create the new link as a temporary first. If this fails
        # then the old link will be preserved as is
        try:
            os.remove(newLink_tmp)
        except:
            pass
            
        mklnk_fn(newTgt, newLink_tmp)
        
        # Backup the current link
        try:
            os.remove(oldLink_bck)
        except:
            pass
            
        try:
            os.rename(oldLnk, oldLink_bck)
        except:
            pass
        
        # Now rename the tmp link to be our new link
        os.rename(newLink_tmp, newLink)
            
        #os.remove(bckLnk)
        
        print("%s -> %s" % (newLink, newTgt))
Example #4
0
 def __init__(self, dryrun, rootPath, oldRootNode, link_type, absLinks):
     self.dryrun = dryrun
     self.rootPath = os.path.abspath(rootPath)
     self.oldRootNode = oldRootNode
     self.mklnk = getLinkMaker(link_type)
     self.newLnkSuffix = getLinkSuffix(self.mklnk)
     
     self.absLinks = absLinks
     if (self.mklnk is not os.symlink) and (not self.absLinks):
         print("Forcing absolute links")
         self.absLinks = True
Example #5
0
def create_marriage_link(tgt, lnk):
    if ml_link_is_url:
        mklnk = makelink_url
    else:
        tgt = os.path.relpath(tgt, os.path.dirname(lnk))
        mklnk = os.symlink

    suffix = getLinkSuffix(mklnk)

    lnk += suffix

    mklnk(tgt, lnk)