Skip to content
This repository was archived by the owner on Jun 22, 2024. It is now read-only.

Commit

Permalink
Removed plutil requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Akhmetov committed Sep 25, 2018
1 parent b203090 commit 2689977
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New example: [shields.toml](/examples/shields.toml)
- New action: SpeakTextAction
- Added `default=True` to field `SetLowPowerModeAction.on`.
- Removed `plutil` requirement

## [0.7.0] - 25.09.2018

Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ sc.actions = [

## How to use

### Requirements

This library requires `plutil` tool, which should be installed on MacOS by default.
On Linux, you should be able to use `plistutil` instead.

### Installation

```bash
Expand Down
7 changes: 1 addition & 6 deletions docs/python_tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ How to use this package from your python code:
```python

from shortcuts import Shortcut, actions
from shortcuts.utils import convert_plist_to_binary


sc = Shortcut()

Expand All @@ -23,11 +21,8 @@ sc.actions = [

file_path = 's.shortcut'

with open(file_path, 'w') as f:
with open(file_path, 'wb') as f:
sc.dump(f, file_format='plist')

convert_plist_to_binary(file_path)

```

Now you can upload `s.shortcut` to your phone and open it with Shortcuts app.
Expand Down
11 changes: 2 additions & 9 deletions shortcuts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,17 @@
import os.path

import shortcuts
from shortcuts.utils import convert_plist_to_binary, convert_plist_to_xml


def convert_shortcut(input_filepath, out_filepath):
input_format = _get_format(input_filepath)
out_format = _get_format(out_filepath)

if input_format == 'plist':
convert_plist_to_xml(input_filepath)

with open(input_filepath, 'rb') as f:
sc = shortcuts.Shortcut.load(f, file_format=input_format)
with open(out_filepath, 'w') as f:
with open(out_filepath, 'wb') as f:
sc.dump(f, file_format=out_format)

if out_format == 'plist':
convert_plist_to_binary(out_filepath)


def _get_format(filepath):
_, ext = os.path.splitext(filepath)
Expand All @@ -34,7 +27,7 @@ def _get_format(filepath):

def main():
parser = argparse.ArgumentParser(description='Shortcuts: Siri shortcuts creator')
parser.add_argument('file', nargs='?', help='Input file: *.(toml|shortcut)')
parser.add_argument('file', nargs='?', help='Input file: *.(toml|shortcut|itunes url)')
parser.add_argument('output', nargs='?', help='Output file: *.(toml|shortcut)')
parser.add_argument('--version', action='store_true', help='Version information')

Expand Down
11 changes: 9 additions & 2 deletions shortcuts/dump.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import plistlib
from typing import TYPE_CHECKING, Any, Dict, TextIO, Type
from typing import TYPE_CHECKING, Any, BinaryIO, Dict, Type

import toml

Expand All @@ -13,14 +13,21 @@ class BaseDumper:
def __init__(self, shortcut: 'Shortcut') -> None:
self.shortcut = shortcut

def dump(self, file_obj: TextIO) -> None:
def dump(self, file_obj: BinaryIO) -> None:
file_obj.write(self.dumps())

def dumps(self) -> str:
raise NotImplementedError()


class PListDumper(BaseDumper):
def dump(self, file_obj: BinaryIO) -> None:
binary = plistlib.dumps( # todo: change dumps to binary and remove this
plistlib.loads(self.dumps().encode('utf-8')),
fmt=plistlib.FMT_BINARY,
)
file_obj.write(binary)

def dumps(self) -> str:
data = {
'WFWorkflowActions': self.shortcut._get_actions(),
Expand Down
9 changes: 0 additions & 9 deletions shortcuts/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +0,0 @@
from subprocess import call


def convert_plist_to_binary(filepath):
call(['plutil', '-convert', 'binary1', filepath])


def convert_plist_to_xml(filepath):
call(['plutil', '-convert', 'xml1', filepath])

0 comments on commit 2689977

Please sign in to comment.