mozInstall 2.1.0__tar.gz → 2.2.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,21 +1,33 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: mozInstall
3
- Version: 2.1.0
3
+ Version: 2.2.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
9
  Keywords: mozilla
10
- Platform: UNKNOWN
11
10
  Classifier: Environment :: Console
12
11
  Classifier: Intended Audience :: Developers
13
12
  Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
14
13
  Classifier: Natural Language :: English
15
14
  Classifier: Operating System :: OS Independent
16
15
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
- Classifier: Programming Language :: Python :: 2.7
18
- Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Requires-Python: >=3.9
19
+ Requires-Dist: mozinfo>=0.7
20
+ Requires-Dist: mozfile>=1.0
21
+ Requires-Dist: requests
22
+ Dynamic: author
23
+ Dynamic: author-email
24
+ Dynamic: classifier
25
+ Dynamic: description
26
+ Dynamic: home-page
27
+ Dynamic: keywords
28
+ Dynamic: license
29
+ Dynamic: requires-dist
30
+ Dynamic: requires-python
31
+ Dynamic: summary
19
32
 
20
33
  see https://firefox-source-docs.mozilla.org/mozbase/index.html
21
-
@@ -1,21 +1,33 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: mozInstall
3
- Version: 2.1.0
3
+ Version: 2.2.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
9
  Keywords: mozilla
10
- Platform: UNKNOWN
11
10
  Classifier: Environment :: Console
12
11
  Classifier: Intended Audience :: Developers
13
12
  Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
14
13
  Classifier: Natural Language :: English
15
14
  Classifier: Operating System :: OS Independent
16
15
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
- Classifier: Programming Language :: Python :: 2.7
18
- Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Requires-Python: >=3.9
19
+ Requires-Dist: mozinfo>=0.7
20
+ Requires-Dist: mozfile>=1.0
21
+ Requires-Dist: requests
22
+ Dynamic: author
23
+ Dynamic: author-email
24
+ Dynamic: classifier
25
+ Dynamic: description
26
+ Dynamic: home-page
27
+ Dynamic: keywords
28
+ Dynamic: license
29
+ Dynamic: requires-dist
30
+ Dynamic: requires-python
31
+ Dynamic: summary
19
32
 
20
33
  see https://firefox-source-docs.mozilla.org/mozbase/index.html
21
-
@@ -8,4 +8,8 @@ mozInstall.egg-info/not-zip-safe
8
8
  mozInstall.egg-info/requires.txt
9
9
  mozInstall.egg-info/top_level.txt
10
10
  mozinstall/__init__.py
11
- mozinstall/mozinstall.py
11
+ mozinstall/mozinstall.py
12
+ tests/test_binary.py
13
+ tests/test_install.py
14
+ tests/test_is_installer.py
15
+ tests/test_uninstall.py
@@ -0,0 +1,5 @@
1
+ [console_scripts]
2
+ moz_add_to_system = mozinstall:install_cli
3
+ moz_remove_from_system = mozinstall:uninstall_cli
4
+ mozinstall = mozinstall:install_cli
5
+ mozuninstall = mozinstall:uninstall_cli
@@ -1,4 +1,3 @@
1
1
  mozinfo>=0.7
2
2
  mozfile>=1.0
3
3
  requests
4
- six>=1.13.0
@@ -16,7 +16,6 @@ from optparse import OptionParser
16
16
  import mozfile
17
17
  import mozinfo
18
18
  import requests
19
- from six import PY3, reraise
20
19
 
21
20
  try:
22
21
  import pefile
@@ -38,14 +37,7 @@ class InvalidBinary(Exception):
38
37
 
39
38
 
40
39
  class InvalidSource(Exception):
41
- """Thrown when the specified source is not a recognized file type.
42
-
43
- Supported types:
44
- Linux: tar.gz, tar.bz2
45
- Mac: dmg
46
- Windows: zip, exe
47
-
48
- """
40
+ """Thrown when the specified source is not a recognized file type."""
49
41
 
50
42
 
51
43
  class UninstallError(Exception):
@@ -53,10 +45,8 @@ class UninstallError(Exception):
53
45
 
54
46
 
55
47
  def _readPlist(path):
56
- if PY3:
57
- with open(path, "rb") as fp:
58
- return plistlib.load(fp)
59
- return plistlib.readPlist(path)
48
+ with open(path, "rb") as fp:
49
+ return plistlib.load(fp)
60
50
 
61
51
 
62
52
  def get_binary(path, app_name):
