-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpytkeditor
More file actions
63 lines (53 loc) · 1.73 KB
/
Copy pathpytkeditor
File metadata and controls
63 lines (53 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
PyTkEditor - Python IDE
Copyright 2018-2019 Juliette Monsel <j_4321 at protonmail dot com>
PyTkEditor is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
PyTkEditor is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Main
"""
import sys
import os
import signal
import traceback
import logging
from pytkeditorlib import App
from pytkeditorlib.utils.constants import PIDFILE, OPENFILE_PATH
from pytkeditorlib.dialogs import showerror
pid = str(os.getpid())
if os.path.isfile(PIDFILE):
with open(PIDFILE) as fich:
old_pid = fich.read().strip()
if os.path.exists("/proc/%s" % old_pid):
if len(sys.argv) > 1:
with open(OPENFILE_PATH, 'w') as f:
for path in sys.argv[1:]:
f.write(os.path.abspath(path) + '\n')
os.kill(int(old_pid), signal.SIGUSR1)
sys.exit()
else:
# it is an old pid file
os.remove(PIDFILE)
open(PIDFILE, 'w').write(pid)
try:
app = App(pid, *sys.argv[1:])
app.mainloop()
except Exception as e:
msg = traceback.format_exc()
print(msg)
showerror("Error", "{}: {}".format(type(e), e), msg)
finally:
try:
logging.shutdown()
os.unlink(PIDFILE)
except Exception:
pass