mozInstall 2.0.0__tar.gz → 2.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,11 @@
1
- Metadata-Version: 1.1
1
+ Metadata-Version: 2.1
2
2
  Name: mozInstall
3
- Version: 2.0.0
3
+ Version: 2.1.0
4
4
  Summary: package for installing and uninstalling Mozilla applications
5
5
  Home-page: https://wiki.mozilla.org/Auto-tools/Projects/Mozbase
6
6
  Author: Mozilla Automation and Tools team
7
7
  Author-email: tools@lists.mozilla.org
8
8
  License: MPL 2.0
9
- Description: see https://firefox-source-docs.mozilla.org/mozbase/index.html
10
9
  Keywords: mozilla
11
10
  Platform: UNKNOWN
12
11
  Classifier: Environment :: Console
@@ -17,3 +16,6 @@ Classifier: Operating System :: OS Independent
17
16
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
17
  Classifier: Programming Language :: Python :: 2.7
19
18
  Classifier: Programming Language :: Python :: 3
19
+
20
+ see https://firefox-source-docs.mozilla.org/mozbase/index.html
21
+
@@ -1,12 +1,11 @@
1
- Metadata-Version: 1.1
1
+ Metadata-Version: 2.1
2
2
  Name: mozInstall
3
- Version: 2.0.0
3
+ Version: 2.1.0
4
4
  Summary: package for installing and uninstalling Mozilla applications
5
5
  Home-page: https://wiki.mozilla.org/Auto-tools/Projects/Mozbase
6
6
  Author: Mozilla Automation and Tools team
7
7
  Author-email: tools@lists.mozilla.org
8
8
  License: MPL 2.0
9
- Description: see https://firefox-source-docs.mozilla.org/mozbase/index.html
10
9
  Keywords: mozilla
11
10
  Platform: UNKNOWN
12
11
  Classifier: Environment :: Console
@@ -17,3 +16,6 @@ Classifier: Operating System :: OS Independent
17
16
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
17
  Classifier: Programming Language :: Python :: 2.7
19
18
  Classifier: Programming Language :: Python :: 3
19
+
20
+ see https://firefox-source-docs.mozilla.org/mozbase/index.html
21
+
@@ -1,4 +1,4 @@
1
1
  mozinfo>=0.7
2
2
  mozfile>=1.0
3
3
  requests
4
- six>=1.10.0
4
+ six>=1.13.0
@@ -3,6 +3,4 @@
3
3
  # License, v. 2.0. If a copy of the MPL was not distributed with this file,
4
4
  # You can obtain one at http://mozilla.org/MPL/2.0/.
5
5
 
6
- from __future__ import absolute_import
7
-
8
- from .mozinstall import *
6
+ from .mozinstall import *
@@ -2,10 +2,8 @@
2
2
  # License, v. 2.0. If a copy of the MPL was not distributed with this file,
3
3
  # You can obtain one at http://mozilla.org/MPL/2.0/.
4
4
 
5
- from __future__ import absolute_import, print_function
6
-
7
- from optparse import OptionParser
8
5
  import os
6
+ import plistlib
9
7
  import shutil
10
8
  import subprocess
11
9
  import sys
@@ -13,23 +11,20 @@ import tarfile
13
11
  import tempfile
14
12
  import time
15
13
  import zipfile
16
-
17
- import requests
18
-
19
- from six import reraise
14
+ from optparse import OptionParser
20
15
 
21
16
  import mozfile
22
17
  import mozinfo
18
+ import requests
19
+ from six import PY3, reraise
23
20
 
24
21
  try:
25
22
  import pefile
23
+
26
24
  has_pefile = True
27
25
  except ImportError:
28
26
  has_pefile = False
29
27
 
30
- if mozinfo.isMac:
31
- from plistlib import readPlist
32
-
33
28
 
34
29
  TIMEOUT_UNINSTALL = 60
35
30
 
@@ -57,6 +52,13 @@ class UninstallError(Exception):
57
52
  """Thrown when uninstallation fails. Includes traceback if available."""
58
53
 
59
54
 
55
+ def _readPlist(path):
56
+ if PY3:
57
+ with open(path, "rb") as fp:
58
+ return plistlib.load(fp)
59
+ return plistlib.readPlist(path)
60
+
61
+
60
62
  def get_binary(path, app_name):
