[docs]defexpand(self,path):"""Return the user's home directory as a ``pathlib.Path`` object."""returnPath.joinpath(self.target_path,path)
[docs]classSymbolicLink(object):"""This classs represents a file system symbolic link. The class also freezes created symbol links. """
[docs]def__init__(self,source:Path,path_translator:PathTranslator):"""Create. :param source: the :class:`.Path` that points to the symbolic link on the local file system. """self.source=sourceself.path_translator=path_translatorself.use_count=0
@propertydeftarget(self):"""The target (where it point to). """returnself.source.resolve()@propertydefsource_relative(self):"""The relative location source (to the user's home). """ifnothasattr(self,'_src'):self._src=self.path_translator.relative_to(self.source)returnself._src@propertydeftarget_relative(self):"""The relative location (where it points to) relative to the user's home. """ifnothasattr(self,'_dst'):self._dst=self.path_translator.relative_to(self.target)returnself._dst
[docs]defincrement_use_count(self):"""Indicate this symblic link is used (linked) to another target. """self.use_count+=1
[docs]deffreeze(self):"""Create and return an object graph as a dict of the link. """return{'source':str(self.source_relative),'target':str(self.target_relative)}
def_str_to_path(self,pathstr:str):returnPath(pathstr)def_target_relative(self,path):returnself.dist.path_translator.expand(path)@property@persisted('_rel')defrelative(self):"""Return the relative path of the file. """returnPath(self._str_to_path(self.finfo['rel']))@property@persisted('_path')defpath(self):"""Return the absolute path of the file. """returnself._target_relative(self.relative)@property@persisted('_mode')defmode(self):"""Return the numeric mode of the file """returnself.finfo['mode']@property@persisted('_modestr')defmodestr(self):"""Return a human readable string of the mode of the file. """returnself.finfo['modestr']@property@persisted('_modify_time')defmodify_time(self):"""Return the numeric modify time of the file """returnself.finfo['modify_time']def__str__(self):returnf'{self.relative} -> {self.path}: {self.mode} ({self.modestr})'def__repr__(self):returnself.__str__()
[docs]classLinkEntry(FileEntry):"""Represents a symbolic link in the frozen version of the distribution zip. """
[docs]classRemoteSpec(object):"""This class represents a remote for a git repo. """
[docs]def__init__(self,remote:Remote,is_master=None):"""Initialize. :param remote: a remote object from the git repo :param is_master: whether or not the remote is the primary (upstream) remote """self.remote=remotewithremote.config_readerascr:self.url=cr.get('url')self.is_master=is_master
@propertydefname(self):"""Return the remote's name. """returnself.remote.name
[docs]defrename(self,name,url=None):"""Rename the remote in the git repository itself, along with the class instance. """remote=self.remoteremote.rename(name)withremote.config_writerascw:ifurlisnotNone:cw.set('url',url)self.repo.git.config('branch.master.pushremote',name)
[docs]deffreeze(self):"""Freeze/create an object graph representation of the remote as a dict. """return{'name':self.name,'url':self.url,'is_master':self.is_master}