@@ -98,23 +88,33 @@ def get_binary(path, app_name):
98
88
  return binary
99
89
 
100
90
 
101
- def install(src, dest):
102
- """Install a zip, exe, tar.gz, tar.bz2 or dmg file, and return the path of
91
+ def install(src, dest, verify=True, dmg_tool=None, hfs_tool=None):
92
+ """Install a zip, exe, tar.gz, tar.bz2, tar.xz or dmg file, and return the path of
103
93
  the installation folder.
104
94
 
105
95
  :param src: Path to the install file
106
96
  :param dest: Path to install to (to ensure we do not overwrite any existent
107
97
  files the folder should not exist yet)
98
+ :param verify: Whether to verify the checksum of a dmg file when mounting it.
99
+ Only affects dmg files on macOS; other formats verify
100
+ integrity as part of extraction.
101
+ :param dmg_tool: Path to the libdmg-hfsplus `dmg` tool. Together with
102
+ `hfs_tool`, lets a dmg file be extracted without mounting
103
+ it. Defaults to the DMG_TOOL build config or environment variable,
104
+ then to `dmg/dmg` in MOZ_FETCHES_DIR.
105
+ :param hfs_tool: Path to the libdmg-hfsplus `hfsplus` tool. Defaults to the
106
+ HFS_TOOL build config or environment variable, then to `dmg/hfsplus` in
107
+ MOZ_FETCHES_DIR.
108
108
  """
109
109
  if not is_installer(src):
110
- msg = "{} is not a valid installer file".format(src)
110
+ msg = f"{src} is not a valid installer file"
111
111
  if "://" in src:
112
112
  try:
113
- return _install_url(src, dest)
113
+ return _install_url(src, dest, verify=verify)
114
114
  except Exception:
115
115
  exc, val, tb = sys.exc_info()
116
- error = InvalidSource("{} ({})".format(msg, val))
117
- reraise(InvalidSource, error, tb)
116
+ error = InvalidSource(f"{msg} ({val})")
117
+ raise error.with_traceback(tb)
118
118
  raise InvalidSource(msg)
119
119
 
120
120
  src = os.path.realpath(src)
@@ -128,14 +128,19 @@ def install(src, dest):
128
128
  trbk = None
129
129
  try:
130
130
  install_dir = None
131
- if src.lower().endswith(".dmg"):
132
- install_dir = _install_dmg(src, dest)
131
+ if src.lower().endswith(".msix"):
132
+ # MSIX packages _are_ ZIP files, so we need to look for them first.
133
+ install_dir = _install_msix(src)
134
+ elif src.lower().endswith(".dmg"):
135
+ install_dir = _install_dmg(
136
+ src, dest, verify=verify, dmg_tool=dmg_tool, hfs_tool=hfs_tool
137
+ )
133
138
  elif src.lower().endswith(".exe"):
134
139
  install_dir = _install_exe(src, dest)
135
- elif src.lower().endswith(".msix"):
136
- install_dir = _install_msix(src)
137
140
  elif zipfile.is_zipfile(src) or tarfile.is_tarfile(src):
138
141
  install_dir = mozfile.extract(src, dest)[0]
142
+ else:
143
+ raise InvalidSource(f"{src} is not a valid installer file")
139
144
 
140
145
  return install_dir
141
146
 
@@ -154,9 +159,9 @@ def install(src, dest):
154
159
  pass
155
160
  if issubclass(cls, Exception):
156
161
  error = InstallError('Failed to install "%s (%s)"' % (src, str(exc)))
157
- reraise(InstallError, error, trbk)
162
+ raise error.with_traceback(trbk)
158
163
  # any other kind of exception like KeyboardInterrupt is just re-raised.
159
- reraise(cls, exc, trbk)
164
+ raise exc.with_traceback(trbk)
160
165
 
161
166
  finally:
162
167
  # trbk won't get GC'ed due to circular reference
@@ -168,9 +173,9 @@ def is_installer(src):
168
173
  """Tests if the given file is a valid installer package.
169
174
 
170
175
  Supported types:
171
- Linux: tar.gz, tar.bz2
172
- Mac: dmg
173
- Windows: zip, exe
176
+ All: zip, tar.gz, tar.bz2, tar.xz
177
+ Linux, Mac: dmg
178
+ Windows: exe, msix
174
179
 
175
180
  On Windows pefile will be used to determine if the executable is the
176
181
  right type, if it is installed on the system.
@@ -182,14 +187,16 @@ def is_installer(src):
182
187
  if not os.path.isfile(src):