61
63
  """Find the binary in the specified path, and return its path. If binary is
62
64
  not found throw an InvalidBinary exception.
@@ -68,18 +70,19 @@ def get_binary(path, app_name):
68
70
 
69
71
  # On OS X we can get the real binary from the app bundle
70
72
  if mozinfo.isMac:
71
- plist = '%s/Contents/Info.plist' % path
73
+ plist = "%s/Contents/Info.plist" % path
72
74
  if not os.path.isfile(plist):
73
- raise InvalidBinary('%s/Contents/Info.plist not found' % path)
75
+ raise InvalidBinary("%s/Contents/Info.plist not found" % path)
74
76
 
75
- binary = os.path.join(path, 'Contents/MacOS/',
76
- readPlist(plist)['CFBundleExecutable'])
77
+ binary = os.path.join(
78
+ path, "Contents/MacOS/", _readPlist(plist)["CFBundleExecutable"]
79
+ )
77
80
 
78
81
  else:
79
82
  app_name = app_name.lower()
80
83
 
81
84
  if mozinfo.isWin:
82
- app_name = app_name + '.exe'
85
+ app_name = app_name + ".exe"
83
86
 
84
87
  for root, dirs, files in os.walk(path):
85
88
  for filename in files:
@@ -105,7 +108,7 @@ def install(src, dest):
105
108
  """
106
109
  if not is_installer(src):
107
110
  msg = "{} is not a valid installer file".format(src)
108
- if '://' in src:
111
+ if "://" in src:
109
112
  try:
110
113
  return _install_url(src, dest)
111
114
  except Exception:
@@ -125,10 +128,12 @@ def install(src, dest):
125
128
  trbk = None
126
129
  try:
127
130
  install_dir = None
128
- if src.lower().endswith('.dmg'):
131
+ if src.lower().endswith(".dmg"):
129
132
  install_dir = _install_dmg(src, dest)
130
- elif src.lower().endswith('.exe'):
133
+ elif src.lower().endswith(".exe"):
131
134
  install_dir = _install_exe(src, dest)
135
+ elif src.lower().endswith(".msix"):
136
+ install_dir = _install_msix(src)
132
137
  elif zipfile.is_zipfile(src) or tarfile.is_tarfile(src):
133
138
  install_dir = mozfile.extract(src, dest)[0]
134
139
 
@@ -180,21 +185,21 @@ def is_installer(src):
180
185
  if mozinfo.isLinux:
181
186
  return tarfile.is_tarfile(src)
182
187
  elif mozinfo.isMac:
183
- return src.lower().endswith('.dmg')
188
+ return src.lower().endswith(".dmg")
184
189
  elif mozinfo.isWin:
185
190
  if zipfile.is_zipfile(src):
186
191
  return True
187
192
 
188
- if os.access(src, os.X_OK) and src.lower().endswith('.exe'):
193
+ if os.access(src, os.X_OK) and src.lower().endswith(".exe"):
189
194
  if has_pefile:
190
195
  # try to determine if binary is actually a gecko installer
191
196
  pe_data = pefile.PE(src)
192
197
  data = {}
193
- for info in getattr(pe_data, 'FileInfo', []):
194
- if info.Key == 'StringFileInfo':
198
+ for info in getattr(pe_data, "FileInfo", []):
199
+ if info.Key == "StringFileInfo":
195
200
  for string in info.StringTable:
196
201
  data.update(string.entries)
197
- return 'BuildID' not in data
202
+ return "BuildID" not in data
198
203
  else:
199
204
  # pefile not available, just assume a proper binary was passed in
200
205
  return True
@@ -209,23 +214,34 @@ def uninstall(install_folder):
209
214
  :param install_folder: Path of the installation folder
210
215
 
