core: getRepositoryData now get the module in argument
This commit is contained in:
parent
2900e815c4
commit
c2314640ba
2 changed files with 7 additions and 6 deletions
|
|
@ -17,6 +17,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import sat
|
||||
from sat.core.i18n import _, D_, languageSwitch
|
||||
from twisted.application import service
|
||||
from twisted.internet import defer
|
||||
|
|
@ -72,7 +73,7 @@ class SAT(service.Service):
|
|||
try:
|
||||
return self._version_cache
|
||||
except AttributeError:
|
||||
self._version_cache = u"{} ({})".format(version, utils.getRepositoryData())
|
||||
self._version_cache = u"{} ({})".format(version, utils.getRepositoryData(sat))
|
||||
return self._version_cache
|
||||
else:
|
||||
return version
|
||||
|
|
|
|||
|
|
@ -36,9 +36,10 @@ def clean_ustr(ustr):
|
|||
yield char
|
||||
return ''.join(valid_chars(ustr))
|
||||
|
||||
def getRepositoryData(as_string=True):
|
||||
def getRepositoryData(module, as_string=True):
|
||||
"""Retrieve info on current mecurial repository
|
||||
|
||||
@param module: module to look for (e.g. sat, libervia)
|
||||
@param as_string(bool): if True return a string, else return a dictionary
|
||||
@return (unicode, dictionary): retrieved info in a nice string,
|
||||
or a dictionary with retrieved data (key is not present if data is not found),
|
||||
|
|
@ -50,13 +51,12 @@ def getRepositoryData(as_string=True):
|
|||
"""
|
||||
from distutils.spawn import find_executable
|
||||
import subprocess
|
||||
import sat
|
||||
KEYS=("node", "branch", "date", "tag")
|
||||
sat_root = os.path.dirname(sat.__file__)
|
||||
repos_root = os.path.dirname(module.__file__)
|
||||
hg_path = find_executable('hg')
|
||||
|
||||
if hg_path is not None:
|
||||
os.chdir(sat_root)
|
||||
os.chdir(repos_root)
|
||||
try:
|
||||
hg_data_raw = subprocess.check_output(["hg","parents","--template","{node}\n{branch}\n{date|isodate}\n{latesttag}"])
|
||||
except subprocess.CalledProcessError:
|
||||
|
|
@ -70,7 +70,7 @@ def getRepositoryData(as_string=True):
|
|||
|
||||
if not hg_data:
|
||||
log.debug(u"Mercurial not available or working, trying to get data from dirstate")
|
||||
os.chdir(os.path.relpath('..', sat_root))
|
||||
os.chdir(os.path.relpath('..', repos_root))
|
||||
try:
|
||||
with open('.hg/dirstate') as hg_dirstate:
|
||||
hg_data['node'] = hg_dirstate.read(20).encode('hex')
|
||||
|
|
|
|||
Loading…
Reference in a new issue