Skip to content

Commit

Permalink
Merge pull request #43 from homebysix/dev
Browse files Browse the repository at this point in the history
2.0.0 merge to main
  • Loading branch information
homebysix authored Apr 13, 2024
2 parents 6ea7975 + ec4e93e commit 60c65b0
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 50 deletions.
19 changes: 19 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[flake8]
select = B,C,E,F,P,W,B9
max-line-length = 80
### DEFAULT IGNORES FOR 4-space INDENTED PROJECTS ###
# E127, E128 are hard to silence in certain nested formatting situations.
# E203 doesn't work for slicing
# E265, E266 talk about comment formatting which is too opinionated.
# E402 warns on imports coming after statements. There are important use cases
# that require statements before imports.
# E501 is not flexible enough, we're using B950 instead.
# E722 is a duplicate of B001.
# P207 is a duplicate of B003.
# P208 is a duplicate of C403.
# W503 talks about operator formatting which is too opinionated.
ignore = E127, E128, E203, E265, E266, E402, E501, E722, P207, P208, W503
exclude =
.git,
.hg,
max-complexity = 65
6 changes: 3 additions & 3 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[settings]
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
include_trailing_comma=True
line_length=88
multi_line_output=3
use_parentheses=True
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).

## [2.0.0] - 2024-04-13

