##// END OF EJS Templates
templater: make open_template() read from resources if in frozen binary...
Martin von Zweigbergk -
r45871:3b27ed8e default
parent child Browse files
Show More
@@ -1074,7 +1074,12 b' def templatedir():'
1074
1074
1075
1075
1076 def open_template(name):
1076 def open_template(name):
1077 '''returns a file-like object for the given template, and its full path'''
1077 '''returns a file-like object for the given template, and its full path
1078
1079 If the name is a relative path and we're in a frozen binary, the template
1080 will be read from the mercurial.templates package instead. The returned path
1081 will then be the relative path.
1082 '''
1078 templatepath = templatedir()
1083 templatepath = templatedir()
1079 if templatepath is not None or os.path.isabs(name):
1084 if templatepath is not None or os.path.isabs(name):
1080 f = os.path.join(templatepath, name)
1085 f = os.path.join(templatepath, name)
@@ -1083,5 +1088,12 b' def open_template(name):'
1083 except EnvironmentError:
1088 except EnvironmentError:
1084 return None, None
1089 return None, None
1085 else:
1090 else:
1086 # TODO: read from resources here
1091 name_parts = pycompat.sysstr(name).split('/')
1087 return None, None
1092 package_name = '.'.join(['mercurial', 'templates'] + name_parts[:-1])
1093 try:
1094 return (
1095 name,
1096 resourceutil.open_resource(package_name, name_parts[-1]),
1097 )
1098 except (ModuleNotFoundError, FileNotFoundError):
1099 return None, None
General Comments 0
You need to be logged in to leave comments. Login now