183
188
  return False
184
189
 
185
- if mozinfo.isLinux:
186
- return tarfile.is_tarfile(src)
187
- elif mozinfo.isMac:
190
+ if mozinfo.isWin and src.lower().endswith(".msix"):
191
+ # MSIX packages _are_ ZIP files, so look for them first.
192
+ return True
193
+ if zipfile.is_zipfile(src):
194
+ return True
195
+ if tarfile.is_tarfile(src):
196
+ return True
197
+ if mozinfo.isMac or mozinfo.isLinux:
188
198
  return src.lower().endswith(".dmg")
189
- elif mozinfo.isWin:
190
- if zipfile.is_zipfile(src):
191
- return True
192
-
199
+ if mozinfo.isWin:
193
200
  if os.access(src, os.X_OK) and src.lower().endswith(".exe"):
194
201
  if has_pefile:
195
202
  # try to determine if binary is actually a gecko installer
@@ -204,7 +211,7 @@ def is_installer(src):
204
211
  # pefile not available, just assume a proper binary was passed in
205
212
  return True
206
213
 
207
- return False
214
+ return False
208
215
 
209
216
 
210
217
  def uninstall(install_folder):
@@ -238,7 +245,7 @@ def uninstall(install_folder):
238
245
  if os.path.isfile(log_file):
239
246
  trbk = None
240
247
  try:
241
- cmdArgs = ["%s\\uninstall\helper.exe" % install_folder, "/S"]
248
+ cmdArgs = ["%s\\uninstall\\helper.exe" % install_folder, "/S"]
242
249
  result = subprocess.call(cmdArgs)
243
250
  if result != 0:
244
251
  raise Exception("Execution of uninstaller failed.")
@@ -258,7 +265,7 @@ def uninstall(install_folder):
258
265
  error = UninstallError(
259
266
  "Failed to uninstall %s (%s)" % (install_folder, str(ex))
260
267
  )
261
- reraise(UninstallError, error, trbk)
268
+ raise error.with_traceback(trbk)
262
269
 
263
270
  finally:
264
271
  # trbk won't get GC'ed due to circular reference
@@ -270,13 +277,16 @@ def uninstall(install_folder):
270
277
  mozfile.remove(install_folder)
271
278
 
272
279
 
273
- def _install_url(url, dest):
280
+ def _install_url(url, dest, verify=True):
274
281
  """Saves a url to a temporary file, and passes that through to the
275
282
  install function.
276
283
 
277
284
  :param url: Url to the install file
278
285
  :param dest: Path to install to (to ensure we do not overwrite any existent
279
286
  files the folder should not exist yet)
287
+ :param verify: Whether to verify the checksum of a dmg file when attaching it.
288
+ Only affects dmg files on macOS; other formats verify
289
+ integrity as part of extraction.
280
290
  """
281
291
  r = requests.get(url, stream=True)
282
292
  name = tempfile.mkstemp()[1]
@@ -284,56 +294,167 @@ def _install_url(url, dest):
284
294
  with open(name, "w+b") as fh:
285
295
  for chunk in r.iter_content(chunk_size=16 * 1024):
286
296
  fh.write(chunk)
287
- result = install(name, dest)
297
+ result = install(name, dest, verify=verify)
288
298
  finally:
289
299
  mozfile.remove(name)
290
300
  return result
291
301
 
292
302
 
293
- def _install_dmg(src, dest):
303
+ def _find_dmg_tools(dmg_tool=None, hfs_tool=None):
304
+ substs = {}
305
+ try:
306
+ import buildconfig
307
+
308
+ substs = buildconfig.substs
309
+ except ImportError:
310
+ pass
311
+ fetches_dir = os.environ.get("MOZ_FETCHES_DIR")
312
+
313
+ def find(tool, var, name):
314
+ tool = tool or substs.get(var) or os.environ.get(var)
315
+ if not tool and fetches_dir:
316
+ path = os.path.join(fetches_dir, "dmg", name)
317
+ if os.path.isfile(path):
318
+ tool = path
319
+ return tool
320
+
321
+ return find(dmg_tool, "DMG_TOOL", "dmg"), find(hfs_tool, "HFS_TOOL", "hfsplus")
322
+
323
+
324
+ def _install_dmg(src, dest_app, verify=True, dmg_tool=None, hfs_tool=None):
294
325
  """Extract a dmg file into the destination folder and return the
295
326
  application folder.
296
327
 
297
328
  src -- DMG image which has to be extracted
298
329
  dest -- the path to extract to
330
+ verify -- whether to verify the checksum of the image when mounting it
331
+ dmg_tool, hfs_tool -- libdmg-hfsplus tools to extract the image without
332
+ mounting it
299
333
 
300
334
  """