## [Unreleased]
This release fixes compatibility with Python 10.12 by removing the dependencies on `distutils.versions`. (Thanks to @arubdesu for #42.)

Nothing yet.
### Removed

- Removed Python 2 support. If you're still deploying docklib to macOS versions prior to Monterey 12.3, be sure you're deploying a Python runtime like [MacAdmins Python](https://github.com/macadmins/python) rather than relying on the built-in `/usr/bin/python`.
- Removed macOS version detection. This may cause unexpected behavior when referencing the `AllowDockFixupOverride`, `show-recents`, `recent-apps`, `dblclickbehavior`, `show-recents-immutable`, and `windowtabbing` keys on macOS versions prior to Big Sur 11.0.

### Changed

- `makeDockAppSpacer()` parameter name has changed from `type` to `tile_type`. Please update your scripts if you use this function.
- Updated unit tests with new `is-beta` preference key present in macOS Sonoma Dock tiles.

## [1.3.0] - 2021-05-31

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The very capable [dockutil](https://github.com/kcrawford/dockutil) tool serves a

The primary benefit of **docklib** is that it allows the Dock to be manipulated in a "Pythonic" way. By parsing the Dock configuration into an object with attributes and data structures that can be modified using familiar functions like `.append()` and `.insert()`, docklib aims to make Python scripters feel at home.

In contrast, **dockutil** behaves more like a shell command-line utility. This makes dockutil a good choice if you're more comfortable writing user setup scripts in bash or zsh. Dockutil also has an `--allhomes` argument that allows Dock configuration for all users to be modified at the same time. Docklib isn't designed for this, instead focusing on configuring the Dock for the user that is currently logged in (for example, via an [outset](https://github.com/chilcote/outset) `login-once` or `login-every` script). [Here's](https://appleshare.it/posts/use-dockutil-in-a-script/) a great article to get you started with dockutil, if that sounds like what you're after.
In contrast, **dockutil** behaves more like a shell command-line utility and is written in Swift. This makes dockutil a good choice if you don't have a 'management python' or you're more comfortable writing user setup scripts in bash or zsh. Dockutil also has an `--allhomes` argument that allows Dock configuration for all users to be modified at the same time. Docklib isn't designed for this, instead focusing on configuring the Dock for the user that is currently logged in (for example, via an [outset](https://github.com/macadmins/outset) `login-once` or `login-every` script). [Here's](https://appleshare.it/posts/use-dockutil-in-a-script/) a great article to get you started with dockutil, if that sounds like what you're after.

## Installation

Expand Down
2 changes: 1 addition & 1 deletion docklib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .docklib import *

__version__ = "1.3.0"
__version__ = "2.0.0"
68 changes: 25 additions & 43 deletions docklib/docklib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

# pylint: disable=C0103

"""Python module intended to assist IT administrators with manipulation of the macOS Dock.
Expand All @@ -9,18 +7,7 @@

import os
import subprocess
from distutils.version import LooseVersion
from platform import mac_ver

try:
# Python 3
from urllib.parse import unquote, urlparse
except ImportError:
# Python 2
from urllib import unquote

from urlparse import urlparse

from urllib.parse import unquote, urlparse

# pylint: disable=E0611
from Foundation import (
Expand Down Expand Up @@ -50,38 +37,33 @@ class Dock:
_SECTIONS = ["persistent-apps", "persistent-others"]
_MUTABLE_KEYS = [
"autohide",
"orientation",
"tilesize",
"largesize",
"orientation-immutable",
"position-immutable",
"autohide-immutable",
"contents-immutable",
"dblclickbehavior",
"largesize",
"launchanim",
"launchanim-immutable",
"magnification",
"magnification-immutable",
"magsize-immutable",
"show-progress-indicators",
"contents-immutable",
"size-immutable",
"mineffect",
"mineffect-immutable",
"size-immutable",
"minimize-to-application",
"minimize-to-application-immutable",
"orientation",
"orientation-immutable",
"position-immutable",
"tilesize",
"show-process-indicators",
"launchanim",
"launchanim-immutable",
"show-progress-indicators",
"show-recents",
"show-recents-immutable",
"size-immutable",
"windowtabbing",
"AllowDockFixupOverride",
]

_IMMUTABLE_KEYS = ["mod-count", "trash-full"]
if LooseVersion(mac_ver()[0]) >= LooseVersion("10.12"):
_MUTABLE_KEYS.append("AllowDockFixupOverride")
if LooseVersion(mac_ver()[0]) >= LooseVersion("10.14"):
_MUTABLE_KEYS.append("show-recents")
_IMMUTABLE_KEYS.append("recent-apps")
if LooseVersion(mac_ver()[0]) >= LooseVersion("10.15"):
_MUTABLE_KEYS.extend(
["dblclickbehavior", "show-recents-immutable", "windowtabbing"]
)
_IMMUTABLE_KEYS = ["mod-count", "recent-apps", "trash-full"]

items = {}

Expand All @@ -107,8 +89,8 @@ def save(self):
for key in self._SECTIONS:
try:
CFPreferencesSetAppValue(key, self.items[key], self._DOMAIN)
except Exception:
raise DockError
except Exception as exc:
raise DockError from exc
for key in self._MUTABLE_KEYS:
# Python doesn't support hyphens in attribute names, so convert
# to/from underscores as needed.
Expand All @@ -119,8 +101,8 @@ def save(self):
getattr(self, key.replace("-", "_")),
self._DOMAIN,
)
except Exception:
raise DockError
except Exception as exc:
raise DockError from exc
if not CFPreferencesAppSynchronize(self._DOMAIN):
raise DockError

Expand Down Expand Up @@ -253,12 +235,12 @@ def replaceDockEntry(
if found_index > -1:
self.items[section][found_index] = newitem

def makeDockAppSpacer(self, type="spacer-tile"):
def makeDockAppSpacer(self, tile_type="spacer-tile"):
"""Makes an empty space in the Dock."""
if type not in ["spacer-tile", "small-spacer-tile"]:
msg = "{0}: invalid makeDockAppSpacer type.".format(type)
if tile_type not in ["spacer-tile", "small-spacer-tile"]:
msg = f"{tile_type}: invalid makeDockAppSpacer type."
raise ValueError(msg)
result = {"tile-data": {}, "tile-type": type}
result = {"tile-data": {}, "tile-type": tile_type}

return result

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyobjc==10.1
1 change: 1 addition & 0 deletions tests/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def test_20_tile_data_keys(self):
"file-label",
"file-mod-date",
"file-type",
"is-beta",
"label",
"parent-mod-date",
"preferreditemsize",
Expand Down

0 comments on commit 60c65b0

Please sign in to comment.