forked from adamreeve/Mendeley-FileSync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaunch_mendeley.py
executable file
·73 lines (55 loc) · 2.11 KB
/
launch_mendeley.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
#!/usr/bin/env python
import sqlite3 as lite
import subprocess
import shutil
import os
from glob import glob
import pdb
from mendeleyfilesync import MendeleyDB, relative_file, directory_to_url
on_master = True
if os.name == 'posix':
HOME = os.environ['HOME']
data_dir = os.path.join(HOME, r'.local/share/data/Mendeley Ltd./Mendeley Desktop')
file_path = r'/Data/johnbur/Dropbox/Library'
on_master = False
elif os.name == 'nt':
HOME = os.environ['LOCALAPPDATA']
data_dir = os.path.join(HOME, r'/Mendeley Ltd/Mendeley Desktop')
print HOME
file_path = r'D:/johnbur/Dropbox/Library'
on_master = True
else:
raise IOError('Cannot Locate Database')
local_data = (r'Organiser/OrganiserLocation', file_path)
def change_os_paths(file_path):
"""
changes file prefixes in database as defined bu file_path
"""
with MendeleyDB(MENDELEY_DB, file_path) as mdb:
mendeley_entries = set(mdb.document_files())
for me_file in mendeley_entries:
me_file.name = me_file.name.replace(mdb.org_url + u'/', '')
# Do this only for existing files?
#exists = relative_file(me_file)
mdb.update_file(me_file)
return mdb.org_organiser # to save for reverting
if not on_master:
MENDELEY_DB = glob(os.path.join(data_dir, '*www.mendeley.com.sqlite'))[0]
MONITOR_DB = glob(os.path.join(data_dir, 'monitor.sqlite'))[0]
shutil.copy(MENDELEY_DB, MENDELEY_DB + '.bak')
shutil.copy(MONITOR_DB, MONITOR_DB + '.bak')
shutil.copy(MONITOR_DB + '.linux', MONITOR_DB)
original_organiser_dir = change_os_paths(file_path)
# pdb.set_trace()
## Now run mendeley and wait for exit.
command='mendeleydesktop.bin'
subprocess.call([command, ''])
## When mendeley exits, change back to orginal settings
## open the database to make changes
___ = change_os_paths(original_organiser_dir)
shutil.copy(MONITOR_DB, MONITOR_DB + '.linux')
shutil.copy(MONITOR_DB + '.bak', MONITOR_DB)
else:
command=r'C:\\Program Files (x86)\\Mendeley Desktop\\MendeleyDesktop.exe'
subprocess.call([command, ''])
print 'okay, now done.'