301
- appDir = None
335
+ dmg_tool, hfs_tool = _find_dmg_tools(dmg_tool, hfs_tool)
336
+ if dmg_tool and hfs_tool:
337
+ return _install_dmg_extract(src, dest_app, dmg_tool, hfs_tool)
338
+ if mozinfo.isLinux:
339
+ raise InstallError(
340
+ "DMG_TOOL and HFS_TOOL are required to install a dmg on Linux"
341
+ )
342
+
343
+ def _detach_with_retry(volume, retries=4, delay=0.25):
344
+ for i in range(retries):
345
+ try:
346
+ subprocess.check_call(f'hdiutil detach "{volume}" -quiet', shell=True)
347
+ return
348
+ except subprocess.CalledProcessError as e:
349
+ # 16 == EBUSY
350
+ if e.returncode != 16 or i == retries - 1:
351
+ raise
352
+ time.sleep(delay)
353
+
354
+ # Final fallback (CI-safe)
355
+ subprocess.check_call(f'hdiutil detach "{volume}" -force -quiet', shell=True)
356
+
357
+ app_dir = None
302
358
  try:
303
- # According to the Apple doc, the hdiutil output is stable and is based on the tab
304
- # separators
305
- # Therefor, $3 should give us the mounted path
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,
359
+ macos_major = int(str(mozinfo.os_version).split(".")[0])
360
+ if macos_major >= 27:
361
+ # Use diskutil instead of hdiutil on macOS 27+. On macOS 27,
362
+ # `hdiutil attach` is deprecated and prints deprecation warnings
363
+ # on stderr. Use thew newer `diskutil` command instead.
364
+ output = subprocess.check_output(
365
+ [
366
+ "diskutil",
367
+ "image",
368
+ "attach",
369
+ "--plist",
370
+ "--readOnly",
371
+ "--nobrowse",
372
+ src,
373
+ ],
374
+ stderr=subprocess.STDOUT,
375
+ )
376
+ entities = plistlib.loads(output)["system-entities"]
377
+ app_dir = next(
378
+ (e["mount-point"] for e in entities if "mount-point" in e), None
379
+ )
380
+ if not app_dir:
381
+ raise InstallError(f"No mounted volume found for {src}")
382
+ else:
383
+ # `hdiutil attach` is now deprecated (macOS 27+). Limit its use
384
+ # to older macOS versions. According to the Apple docs, the hdiutil
385
+ # output is stable and is based on the tab separators. Therefore,
386
+ # $3 should give us the mounted path.
387
+ verify_flag = "" if verify else " -noverify"
388
+ app_dir = (
389
+ subprocess
390
+ .check_output(
391
+ f'hdiutil attach -noautoopen -nobrowse -readonly{verify_flag} "{src}"'
392
+ "| grep /Volumes/ | awk 'BEGIN{FS=\"\t\"} {print $3}'",
393
+ shell=True,
394
+ stderr=subprocess.STDOUT,
395
+ )
396
+ .strip()
397
+ .decode("utf-8")
312
398
  )
313
- .strip()
314
- .decode("ascii")
315
- )
316
399
 
317
- for appFile in os.listdir(appDir):
318
- if appFile.endswith(".app"):
319
- appName = appFile
400
+ app_name = None
401
+ for entry in os.listdir(app_dir):
402
+ if entry.endswith(".app"):
403
+ app_name = entry
320
404
  break
321
405
 
322
- mounted_path = os.path.join(appDir, appName)
406
+ if not app_name:
407
+ raise InstallError(f"No .app bundle found in {src}")
323
408
 
324
- dest = os.path.join(dest, appName)
409
+ src_app = os.path.join(app_dir, app_name)
410
+ dest_app = os.path.join(dest_app, app_name)
325
411
 
326
412
  # copytree() would fail if dest already exists.
327
- if os.path.exists(dest):
328
- raise InstallError('App bundle "%s" already exists.' % dest)
413
+ if os.path.exists(dest_app):
414
+ raise InstallError(f"App bundle already exists: {dest_app}")
329
415
 
330
- shutil.copytree(mounted_path, dest, False)
416
+ shutil.copytree(src_app, dest_app, False)
331
417
 
332
418
  finally:
