eric6/eric6_post_install.py

branch
setup.py
changeset 6951
ef3e87580dc9
parent 6950
62e39a353cd9
child 7192
a22eee00b052
equal deleted inserted replaced
6950:62e39a353cd9 6951:ef3e87580dc9
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 # Copyright (c) 2019 Detlev Offenbach <detlev@die-offenbachs.de> 4 # Copyright (c) 2019 Detlev Offenbach <detlev@die-offenbachs.de>
5 # 5 #
6
7 """
8 Module implemenzing the post install logic for 'pip install'.
9 """
6 10
7 from __future__ import unicode_literals 11 from __future__ import unicode_literals
8 12
9 import sys 13 import sys
10 import os 14 import os
12 import sysconfig 16 import sysconfig
13 17
14 ###################################################################### 18 ######################################################################
15 ## Post installation hooks for Windows below 19 ## Post installation hooks for Windows below
16 ###################################################################### 20 ######################################################################
21
17 22
18 def createWindowsLinks(): 23 def createWindowsLinks():
19 """ 24 """
20 Create Desktop and Start Menu links. 25 Create Desktop and Start Menu links.
21 """ 26 """
142 147
143 ###################################################################### 148 ######################################################################
144 ## Post installation hooks for Linux below 149 ## Post installation hooks for Linux below
145 ###################################################################### 150 ######################################################################
146 151
152
147 def copyLinuxMetaData(): 153 def copyLinuxMetaData():
148 """ 154 """
149 Function to copy the meta data files. 155 Function to copy the meta data files.
150 """ 156 """
151 # TODO: .desktop files need patching of the exec line 157 scriptsDir = sysconfig.get_path("scripts")
152 srcDir = os.path.join(os.path.dirname(sysconfig.get_path("scripts")), 158 srcDir = os.path.join(os.path.dirname(scriptsDir), "share")
153 "share")
154 dstDir = os.path.join(os.path.expanduser("~"), ".local", "share") 159 dstDir = os.path.join(os.path.expanduser("~"), ".local", "share")
155 for metaDir in ["applications", "icons", "appdata", "metainfo"]: 160
161 for metaDir in ["icons", "appdata", "metainfo"]:
156 copyMetaFilesTree(os.path.join(srcDir, metaDir), 162 copyMetaFilesTree(os.path.join(srcDir, metaDir),
157 os.path.join(dstDir, metaDir)) 163 os.path.join(dstDir, metaDir))
164
165 for desktop in ["eric6.desktop", "eric6_browser.desktop"]:
166 copyDesktopFile(
167 os.path.join(srcDir, "applications", desktop),
168 os.path.join(dstDir, "applications", desktop),
169 scriptsDir
170 )
158 171
159 172
160 def copyMetaFilesTree(src, dst): 173 def copyMetaFilesTree(src, dst):
161 """ 174 """
162 Function to copy the files of a directory tree. 175 Function to copy the files of a directory tree.
179 os.chmod(dstname, 0o644) 192 os.chmod(dstname, 0o644)
180 193
181 if os.path.isdir(srcname): 194 if os.path.isdir(srcname):
182 copyMetaFilesTree(srcname, dstname) 195 copyMetaFilesTree(srcname, dstname)
183 196
197
198 def copyDesktopFile(src, dst, scriptsdir):
199 """
200 Modify a desktop file and write it to its destination.
201
202 @param src source file name (string)
203 @param dst destination file name (string)
204 @param scriptsdir directory containing the scripts (string)
205 """
206 f = open(src, "r", encoding="utf-8")
207 text = f.read()
208 f.close()
209
210 text = text.replace("@BINDIR@", scriptsdir)
211
212 f = open(dst, "w", encoding="utf-8")
213 f.write(text)
214 f.close()
215 os.chmod(dst, 0o644)
216
184 ###################################################################### 217 ######################################################################
185 ## Main script below 218 ## Main script below
186 ###################################################################### 219 ######################################################################
187 220
221
188 def main(): 222 def main():
189 """ 223 """
190 Main script 224 Main script orchestrating the platform dependent post installation tasks.
191 """ 225 """
192 if sys.platform.startswith(("win", "cygwin")): 226 if sys.platform.startswith(("win", "cygwin")):
193 createWindowsLinks() 227 createWindowsLinks()
194 elif sys.platform.startswith("linux"): 228 elif sys.platform.startswith("linux"):
195 copyLinuxMetaData() 229 copyLinuxMetaData()

eric ide

mercurial