Skip to content

Commit f5bdd6e

Browse files
committed
Refactor
1 parent b86f178 commit f5bdd6e

File tree

13 files changed

+139
-49
lines changed

13 files changed

+139
-49
lines changed

Build.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Alfred Workflow: Time Converter
22

3+
[![downloads](https://img.shields.io/github/downloads/rexzhang/alfred-workflow-time-converter/total)](https://github.com/rexzhang/asgi-webdav/releases)
4+
35
## What
46

57
![demo-basic](docs/demo-basic.gif)

Update3rdLib.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

afw.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/usr/bin/env python
2+
3+
import json
4+
import subprocess
5+
from pathlib import Path
6+
from uuid import uuid4
7+
from zipfile import ZipFile
8+
9+
import click
10+
11+
FILENAME_LIST = (
12+
"info.plist",
13+
"entry_point.py",
14+
"core.py",
15+
)
16+
17+
PATH_LIST = (
18+
"arrow",
19+
"backports",
20+
"dateutil",
21+
"ualfred",
22+
)
23+
24+
25+
# def main():
26+
# with open("version") as f:
27+
# version = f.readline().rstrip("\n\r ")
28+
#
29+
# zip_filename = f"time-converter.{version}.alfredworkflow"
30+
# z = ZipFile(zip_filename, mode="w")
31+
#
32+
# for filename in FILENAME_LIST:
33+
# z.write(filename)
34+
#
35+
# for pathname in PATH_LIST:
36+
# for root, dirs, files in walk(pathname):
37+
# for filename in files:
38+
# if filename.rfind(".pyc") == -1:
39+
# z.write(join(root, filename))
40+
#
41+
# z.close()
42+
#
43+
# print(f"Create Alfred workflow({zip_filename}) finished.")
44+
45+
46+
@click.group()
47+
def cli():
48+
pass
49+
50+
51+
@cli.command()
52+
@click.argument("workflow_path")
53+
def build(workflow_path: str):
54+
workflow_path = Path(".").joinpath(workflow_path)
55+
56+
# load package info
57+
with open(workflow_path.joinpath("package.json")) as f:
58+
package_info = json.load(f)
59+
60+
# build package
61+
build_path = Path(".").joinpath("build").joinpath(uuid4().hex)
62+
build_path.mkdir(parents=True)
63+
dist_path = Path(".").joinpath("dist")
64+
dist_path.mkdir(exist_ok=True)
65+
package_path = dist_path.joinpath(
66+
f"{package_info['name']}.{package_info['version']}.alfredworkflow"
67+
)
68+
69+
# build package - depend
70+
print("Prepare...")
71+
requirements: list[str] = list()
72+
with open(workflow_path.joinpath("requirements.txt")) as f:
73+
for line in f.readlines():
74+
if line.startswith("#") or len(line) == 0:
75+
continue
76+
77+
requirements.append(line)
78+
79+
for requirement in requirements:
80+
subprocess.run(
81+
["pip", "install", "-U", f"--target={str(build_path)}", requirement],
82+
capture_output=True,
83+
)
84+
85+
# build package - zip
86+
package_file = ZipFile(package_path, mode="w")
87+
88+
# for filename in FILENAME_LIST:
89+
# package_file.write(filename)
90+
91+
print("Add 3rd depends files...")
92+
build_path_str_length = len(str(build_path)) + 1
93+
for file in build_path.rglob("*"):
94+
if file.suffix == ".pyc" or file.name == "__pycache__":
95+
continue
96+
97+
arc_name = str(file)[build_path_str_length:]
98+
print(arc_name)
99+
package_file.write(file, arcname=arc_name)
100+
101+
print("Add workflow files...")
102+
workflow_files: list[str] = ["info.plist", "main.py", "__init__.py"]
103+
icon_file = package_info.get("icon")
104+
if icon_file:
105+
workflow_files.append(icon_file)
106+
107+
for file in workflow_files:
108+
package_file.write(workflow_path.joinpath(file), arcname=file)
109+
110+
package_file.write("entry_point.py")
111+
112+
package_file.close()
113+
print(f"Create Alfred workflow[{package_path}] finished.")
114+
115+
116+
@cli.command()
117+
def test():
118+
click.echo("test...todo")
119+
120+
121+
if __name__ == "__main__":
122+
cli()

afw_time_converter/__init__.py

Whitespace-only changes.
File renamed without changes.
File renamed without changes.

core.py renamed to afw_time_converter/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def get_feedback(self):
203203
return f
204204

205205

206-
def do_convert(wf):
206+
def do_workflow(wf):
207207
time = Time(wf)
208208
time.do_parser()
209209

afw_time_converter/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "time-converter",
3+
"version": "0.3.0",
4+
"icon": "icon.png"
5+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ualfred
2+
arrow

0 commit comments

Comments
 (0)