Skip to content

Commit 9d1edf3

Browse files
committed
v0.7.4
improve ipc handling * encapsulate * sync way how ipc methods are set * set them as early as possible * better logging
1 parent 981b458 commit 9d1edf3

File tree

5 files changed

+37
-18
lines changed

5 files changed

+37
-18
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
# CHANGELOG
22

3+
## 0.7.4 (Packaging is fun and good for testing) - 2017-06-11
4+
5+
### Changed
6+
7+
- improve ipc handling - fix setting methods too late
8+
39
## 0.7.3 (Do the right thing) - 2017-06-11
410

11+
### Fixed
12+
513
- use actual partials path for initialization instead of assuming that parent of config path == partials path
614

715
## 0.7.2 (Need for speed) - 2017-06-11
816

17+
### Changed
18+
919
- shave off a few hundred precious milliseconds startup time, by moving the very expensive version fetching into a function that is only called, when the version is really needed.
1020
- help the user, when they use a non existing command
1121
- remove unwanted side effects from message

i3configger/build.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def generate_status_file_content(prts, selectKey, selectValue, ctx):
8585
def check_config(content):
8686
tmpPath = Path(tempfile.gettempdir()) / 'i3config_check'
8787
tmpPath.write_text(content)
88-
errorReport = ipc.I3.get_config_errors(tmpPath)
88+
errorReport = ipc.I3.get_config_error_report(tmpPath)
8989
if errorReport:
9090
raise exc.ConfigError(
9191
f"config:\n{content}\n\nerrors:\n{errorReport.decode()}"

i3configger/ipc.py

+23-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1+
import logging
12
import subprocess
23

3-
from i3configger.base import log
4+
log = logging.getLogger(__name__)
5+
6+
7+
def configure(args):
8+
I3.set_msg_type(args.i3_refresh_msg)
9+
log.info(f'set i3 refresh method to {I3.refresh.__name__}', )
10+
Notify.set_notify_command(args.notify)
11+
log.info(f'set notify method to {Notify.send.__name__}', )
12+
13+
14+
def communicate(msg='new config active', refresh=False):
15+
if refresh:
16+
I3.refresh()
17+
StatusBar.refresh()
18+
Notify.send(msg)
419

520

621
class I3:
@@ -38,30 +53,30 @@ def _send_i3_msg(cls, msg):
3853
return True
3954

4055
@classmethod
41-
def get_config_errors(cls, path):
56+
def get_config_error_report(cls, path):
57+
cmd = ['i3', '-C', '-c', str(path)]
4258
try:
43-
subprocess.check_output(['i3', '-C', '-c', str(path)])
44-
return None
59+
return subprocess.check_output(cmd).decode()
4560
except subprocess.CalledProcessError as e:
4661
return e.output
4762

4863

4964
class Notify:
5065
@classmethod
5166
def set_notify_command(cls, notify):
52-
if not notify:
53-
log.debug("do not send notifications")
54-
cls.send = cls.nop
67+
cls.send = cls.notify_send if notify else cls.nop
5568

5669
@classmethod
57-
def send(cls, msg, urgency='low'):
70+
def notify_send(cls, msg, urgency='low'):
5871
subprocess.check_call([
5972
'notify-send', '-a', 'i3configger', '-t', '1', '-u', urgency, msg])
6073

6174
@staticmethod
6275
def nop(*args, **kwargs):
6376
pass
6477

78+
send = notify_send
79+
6580

6681
class StatusBar:
6782
@classmethod

i3configger/main.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def main():
1919

2020

2121
def _main(args):
22+
ipc.configure(args)
2223
if args.version:
2324
print(f"i3configger {base.get_version()}")
2425
return 0
@@ -35,9 +36,6 @@ def _main(args):
3536
sys.exit("Already running - did you mean to send a message?")
3637
log.info("let the daemon do the work")
3738
return 0
38-
ipc.I3.set_msg_type(args.i3_refresh_msg)
39-
log.info("set i3 refresh method to %s", ipc.I3.refresh)
40-
ipc.Notify.set_notify_command(args.notify)
4139
if args.daemon:
4240
daemonize.daemonize(args.v, args.log, configPath)
4341
elif args.watch:
@@ -47,6 +45,4 @@ def _main(args):
4745
sys.exit("interrupted by user")
4846
else:
4947
build.build_all(configPath)
50-
ipc.I3.refresh()
51-
ipc.StatusBar.refresh()
52-
ipc.Notify.send('new config active')
48+
ipc.communicate(refresh=True)

i3configger/watch.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,4 @@ def forever(configPath):
2525
paths = [partialsPath / e[-1] for e in events]
2626
if any(p.suffix in [base.SUFFIX, '.json'] for p in paths):
2727
build.build_all(configPath)
28-
ipc.I3.refresh()
29-
ipc.StatusBar.refresh()
30-
ipc.Notify.send('new config active')
28+
ipc.communicate(refresh=True)

0 commit comments

Comments
 (0)