333
- if appDir:
334
- subprocess.check_call('hdiutil detach "%s" -quiet' % appDir, shell=True)
419
+ if app_dir:
420
+ try:
421
+ _detach_with_retry(app_dir)
422
+ except Exception as e:
423
+ # Log, but do not override the original exception
424
+ print(f"Warning: failed to detach {app_dir}: {e}")
335
425
 
336
- return dest
426
+ return dest_app
427
+
428
+
429
+ def _install_dmg_extract(src, dest, dmg_tool, hfs_tool):
430
+ """Extract the .app bundle of a dmg file into dest without mounting the
431
+ image, and return the path of the bundle."""
432
+ tmpdir = tempfile.mkdtemp(dir=dest)
433
+ try:
434
+ hfs_file = os.path.join(tmpdir, "image.hfs")
435
+ contents = os.path.join(tmpdir, "contents")
436
+ os.mkdir(contents)
437
+ subprocess.check_call(
438
+ [dmg_tool, "extract", src, hfs_file], stdout=subprocess.DEVNULL
439
+ )
440
+ subprocess.check_call(
441
+ [hfs_tool, hfs_file, "extractall", "/", contents],
442
+ stdout=subprocess.DEVNULL,
443
+ )
444
+
445
+ app_name = next((e for e in os.listdir(contents) if e.endswith(".app")), None)
446
+ if not app_name:
447
+ raise InstallError(f"No .app bundle found in {src}")
448
+
449
+ dest_app = os.path.join(dest, app_name)
450
+ if os.path.exists(dest_app):
451
+ raise InstallError(f"App bundle already exists: {dest_app}")
452
+
453
+ os.rename(os.path.join(contents, app_name), dest_app)
454
+ finally:
455
+ shutil.rmtree(tmpdir, ignore_errors=True)
456
+
457
+ return dest_app
337
458
 
338
459
 
339
460
  def _install_exe(src, dest):
@@ -375,13 +496,29 @@ def _get_msix_install_location(pkg):
375
496
  cmd = (
376
497
  f'powershell.exe "Get-AppxPackage" "-Name" "{pkgname}"'
377
498
  )
499
+ # Powershell "helpfully" wraps long lines and there's
500
+ # no tidy way to tell it not to, so we'll have to
501
+ # reconstruct the value. Output could look like this:
502
+ # InstallLocation : C:\Program
503
+ # Files\WindowsApps\...
504
+ # Don't strip trailing spaces. The space between
505
+ # "Program" and "Files" is at the end of the first
506
+ # line. (Not in this comment, due to linting.)
507
+ location = None
378
508
  for line in (
379
- subprocess.check_output(cmd)
509
+ subprocess
510
+ .check_output(cmd)
380
511
  .decode("utf-8")
381
512
  .splitlines()
382
513
  ):
383
514
  if line.startswith("InstallLocation"):
384
- return "C:{}".format(line.split(":")[-1].strip())
515
+ location = line[line.find(": ") + 2 :]
516
+ elif location is not None:
517
+ if line.startswith(" "):
518
+ location += line.lstrip()
519
+ else:
520
+ break
521
+ return location
385
522
 
386
523
  raise Exception(f"Couldn't find install location of {pkg}")
387
524
 
@@ -407,7 +544,7 @@ def install_cli(argv=sys.argv[1:]):
407
544
  "--destination",
408
545
  dest="dest",
409
546
  default=os.getcwd(),
410
- help="Directory to install application into. " '[default: "%default"]',
547
+ help='Directory to install application into. [default: "%default"]',
411
548
  )
412
549
  parser.add_option(
413
550
  "--app",
@@ -415,6 +552,13 @@ def install_cli(argv=sys.argv[1:]):
415
552
  default="firefox",
416
553
  help="Application being installed. [default: %default]",
417
554
  )
555
+ parser.add_option(
556
+ "--no-verify",
557
+ dest="verify",
558
+ action="store_false",
559
+ default=True,
560
+ help="Skip checksum verification when attaching a dmg file.",
561
+ )
418
562
 
419
563
  (options, args) = parser.parse_args(argv)
420
564
  if not len(args) == 1:
@@ -426,7 +570,7 @@ def install_cli(argv=sys.argv[1:]):
426
570
  if os.path.isdir(src):
427
571
  binary = get_binary(src, app_name=options.app)
428
572
  else:
429
- install_path = install(src, options.dest)
573
+ install_path = install(src, options.dest, verify=options.verify)
430
574
  binary = get_binary(install_path, app_name=options.app)
431
575
 
432
576
  print(binary)
