-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdropbox_start.py
103 lines (85 loc) · 2.75 KB
/
dropbox_start.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/python
#
# Fix the filesystem detection in the Linux Dropbox client
# Copyright (C) 2018 Marco Leogrande
#
# This program 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.
#
# This program 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/>.
#
# This code is loosely based on:
# dropbox
# Dropbox frontend script
# This file is part of nautilus-dropbox 2.10.0
import os
import subprocess
import sys
import time
# Python 3 compatibility on xrange
# Ref: https://stackoverflow.com/a/31136897/1259696
try:
xrange
except NameError:
xrange = range
def is_dropbox_running():
pidfile = os.path.expanduser("~/.dropbox/dropbox.pid")
try:
with open(pidfile, "r") as f:
pid = int(f.read())
with open("/proc/%d/cmdline" % pid, "r") as f:
cmdline = f.read().lower()
except:
cmdline = ""
return "dropbox" in cmdline
def start_dropbox():
lib_dir = os.path.dirname(os.path.realpath(__file__))
lib_path = os.path.join(lib_dir, "libdropbox_fs_fix.so")
if not os.access(lib_path, os.X_OK):
print(">>> Library '%s' is not available!" % lib_path)
return False
os.environ["LD_PRELOAD"] = lib_path
db_path = os.path.expanduser(u"~/.dropbox-dist/dropboxd").encode(
sys.getfilesystemencoding()
)
if os.access(db_path, os.X_OK):
f = open("/dev/null", "w")
# we don't reap the child because we're gonna die anyway, let init do it
a = subprocess.Popen(
[db_path],
preexec_fn=os.setsid,
cwd=os.path.expanduser("~"),
stderr=sys.stderr,
stdout=f,
close_fds=True,
)
# in seconds
interval = 0.5
wait_for = 60
for i in xrange(int(wait_for / interval)):
if is_dropbox_running():
return True
# back off from connect for a while
time.sleep(interval)
return False
else:
return False
def main():
if is_dropbox_running():
print(">>> Dropbox is already running")
return 0
if start_dropbox():
print(">>> Dropbox started successfully")
return 0
print(">>> Dropbox failed to start!")
return 1
if __name__ == "__main__":
sys.exit(main())