211
216
  """
217
+ # Uninstallation for MSIX applications is totally different than
218
+ # any other installs...
219
+ if "WindowsApps" in install_folder:
220
+ # At the time of writing, the package installation directory is always
221
+ # the package full name, so this assumption is valid (for now....).
222
+ packageFullName = install_folder.split("WindowsApps\\")[1].split("\\")[0]
223
+ cmd = f"powershell.exe Remove-AppxPackage -Package {packageFullName}"
224
+ subprocess.check_call(cmd)
225
+ return
226
+
212
227
  install_folder = os.path.realpath(install_folder)
213
- assert os.path.isdir(install_folder), \
228
+ assert os.path.isdir(install_folder), (
214
229
  'installation folder "%s" exists.' % install_folder
230
+ )
215
231
 
216
232
  # On Windows we have to use the uninstaller. If it's not available fallback
217
233
  # to the directory removal code
218
234
  if mozinfo.isWin:
219
- uninstall_folder = '%s\\uninstall' % install_folder
220
- log_file = '%s\\uninstall.log' % uninstall_folder
235
+ uninstall_folder = "%s\\uninstall" % install_folder
236
+ log_file = "%s\\uninstall.log" % uninstall_folder
221
237
 
222
238
  if os.path.isfile(log_file):
223
239
  trbk = None
224
240
  try:
225
- cmdArgs = ['%s\\uninstall\helper.exe' % install_folder, '/S']
241
+ cmdArgs = ["%s\\uninstall\helper.exe" % install_folder, "/S"]
226
242
  result = subprocess.call(cmdArgs)
227
- if result is not 0:
228
- raise Exception('Execution of uninstaller failed.')
243
+ if result != 0:
244
+ raise Exception("Execution of uninstaller failed.")
229
245
 
230
246
  # The uninstaller spawns another process so the subprocess call
231
247
  # returns immediately. We have to wait until the uninstall
@@ -235,11 +251,13 @@ def uninstall(install_folder):
235
251
  time.sleep(1)
236
252
 
237
253
  if time.time() > end_time:
238
- raise Exception('Failure removing uninstall folder.')
254
+ raise Exception("Failure removing uninstall folder.")
239
255
 
240
256
  except Exception as ex:
241
257
  cls, exc, trbk = sys.exc_info()
242
- error = UninstallError('Failed to uninstall %s (%s)' % (install_folder, str(ex)))
258
+ error = UninstallError(
259
+ "Failed to uninstall %s (%s)" % (install_folder, str(ex))
260
+ )
243
261
  reraise(UninstallError, error, trbk)
244
262
 
245
263
  finally:
@@ -263,8 +281,8 @@ def _install_url(url, dest):
263
281
  r = requests.get(url, stream=True)
264
282
  name = tempfile.mkstemp()[1]
265
283
  try:
266
- with open(name, 'w+b') as fh:
267
- for chunk in r.iter_content(chunk_size=16*1024):
284
+ with open(name, "w+b") as fh:
285
+ for chunk in r.iter_content(chunk_size=16 * 1024):
268
286
  fh.write(chunk)
269
287
  result = install(name, dest)
270
288
  finally:
@@ -285,13 +303,19 @@ def _install_dmg(src, dest):
285
303
  # According to the Apple doc, the hdiutil output is stable and is based on the tab
286
304
  # separators
287
305
  # Therefor, $3 should give us the mounted path
288
- appDir = subprocess.check_output('hdiutil attach -nobrowse -noautoopen "%s"'
289
- '|grep /Volumes/'
290
- '|awk \'BEGIN{FS="\t"} {print $3}\'' % str(src),
291
- shell=True).strip().decode('ascii')
306
+ appDir = (
307
+ subprocess.check_output(
308
+ 'hdiutil attach -nobrowse -noautoopen "%s"'
309
+ "|grep /Volumes/"
310
+ "|awk 'BEGIN{FS=\"\t\"} {print $3}'" % str(src),
311
+ shell=True,
312
+ )
313
+ .strip()
314
+ .decode("ascii")
315
+ )
292
316
 
293
317
  for appFile in os.listdir(appDir):
294
- if appFile.endswith('.app'):
318
+ if appFile.endswith(".app"):
295
319
  appName = appFile
296
320
  break
297
321
 
@@ -307,8 +331,7 @@ def _install_dmg(src, dest):
307
331
 
308
332
  finally:
309
333
  if appDir:
310
- subprocess.check_call('hdiutil detach "%s" -quiet' % appDir,
311
- shell=True)
334
+ subprocess.check_call('hdiutil detach "%s" -quiet' % appDir, shell=True)
312
335
 
313
336
  return dest
314
337
 
@@ -325,10 +348,10 @@ def _install_exe(src, dest):
325
348
  # The installer doesn't automatically create a sub folder. Lets guess the
326
349
  # best name from the src file name
327
350
  filename = os.path.basename(src)
328
- dest = os.path.join(dest, filename.split('.')[0])
351
+ dest = os.path.join(dest, filename.split(".")[0])
329
352
 
330
353
  # possibly gets around UAC in vista (still need to run as administrator)
331
- os.environ['__compat_layer'] = 'RunAsInvoker'
354
+ os.environ["__compat_layer"] = "RunAsInvoker"
332
355
  cmd = '"%s" /extractdir=%s' % (src, os.path.realpath(dest))
333
356
 
334
357
  subprocess.check_call(cmd)
@@ -336,20 +359,66 @@ def _install_exe(src, dest):
336
359
  return dest
337
360
 
338
361
 
362
+ def _get_msix_install_location(pkg):
363
+ with zipfile.ZipFile(pkg) as zf:
364
+ # First, we pull the app identity out of the AppxManifest...
365
+ with zf.open("AppxManifest.xml") as am:
366
+ for line in am.readlines():
367
+ line = line.decode("utf-8")
368
+ if "<Identity" in line:
369
+ for part in line.split(" "):
370
+ if part.startswith("Name"):
371
+ pkgname = part.split("=")[-1].strip('"\r\n')
372
+
373
+ # ...then we can use it to find the install location
374
+ # with this cmdlet
375
+ cmd = (
376
+ f'powershell.exe "Get-AppxPackage" "-Name" "{pkgname}"'
377
+ )
378
+ for line in (
379
+ subprocess.check_output(cmd)
380
+ .decode("utf-8")
381
+ .splitlines()
382
+ ):
383
+ if line.startswith("InstallLocation"):
384
+ return "C:{}".format(line.split(":")[-1].strip())
385
+
386
+ raise Exception(f"Couldn't find install location of {pkg}")
387
+
388
+
389
+ def _install_msix(src):
390
+ """Install the MSIX package and return the installation path.
391
+
392
+ Arguments:
393
+ src -- MSIX package to install
394
+
395
+ """
396
+ # possibly gets around UAC in vista (still need to run as administrator)
397
+ cmd = f'powershell.exe "Add-AppxPackage" "-Path" "{src}"'
398
+ subprocess.check_call(cmd)
399
+
400
+ return _get_msix_install_location(src)
401
+
402
+
339
403
  def install_cli(argv=sys.argv[1:]):
340
404
  parser = OptionParser(usage="usage: %prog [options] installer")
341
- parser.add_option('-d', '--destination',
342
- dest='dest',
343
- default=os.getcwd(),
344
- help='Directory to install application into. '
345
- '[default: "%default"]')
346
- parser.add_option('--app', dest='app',
347
- default='firefox',
348
- help='Application being installed. [default: %default]')
405
+ parser.add_option(
406
+ "-d",
407
+ "--destination",
408
+ dest="dest",
409
+ default=os.getcwd(),
410
+ help="Directory to install application into. " '[default: "%default"]',
411
+ )
412
+ parser.add_option(
413
+ "--app",
414
+ dest="app",
415
+ default="firefox",
416
+ help="Application being installed. [default: %default]",
417
+ )
349
418
 
350
419
  (options, args) = parser.parse_args(argv)
351
420
  if not len(args) == 1:
352
- parser.error('An installer file has to be specified.')
421
+ parser.error("An installer file has to be specified.")
353
422
 
354
423
  src = args[0]
355
424
 
@@ -368,7 +437,7 @@ def uninstall_cli(argv=sys.argv[1:]):
368
437
 
369
438
  (options, args) = parser.parse_args(argv)
370
439
  if not len(args) == 1:
371
- parser.error('An installation path has to be specified.')
440
+ parser.error("An installation path has to be specified.")
372
441
 
373
442
  # Run it
374
443
  uninstall(argv[0])
@@ -0,0 +1,59 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this file,
3
+ # You can obtain one at http://mozilla.org/MPL/2.0/.
4
+
5
+ import os
6
+
7
+ from setuptools import setup
8
+
9
+ try:
10
+ here = os.path.dirname(os.path.abspath(__file__))
11
+ description = open(os.path.join(here, "README.md")).read()
12
+ except IOError:
13
+ description = None
14
+
15
+ PACKAGE_VERSION = "2.1.0"
16
+
17
+ deps = [
18
+ "mozinfo >= 0.7",
19
+ "mozfile >= 1.0",
20
+ "requests",
21
+ "six >= 1.13.0",
22
+ ]
23
+
24
+ setup(
25
+ name="mozInstall",
26
+ version=PACKAGE_VERSION,
27
+ description="package for installing and uninstalling Mozilla applications",
28
+ long_description="see https://firefox-source-docs.mozilla.org/mozbase/index.html",
29
+ # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
30
+ classifiers=[
31
+ "Environment :: Console",
32
+ "Intended Audience :: Developers",
33
+ "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
34
+ "Natural Language :: English",
35
+ "Operating System :: OS Independent",
36
+ "Topic :: Software Development :: Libraries :: Python Modules",
37
+ "Programming Language :: Python :: 2.7",
38
+ "Programming Language :: Python :: 3",
39
+ ],
40
+ keywords="mozilla",
41
+ author="Mozilla Automation and Tools team",
42
+ author_email="tools@lists.mozilla.org",
43
+ url="https://wiki.mozilla.org/Auto-tools/Projects/Mozbase",
44
+ license="MPL 2.0",
45
+ packages=["mozinstall"],
46
+ include_package_data=True,
47
+ zip_safe=False,
48
+ install_requires=deps,
49
+ # we have to generate two more executables for those systems that cannot run as Administrator
50
+ # and the filename containing "install" triggers the UAC
51
+ entry_points="""
52
+ # -*- Entry points: -*-
53
+ [console_scripts]
54
+ mozinstall = mozinstall:install_cli
55
+ mozuninstall = mozinstall:uninstall_cli
56
+ moz_add_to_system = mozinstall:install_cli
57
+ moz_remove_from_system = mozinstall:uninstall_cli
58
+ """,
59
+ )
mozInstall-2.0.0/setup.py DELETED
@@ -1,58 +0,0 @@
1
-
2
- # This Source Code Form is subject to the terms of the Mozilla Public
3
- # License, v. 2.0. If a copy of the MPL was not distributed with this file,
4
- # You can obtain one at http://mozilla.org/MPL/2.0/.
5
-
6
- from __future__ import absolute_import
7
-
8
- import os
9
- from setuptools import setup
10
-
11
- try:
12
- here = os.path.dirname(os.path.abspath(__file__))
13
- description = open(os.path.join(here, 'README.md')).read()
14
- except IOError:
15
- description = None
16
-
17
- PACKAGE_VERSION = '2.0.0'
18
-
19
- deps = ['mozinfo >= 0.7',
20
- 'mozfile >= 1.0',
21
- 'requests',
22
- 'six >= 1.10.0',
23
- ]
24
-
25
- setup(name='mozInstall',
26
- version=PACKAGE_VERSION,
27
- description="package for installing and uninstalling Mozilla applications",
28
- long_description="see https://firefox-source-docs.mozilla.org/mozbase/index.html",
29
- # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
30
- classifiers=['Environment :: Console',
31
- 'Intended Audience :: Developers',
32
- 'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
33
- 'Natural Language :: English',
34
- 'Operating System :: OS Independent',
35
- 'Topic :: Software Development :: Libraries :: Python Modules',
36
- 'Programming Language :: Python :: 2.7',
37
- 'Programming Language :: Python :: 3'],
38
- keywords='mozilla',
39
- author='Mozilla Automation and Tools team',
40
- author_email='tools@lists.mozilla.org',
41
- url='https://wiki.mozilla.org/Auto-tools/Projects/Mozbase',
42
- license='MPL 2.0',
43
- packages=['mozinstall'],
44
- include_package_data=True,
45
- zip_safe=False,
46
- install_requires=deps,
47
- tests_require=['mozprocess >= 0.15', ],
48
- # we have to generate two more executables for those systems that cannot run as Administrator
49
- # and the filename containing "install" triggers the UAC
50
- entry_points="""
51
- # -*- Entry points: -*-
52
- [console_scripts]
53
- mozinstall = mozinstall:install_cli
54
- mozuninstall = mozinstall:uninstall_cli
55
- moz_add_to_system = mozinstall:install_cli
56
- moz_remove_from_system = mozinstall:uninstall_cli
57
- """,
58
- )
File without changes