@@ -9,16 +9,15 @@ from setuptools import setup
9
9
  try:
10
10
  here = os.path.dirname(os.path.abspath(__file__))
11
11
  description = open(os.path.join(here, "README.md")).read()
12
- except IOError:
12
+ except OSError:
13
13
  description = None
14
14
 
15
- PACKAGE_VERSION = "2.1.0"
15
+ PACKAGE_VERSION = "2.2.0"
16
16
 
17
17
  deps = [
18
18
  "mozinfo >= 0.7",
19
19
  "mozfile >= 1.0",
20
20
  "requests",
21
- "six >= 1.13.0",
22
21
  ]
23
22
 
24
23
  setup(
@@ -34,8 +33,8 @@ setup(
34
33
  "Natural Language :: English",
35
34
  "Operating System :: OS Independent",
36
35
  "Topic :: Software Development :: Libraries :: Python Modules",
37
- "Programming Language :: Python :: 2.7",
38
- "Programming Language :: Python :: 3",
36
+ "Programming Language :: Python",
37
+ "Programming Language :: Python :: 3 :: Only",
39
38
  ],
40
39
  keywords="mozilla",
41
40
  author="Mozilla Automation and Tools team",
@@ -56,4 +55,5 @@ setup(
56
55
  moz_add_to_system = mozinstall:install_cli
57
56
  moz_remove_from_system = mozinstall:uninstall_cli
58
57
  """,
58
+ python_requires=">=3.9",
59
59
  )
@@ -0,0 +1,50 @@
1
+ import os
2
+
3
+ import mozinfo
4
+ import mozinstall
5
+ import mozunit
6
+ import pytest
7
+
8
+
9
+ @pytest.mark.skipif(
10
+ mozinfo.isWin,
11
+ reason="Bug 1157352 - New firefox.exe needed for mozinstall 1.12 and higher.",
12
+ )
13
+ def test_get_binary(tmpdir, get_installer):
14
+ """Test to retrieve binary from install path."""
15
+ if mozinfo.isLinux:
16
+ installdir = mozinstall.install(get_installer("tar.xz"), tmpdir.strpath)
17
+ binary = os.path.join(installdir, "firefox")
18
+
19
+ assert mozinstall.get_binary(installdir, "firefox") == binary
20
+
21
+ elif mozinfo.isWin:
22
+ installdir_exe = mozinstall.install(
23
+ get_installer("exe"), tmpdir.join("exe").strpath
24
+ )
25
+ binary_exe = os.path.join(installdir_exe, "core", "firefox.exe")
26
+
27
+ assert mozinstall.get_binary(installdir_exe, "firefox") == binary_exe
28
+
29
+ installdir_zip = mozinstall.install(
30
+ get_installer("zip"), tmpdir.join("zip").strpath
31
+ )
32
+ binary_zip = os.path.join(installdir_zip, "firefox.exe")
33
+
34
+ assert mozinstall.get_binary(installdir_zip, "firefox") == binary_zip
35
+
36
+ elif mozinfo.isMac:
37
+ installdir = mozinstall.install(get_installer("dmg"), tmpdir.strpath)
38
+ binary = os.path.join(installdir, "Contents", "MacOS", "firefox")
39
+
40
+ assert mozinstall.get_binary(installdir, "firefox") == binary
41
+
42
+
43
+ def test_get_binary_error(tmpdir):
44
+ """Test that an InvalidBinary error is raised."""
45
+ with pytest.raises(mozinstall.InvalidBinary):
46
+ mozinstall.get_binary(tmpdir.strpath, "firefox")
47
+
48
+
49
+ if __name__ == "__main__":
50
+ mozunit.main()
@@ -0,0 +1,138 @@
1
+ import subprocess
2
+ from unittest import mock
3
+
4
+ import mozinfo
5
+ import mozinstall
6
+ import mozunit
7
+ import pytest
8
+
9
+
10
+ @pytest.mark.skipif(
11
+ mozinfo.isWin,
12
+ reason="Bug 1157352 - New firefox.exe needed for mozinstall 1.12 and higher.",
13
+ )
14
+ def test_is_installer(request, get_installer):
15
+ """Test that we can identify a correct installer."""
16
+ assert mozinstall.is_installer(get_installer("tar.xz"))
17
+ assert mozinstall.is_installer(get_installer("zip"))
18
+
19
+ if mozinfo.isWin:
20
+ assert mozinstall.is_installer(get_installer("msix"))
21
+
22
+ # test exe installer
23
+ assert mozinstall.is_installer(get_installer("exe"))
24
+
25
+ try:
26
+ # test stub browser file
27
+ # without pefile on the system this test will fail
28
+ import pefile # noqa
29
+
30
+ stub_exe = (
31
+ request.node.fspath.dirpath("build_stub").join("firefox.exe").strpath
32
+ )
33
+ assert not mozinstall.is_installer(stub_exe)
34
+ except ImportError:
35
+ pass
36
+
37
+ if mozinfo.isMac or mozinfo.isLinux:
38
+ assert mozinstall.is_installer(get_installer("dmg"))
39
+
40
+
41
+ def test_invalid_source_error(get_installer):
42
+ """Test that InvalidSource error is raised with an incorrect installer."""
43
+ if mozinfo.isWin:
44
+ with pytest.raises(mozinstall.InvalidSource):
45
+ mozinstall.install(get_installer("dmg"), "firefox")
46
+
47
+ elif mozinfo.isLinux:
48
+ with pytest.raises(mozinstall.InvalidSource):
49
+ mozinstall.install(get_installer("msix"), "firefox")
50
+
51
+ elif mozinfo.isMac:
52
+ with pytest.raises(mozinstall.InvalidSource):
53
+ mozinstall.install(get_installer("exe"), "firefox")
54
+
55
+ # Test an invalid url handler
56
+ with pytest.raises(mozinstall.InvalidSource):
57
+ mozinstall.install("file://foo.bar", "firefox")
58
+
59
+
60
+ @pytest.mark.skipif(
61
+ mozinfo.isWin,
62
+ reason="Bug 1157352 - New firefox.exe needed for mozinstall 1.12 and higher.",
63
+ )
64
+ def test_install(tmpdir, get_installer):
65
+ """Test to install an installer."""
66
+ installdir_zip = mozinstall.install(
67
+ get_installer("zip"), tmpdir.join("zip").strpath
68
+ )
69
+ assert installdir_zip == tmpdir.join("zip", "firefox").strpath
70
+
71
+ if mozinfo.isLinux:
72
+ installdir = mozinstall.install(get_installer("tar.xz"), tmpdir.strpath)
73
+ assert installdir == tmpdir.join("firefox").strpath
74
+
75
+ elif mozinfo.isWin:
76
+ installdir_exe = mozinstall.install(
77
+ get_installer("exe"), tmpdir.join("exe").strpath
78
+ )
79
+ assert installdir_exe == tmpdir.join("exe", "firefox").strpath
80
+
81
+ elif mozinfo.isMac:
82
+ installdir = mozinstall.install(get_installer("dmg"), tmpdir.strpath)
83
+ assert installdir == tmpdir.realpath().join("Firefox Stub.app").strpath
84
+
85
+ mounted_images = subprocess.check_output(["hdiutil", "info"]).decode("utf-8")
86
+ assert get_installer("dmg") not in mounted_images
87
+
88
+
89
+ def test_install_existing_target_folder(tmpdir, get_installer):
90
+ """Test that InstallError is raised when target folder already exists."""
91
+ if mozinfo.isMac:
92
+ installdir = mozinstall.install(get_installer("dmg"), tmpdir.strpath)
93
+ assert installdir == tmpdir.realpath().join("Firefox Stub.app").strpath
94
+
95
+ with pytest.raises(mozinstall.InstallError, match="App bundle already exists"):
96
+ mozinstall.install(get_installer("dmg"), tmpdir.strpath)
97
+
98
+
99
+ @pytest.mark.skipif(not mozinfo.isMac, reason="DMG installer only on macOS")
100
+ def test_install_dmg_detach_retry(tmpdir, get_installer, monkeypatch):
101
+ """Test that DMG detach retries on EBUSY errors."""
102
+ for var in ("DMG_TOOL", "HFS_TOOL", "MOZ_FETCHES_DIR"):
103
+ monkeypatch.delenv(var, raising=False)
104
+ original_check_call = subprocess.check_call
105
+ detach_call_count = 0
106
+
107
+ def mock_check_call(cmd, shell=False, **kwargs):
108
+ nonlocal detach_call_count
109
+
110
+ if shell and "hdiutil detach" in cmd:
111
+ detach_call_count += 1
112
+ if detach_call_count <= 2:
113
+ raise subprocess.CalledProcessError(16, cmd)
114
+
115
+ return original_check_call(cmd, shell=shell, **kwargs)
116
+
117
+ with mock.patch("subprocess.check_call", side_effect=mock_check_call):
118
+ installdir = mozinstall.install(get_installer("dmg"), tmpdir.strpath)
119
+ assert installdir == tmpdir.realpath().join("Firefox Stub.app").strpath
120
+
121
+ assert detach_call_count == 3
122
+
123
+
124
+ @pytest.mark.skipif(
125
+ not all(mozinstall.mozinstall._find_dmg_tools()),
126
+ reason="Needs the libdmg-hfsplus dmg and hfsplus tools",
127
+ )
128
+ def test_install_dmg_extract(tmpdir, get_installer):
129
+ """Test that a DMG can be installed by extracting it without mounting it."""
130
+ dest = tmpdir.join("dest")
131
+ dest.mkdir()
132
+ installdir = mozinstall.install(get_installer("dmg"), dest.strpath)
133
+ assert installdir == dest.realpath().join("Firefox Stub.app").strpath
134
+ assert dest.listdir() == [dest.join("Firefox Stub.app")]
135
+
136
+
137
+ if __name__ == "__main__":
138
+ mozunit.main()
@@ -0,0 +1,40 @@
1
+ import mozinfo
2
+ import mozinstall
3
+ import mozunit
4
+ import pytest
5
+
6
+
7
+ @pytest.mark.skipif(
8
+ mozinfo.isWin,
9
+ reason="Bug 1157352 - New firefox.exe needed for mozinstall 1.12 and higher.",
10
+ )
11
+ def test_is_installer(request, get_installer):
12
+ """Test that we can identify a correct installer."""
13
+
14
+ assert mozinstall.is_installer(get_installer("tar.xz"))
15
+ assert mozinstall.is_installer(get_installer("zip"))
16
+
17
+ if mozinfo.isWin:
18
+ assert mozinstall.is_installer(get_installer("msix"))
19
+
20
+ # test exe installer
21
+ assert mozinstall.is_installer(get_installer("exe"))
22
+
23
+ try:
24
+ # test stub browser file
25
+ # without pefile on the system this test will fail
26
+ import pefile # noqa
27
+
28
+ stub_exe = (
29
+ request.node.fspath.dirpath("build_stub").join("firefox.exe").strpath
30
+ )
31
+ assert not mozinstall.is_installer(stub_exe)
32
+ except ImportError:
33
+ pass
34
+
35
+ if mozinfo.isMac or mozinfo.isLinux:
36
+ assert mozinstall.is_installer(get_installer("dmg"))
37
+
38
+
39
+ if __name__ == "__main__":
40
+ mozunit.main()
@@ -0,0 +1,39 @@
1
+ import mozinfo
2
+ import mozinstall
3
+ import mozunit
4
+ import py
5
+ import pytest
6
+
7
+
8
+ @pytest.mark.skipif(
9
+ mozinfo.isWin,
10
+ reason="Bug 1157352 - New firefox.exe needed for mozinstall 1.12 and higher.",
11
+ )
12
+ def test_uninstall(tmpdir, get_installer):
13
+ """Test to uninstall an installed binary."""
14
+ if mozinfo.isLinux:
15
+ installdir = mozinstall.install(get_installer("tar.xz"), tmpdir.strpath)
16
+ mozinstall.uninstall(installdir)
17
+ assert not py.path.local(installdir).check()
18
+
19
+ elif mozinfo.isWin:
20
+ installdir_exe = mozinstall.install(
21
+ get_installer("exe"), tmpdir.join("exe").strpath
22
+ )
23
+ mozinstall.uninstall(installdir_exe)
24
+ assert not py.path.local(installdir).check()
25
+
26
+ installdir_zip = mozinstall.install(
27
+ get_installer("zip"), tmpdir.join("zip").strpath
28
+ )
29
+ mozinstall.uninstall(installdir_zip)
30
+ assert not py.path.local(installdir).check()
31
+
32
+ elif mozinfo.isMac:
33
+ installdir = mozinstall.install(get_installer("dmg"), tmpdir.strpath)
34
+ mozinstall.uninstall(installdir)
35
+ assert not py.path.local(installdir).check()
36
+
37
+
38
+ if __name__ == "__main__":
39
+ mozunit.main()
@@ -1,8 +0,0 @@
1
-
2
- # -*- Entry points: -*-
3
- [console_scripts]
4
- mozinstall = mozinstall:install_cli
5
- mozuninstall = mozinstall:uninstall_cli
6
- moz_add_to_system = mozinstall:install_cli
7
- moz_remove_from_system = mozinstall:uninstall_cli
8
-
File without changes