overleaf-sync 1.2.0__tar.gz → 2.0.0a1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- overleaf_sync-2.0.0a1/PKG-INFO +139 -0
- {overleaf-sync-1.2.0 → overleaf_sync-2.0.0a1}/README.md +6 -4
- {overleaf-sync-1.2.0 → overleaf_sync-2.0.0a1}/olsync/__init__.py +1 -1
- {overleaf-sync-1.2.0 → overleaf_sync-2.0.0a1}/olsync/olbrowserlogin.py +0 -1
- {overleaf-sync-1.2.0 → overleaf_sync-2.0.0a1}/olsync/olclient.py +105 -24
- {overleaf-sync-1.2.0 → overleaf_sync-2.0.0a1}/olsync/olsync.py +39 -5
- overleaf_sync-2.0.0a1/pyproject.toml +60 -0
- overleaf-sync-1.2.0/.gitignore +0 -118
- overleaf-sync-1.2.0/PKG-INFO +0 -7
- overleaf-sync-1.2.0/pyproject.toml +0 -26
- overleaf-sync-1.2.0/requirements.txt +0 -7
- overleaf-sync-1.2.0/setup.py +0 -35
- {overleaf-sync-1.2.0 → overleaf_sync-2.0.0a1}/LICENSE +0 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: overleaf-sync
|
|
3
|
+
Version: 2.0.0a1
|
|
4
|
+
Summary: Overleaf Two-Way Sync Tool
|
|
5
|
+
Keywords: overleaf,sync,latex,tex
|
|
6
|
+
Author-email: Moritz Glöckl <moritzgloeckl@users.noreply.github.com>
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: requests >=2.31,<3
|
|
14
|
+
Requires-Dist: beautifulsoup4 >=4.12,<5
|
|
15
|
+
Requires-Dist: yaspin >=3,<4
|
|
16
|
+
Requires-Dist: python-dateutil >=2.8,<3
|
|
17
|
+
Requires-Dist: click >=8.1,<9
|
|
18
|
+
Requires-Dist: socketIO-client ==0.5.7.2
|
|
19
|
+
Requires-Dist: websocket-client >=1,<2
|
|
20
|
+
Requires-Dist: pytest >=8 ; extra == "dev"
|
|
21
|
+
Requires-Dist: pytest-cov >=5 ; extra == "dev"
|
|
22
|
+
Requires-Dist: responses >=0.25 ; extra == "dev"
|
|
23
|
+
Requires-Dist: ruff >=0.6 ; extra == "dev"
|
|
24
|
+
Requires-Dist: PySide6 >=6.5,<7 ; extra == "gui"
|
|
25
|
+
Project-URL: Homepage, https://github.com/moritzgloeckl/overleaf-sync
|
|
26
|
+
Project-URL: Issues, https://github.com/moritzgloeckl/overleaf-sync/issues
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Provides-Extra: gui
|
|
29
|
+
|
|
30
|
+
# Overleaf-Sync
|
|
31
|
+
### Easy Overleaf Two-Way Synchronization
|
|
32
|
+
|
|
33
|
+
   
|
|
34
|
+
|
|
35
|
+
This tool provides an easy way to synchronize Overleaf projects from and to your local computer. No paid account necessary.
|
|
36
|
+
|
|
37
|
+
----
|
|
38
|
+
|
|
39
|
+
## Features
|
|
40
|
+
- Sync your locally modified `.tex` (and other) files to your Overleaf projects
|
|
41
|
+
- Sync your remotely modified `.tex` (and other) files to computer
|
|
42
|
+
- Works with free Overleaf account
|
|
43
|
+
- No Git or Dropbox required
|
|
44
|
+
- Does not steal or store your login credentials (works with a persisted cookie, logging in is done on the original Overleaf website)
|
|
45
|
+
|
|
46
|
+
## How To Use
|
|
47
|
+
### Install
|
|
48
|
+
The package is available via [PyPI](https://pypi.org/project/overleaf-sync/) and needs Python 3.11 or newer. Install it including the login window (`gui` extra):
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
moritz@github:~/test$ pip3 install "overleaf-sync[gui]"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Depending on your local Python installation, you might need to use `pip` instead of `pip3`. [pipx](https://pipx.pypa.io/) works too: `pipx install "overleaf-sync[gui]"`.
|
|
55
|
+
|
|
56
|
+
> **2.0 pre-release:** Overleaf changed its website in a way that broke version 1.2.0. The fixes are available as a pre-release: `pip3 install --pre "overleaf-sync[gui]"`. Please report any problems in the [issues](https://github.com/moritzgloeckl/overleaf-sync/issues).
|
|
57
|
+
|
|
58
|
+
### Prerequisites
|
|
59
|
+
- Create your project on [Overleaf](https://www.overleaf.com/project), for example a project named `test`. Overleaf-sync is not able to create projects (yet).
|
|
60
|
+
- Create a folder, preferably with the same name as the project (`test`) on your computer.
|
|
61
|
+
- Execute the script from that folder (`test`).
|
|
62
|
+
- If you do not specify the project name, overleaf-sync uses the current folder's name as the project name.
|
|
63
|
+
|
|
64
|
+
### Usage
|
|
65
|
+
#### Login
|
|
66
|
+
```
|
|
67
|
+
moritz@github:~/test$ ols login [--path]
|
|
68
|
+
Login successful. Cookie persisted as `.olauth`. You may now sync your project.
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Logging in will be handled by a mini web browser opening on your device (using Qt via PySide6, from the `gui` extra). You can then enter your username and password securely on the official Overleaf website. You might get asked to solve a CAPTCHA in the process. Your credentials are sent to Overleaf over HTTPS.
|
|
72
|
+
|
|
73
|
+
It then stores your *cookie* (**not** your login credentials) in a hidden file called `.olauth` in the same folder you run the command from. It is possible to store the cookie elsewhere using the `--path` option. The cookie file will not be synced to or from Overleaf.
|
|
74
|
+
|
|
75
|
+
Keep the `.olauth` file save, as it can be used to log in into your account.
|
|
76
|
+
|
|
77
|
+
### Listing all projects
|
|
78
|
+
```
|
|
79
|
+
moritz@github:~/test$ ols list [--store-path -v/--verbose]
|
|
80
|
+
10/31/2021, 01:23:45 - Project A
|
|
81
|
+
09/21/2020, 01:23:45 - Project B
|
|
82
|
+
08/11/2019, 01:23:45 - Project C
|
|
83
|
+
07/01/2018, 01:23:45 - Project D
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Use `ols list` to conveniently list all projects in your account available for syncing.
|
|
87
|
+
|
|
88
|
+
### Downloading project's PDF
|
|
89
|
+
```
|
|
90
|
+
moritz@github:~/test$ ols download [--name --download-path --store-path -v/--verbose]
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Use `ols download` to compile and download your project's PDF. Specify a download path if you do not want to store the PDF file in the current folder. Currently only downloads the first PDF file it finds.
|
|
94
|
+
|
|
95
|
+
### Syncing
|
|
96
|
+
```
|
|
97
|
+
moritz@github:~/test$ ols [-l/--local-only -r/--remote-only --store-path -p/--path -i/--olignore]
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Just calling `ols` will two-way sync your project. When there are changes both locally, and remotely you will be asked which file to keep. Using the `-l` or `-r` option you can specify to either sync local project files to Overleaf only or Overleaf files to local ones only respectively. When using these options you can also sync deleted files. If a file has been deleted it can either be deleted on the target (remote when `-l`, local when `-r`) as well, restored on the source (local when `-l`, remote when `-r`) or ignored.
|
|
101
|
+
|
|
102
|
+
The option `--store-path` specifies the path of the cookie file created by the `login` command. If you did not change its path, you do not need to specify this argument. The `-p/--path` option allows you to specify a different sync folder than the one you're calling `ols` from. The `-i/--olignore` option allows you to specify the path of an `.olignore` file. It uses `fnmatch` internally, so it may have some similarity to `.gitignore` but doesn't work exactly the same. For example, if you wish to exclude a specific folder named `out`, you need to specify it as `out/*`. See [here](https://docs.python.org/3/library/fnmatch.html) for more information.
|
|
103
|
+
|
|
104
|
+
Sample Output:
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
Project queried successfully.
|
|
108
|
+
✅ Querying project
|
|
109
|
+
Project downloaded successfully.
|
|
110
|
+
✅ Downloading project
|
|
111
|
+
|
|
112
|
+
Syncing files from remote to local
|
|
113
|
+
====================
|
|
114
|
+
|
|
115
|
+
[SYNCING] report.tex
|
|
116
|
+
report.tex does not exist on local. Creating file.
|
|
117
|
+
|
|
118
|
+
[SYNCING] other-report.tex
|
|
119
|
+
other-report.tex does not exist on local. Creating file.
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
✅ Syncing files from remote to local
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Known Bugs
|
|
126
|
+
- When modifying a file on Overleaf and immediately syncing afterwards, the tool might not detect the changes. Please allow 1-2 minutes after modifying a file on Overleaf before syncing it to your local computer.
|
|
127
|
+
|
|
128
|
+
## Contributing
|
|
129
|
+
|
|
130
|
+
All pull requests and change/feature requests are welcome.
|
|
131
|
+
|
|
132
|
+
## Disclaimer
|
|
133
|
+
THE AUTHOR OF THIS SOFTWARE AND THIS SOFTWARE IS NOT ENDORSED BY, DIRECTLY AFFILIATED WITH, MAINTAINED, AUTHORIZED, OR SPONSORED BY OVERLEAF OR WRITELATEX LIMITED. ALL PRODUCT AND COMPANY NAMES ARE THE REGISTERED TRADEMARKS OF THEIR ORIGINAL OWNERS. THE USE OF ANY TRADE NAME OR TRADEMARK IS FOR IDENTIFICATION AND REFERENCE PURPOSES ONLY AND DOES NOT IMPLY ANY ASSOCIATION WITH THE TRADEMARK HOLDER OF THEIR PRODUCT BRAND.
|
|
134
|
+
|
|
135
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
136
|
+
|
|
137
|
+
THIS SOFTWARE WAS DESIGNED TO BE USED ONLY FOR RESEARCH PURPOSES. THIS SOFTWARE COMES WITH NO WARRANTIES OF ANY KIND WHATSOEVER. USE IT AT YOUR OWN RISK! IF THESE TERMS ARE NOT ACCEPTABLE, YOU AREN'T ALLOWED TO USE THE CODE.
|
|
138
|
+
|
|
139
|
+
|
|
@@ -16,13 +16,15 @@ This tool provides an easy way to synchronize Overleaf projects from and to your
|
|
|
16
16
|
|
|
17
17
|
## How To Use
|
|
18
18
|
### Install
|
|
19
|
-
The package is available via [PyPI](https://pypi.org/project/overleaf-sync/).
|
|
19
|
+
The package is available via [PyPI](https://pypi.org/project/overleaf-sync/) and needs Python 3.11 or newer. Install it including the login window (`gui` extra):
|
|
20
20
|
|
|
21
21
|
```
|
|
22
|
-
moritz@github:~/test$ pip3 install overleaf-sync
|
|
22
|
+
moritz@github:~/test$ pip3 install "overleaf-sync[gui]"
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
Depending on your local Python installation, you might need to use `pip` instead of `pip3`. [pipx](https://pipx.pypa.io/) works too: `pipx install "overleaf-sync[gui]"`.
|
|
26
|
+
|
|
27
|
+
> **2.0 pre-release:** Overleaf changed its website in a way that broke version 1.2.0. The fixes are available as a pre-release: `pip3 install --pre "overleaf-sync[gui]"`. Please report any problems in the [issues](https://github.com/moritzgloeckl/overleaf-sync/issues).
|
|
26
28
|
|
|
27
29
|
### Prerequisites
|
|
28
30
|
- Create your project on [Overleaf](https://www.overleaf.com/project), for example a project named `test`. Overleaf-sync is not able to create projects (yet).
|
|
@@ -37,7 +39,7 @@ moritz@github:~/test$ ols login [--path]
|
|
|
37
39
|
Login successful. Cookie persisted as `.olauth`. You may now sync your project.
|
|
38
40
|
```
|
|
39
41
|
|
|
40
|
-
Logging in will be handled by a mini web browser opening on your device (using
|
|
42
|
+
Logging in will be handled by a mini web browser opening on your device (using Qt via PySide6, from the `gui` extra). You can then enter your username and password securely on the official Overleaf website. You might get asked to solve a CAPTCHA in the process. Your credentials are sent to Overleaf over HTTPS.
|
|
41
43
|
|
|
42
44
|
It then stores your *cookie* (**not** your login credentials) in a hidden file called `.olauth` in the same folder you run the command from. It is possible to store the cookie elsewhere using the `--path` option. The cookie file will not be synced to or from Overleaf.
|
|
43
45
|
|
|
@@ -6,16 +6,24 @@
|
|
|
6
6
|
# Description: Overleaf API Wrapper
|
|
7
7
|
# Author: Moritz Glöckl
|
|
8
8
|
# License: MIT
|
|
9
|
-
# Version: 1.2.0
|
|
10
9
|
##################################################
|
|
11
10
|
|
|
12
11
|
import requests as reqs
|
|
13
12
|
from bs4 import BeautifulSoup
|
|
14
13
|
import json
|
|
14
|
+
import ssl
|
|
15
15
|
import uuid
|
|
16
|
+
import websocket
|
|
16
17
|
from socketIO_client import SocketIO
|
|
17
18
|
import time
|
|
18
19
|
|
|
20
|
+
# socketIO_client/transports.py has `except websocket.SSLError`, an attribute
|
|
21
|
+
# recent websocket-client (1.9.0+) no longer exposes; that raises AttributeError
|
|
22
|
+
# and masks whatever the actual connection error is. Keep this shim for as long
|
|
23
|
+
# as we depend on socketIO-client.
|
|
24
|
+
if not hasattr(websocket, "SSLError"):
|
|
25
|
+
websocket.SSLError = ssl.SSLError
|
|
26
|
+
|
|
19
27
|
# Where to get the CSRF Token and where to send the login request to
|
|
20
28
|
LOGIN_URL = "https://www.overleaf.com/login"
|
|
21
29
|
PROJECT_URL = "https://www.overleaf.com/project" # The dashboard URL
|
|
@@ -82,14 +90,32 @@ class OverleafClient(object):
|
|
|
82
90
|
|
|
83
91
|
return {"cookie": self._cookie, "csrf": self._csrf}
|
|
84
92
|
|
|
93
|
+
@staticmethod
|
|
94
|
+
def _extract_projects(page_content):
|
|
95
|
+
"""
|
|
96
|
+
Extract the project list from the Overleaf dashboard page.
|
|
97
|
+
|
|
98
|
+
Overleaf used to embed the list as a bare JSON array in a
|
|
99
|
+
<meta name="ol-projects"> tag. It now embeds
|
|
100
|
+
{"totalSize": N, "projects": [...]} in a
|
|
101
|
+
<meta name="ol-prefetchedProjectsBlob"> tag instead. Support both so
|
|
102
|
+
this keeps working if Overleaf reverts or if an older cookie/page is
|
|
103
|
+
cached somewhere.
|
|
104
|
+
"""
|
|
105
|
+
soup = BeautifulSoup(page_content, 'html.parser')
|
|
106
|
+
tag = soup.find('meta', {'name': 'ol-prefetchedProjectsBlob'}) or soup.find('meta', {'name': 'ol-projects'})
|
|
107
|
+
json_content = json.loads(tag.get('content'))
|
|
108
|
+
if isinstance(json_content, dict):
|
|
109
|
+
json_content = json_content.get('projects', [])
|
|
110
|
+
return json_content
|
|
111
|
+
|
|
85
112
|
def all_projects(self):
|
|
86
113
|
"""
|
|
87
114
|
Get all of a user's active projects (= not archived and not trashed)
|
|
88
115
|
Returns: List of project objects
|
|
89
116
|
"""
|
|
90
117
|
projects_page = reqs.get(PROJECT_URL, cookies=self._cookie)
|
|
91
|
-
json_content =
|
|
92
|
-
BeautifulSoup(projects_page.content, 'html.parser').find('meta', {'name': 'ol-projects'}).get('content'))
|
|
118
|
+
json_content = OverleafClient._extract_projects(projects_page.content)
|
|
93
119
|
return list(OverleafClient.filter_projects(json_content))
|
|
94
120
|
|
|
95
121
|
def get_project(self, project_name):
|
|
@@ -100,8 +126,7 @@ class OverleafClient(object):
|
|
|
100
126
|
"""
|
|
101
127
|
|
|
102
128
|
projects_page = reqs.get(PROJECT_URL, cookies=self._cookie)
|
|
103
|
-
json_content =
|
|
104
|
-
BeautifulSoup(projects_page.content, 'html.parser').find('meta', {'name': 'ol-projects'}).get('content'))
|
|
129
|
+
json_content = OverleafClient._extract_projects(projects_page.content)
|
|
105
130
|
return next(OverleafClient.filter_projects(json_content, {"name": project_name}), None)
|
|
106
131
|
|
|
107
132
|
def download_project(self, project_id):
|
|
@@ -138,8 +163,11 @@ class OverleafClient(object):
|
|
|
138
163
|
|
|
139
164
|
if r.ok:
|
|
140
165
|
return json.loads(r.content)
|
|
141
|
-
elif r.status_code ==
|
|
142
|
-
# Folder already exists
|
|
166
|
+
elif r.status_code == 400:
|
|
167
|
+
# Folder already exists. status_code is an int; comparing to
|
|
168
|
+
# str(400) was always False, so this branch never actually
|
|
169
|
+
# fired -- a real folder-exists response fell through to the
|
|
170
|
+
# HTTPError below instead of silently continuing.
|
|
143
171
|
return
|
|
144
172
|
else:
|
|
145
173
|
raise reqs.HTTPError()
|
|
@@ -155,23 +183,50 @@ class OverleafClient(object):
|
|
|
155
183
|
"""
|
|
156
184
|
project_infos = None
|
|
157
185
|
|
|
158
|
-
# Callback
|
|
159
|
-
|
|
160
|
-
|
|
186
|
+
# Callback for the joinProjectResponse event the server pushes right
|
|
187
|
+
# after a successful connect+auto-join (see below) -- delivered as a
|
|
188
|
+
# plain named event, not as an ack to an explicit emit, and shaped as
|
|
189
|
+
# {"publicId": ..., "project": {...}}. Downstream code (upload_file,
|
|
190
|
+
# delete_file) indexes project_infos['rootFolder'][0][...] directly,
|
|
191
|
+
# so unwrap to the inner "project" dict here rather than returning
|
|
192
|
+
# the wrapper.
|
|
193
|
+
def set_project_infos(data):
|
|
161
194
|
nonlocal project_infos
|
|
162
|
-
project_infos =
|
|
163
|
-
|
|
164
|
-
#
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
195
|
+
project_infos = data.get('project')
|
|
196
|
+
|
|
197
|
+
# The Socket.IO handshake below (done again internally by the SocketIO()
|
|
198
|
+
# constructor) has Overleaf issue a *fresh* load-balancer affinity cookie
|
|
199
|
+
# (currently named GCLB, see olbrowserlogin.COOKIE_NAMES and commit
|
|
200
|
+
# 0cc61e7) on its response -- but socketIO_client calls requests.get()
|
|
201
|
+
# directly rather than through a Session, so that Set-Cookie is silently
|
|
202
|
+
# dropped, and the WebSocket upgrade that follows then 502s without it.
|
|
203
|
+
# Perform the same handshake ourselves first, purely to capture that
|
|
204
|
+
# cookie, and merge it into the header used for the real connection.
|
|
205
|
+
# (Built from whatever cookies are present rather than hardcoded names:
|
|
206
|
+
# a session may not carry every cookie -- this previously raised
|
|
207
|
+
# KeyError here even though overleaf_session2 alone is enough to connect.)
|
|
208
|
+
handshake = reqs.get(
|
|
209
|
+
"{}/socket.io/1/".format(BASE_URL),
|
|
210
|
+
params={"t": int(time.time() * 1000)},
|
|
211
|
+
cookies=self._cookie,
|
|
212
|
+
)
|
|
213
|
+
cookie_dict = dict(self._cookie)
|
|
214
|
+
cookie_dict.update(handshake.cookies.get_dict())
|
|
215
|
+
cookie = "; ".join(
|
|
216
|
+
"{}={}".format(name, value) for name, value in cookie_dict.items()
|
|
169
217
|
)
|
|
170
218
|
|
|
171
|
-
#
|
|
219
|
+
# projectId must be a query parameter on THIS handshake -- the one
|
|
220
|
+
# socketIO_client performs internally when SocketIO() connects, not
|
|
221
|
+
# the pre-fetch above. Overleaf now binds the session to a project at
|
|
222
|
+
# handshake time and rejects the connection otherwise
|
|
223
|
+
# (connectionRejected: "missing/bad ?projectId=... query flag on
|
|
224
|
+
# handshake"); confirmed it rejects even when projectId is only on
|
|
225
|
+
# the WebSocket upgrade URL -- it must be on the initial
|
|
226
|
+
# /socket.io/1/ GET specifically.
|
|
172
227
|
socket_io = SocketIO(
|
|
173
228
|
BASE_URL,
|
|
174
|
-
params={'t': int(time.time())},
|
|
229
|
+
params={'t': int(time.time()), 'projectId': project_id},
|
|
175
230
|
headers={'Cookie': cookie}
|
|
176
231
|
)
|
|
177
232
|
|
|
@@ -179,9 +234,19 @@ class OverleafClient(object):
|
|
|
179
234
|
socket_io.on('connect', lambda: None)
|
|
180
235
|
socket_io.wait_for_callbacks()
|
|
181
236
|
|
|
182
|
-
#
|
|
183
|
-
|
|
184
|
-
|
|
237
|
+
# With projectId on the handshake, the server auto-joins and pushes
|
|
238
|
+
# the result as a joinProjectResponse event -- no explicit joinProject
|
|
239
|
+
# emit needed (confirmed live: the emit's ack callback never fires
|
|
240
|
+
# since the server responds with a named event, not an ack).
|
|
241
|
+
# wait_for_callbacks() only waits for a pending *ack* callback, which
|
|
242
|
+
# .on() never registers -- it would return immediately without
|
|
243
|
+
# reading anything. Wait in short slices instead, stopping as soon as
|
|
244
|
+
# the event has actually been processed.
|
|
245
|
+
socket_io.on('joinProjectResponse', set_project_infos)
|
|
246
|
+
for _ in range(20):
|
|
247
|
+
if project_infos is not None:
|
|
248
|
+
break
|
|
249
|
+
socket_io.wait(seconds=1)
|
|
185
250
|
|
|
186
251
|
# Disconnect from the socket if still connected
|
|
187
252
|
if socket_io.connected:
|
|
@@ -233,13 +298,26 @@ class OverleafClient(object):
|
|
|
233
298
|
"qqtotalfilesize": file_size,
|
|
234
299
|
}
|
|
235
300
|
files = {
|
|
301
|
+
# Overleaf's upload endpoint now rejects the request with 422
|
|
302
|
+
# {"success":false,"error":"invalid_filename"} unless the
|
|
303
|
+
# filename is also present as a plain multipart field, not just
|
|
304
|
+
# in qqfilename above. Confirmed live: identical request without
|
|
305
|
+
# this field gets 422; with it, 200 and the file is actually
|
|
306
|
+
# updated. It must be the bare file name: Overleaf rejects names
|
|
307
|
+
# containing "/" (SafePath), the folder is chosen via folder_id.
|
|
308
|
+
"name": (None, file_name.split(PATH_SEP)[-1]),
|
|
236
309
|
"qqfile": file
|
|
237
310
|
}
|
|
238
311
|
|
|
239
312
|
# Upload the file to the predefined folder
|
|
240
313
|
r = reqs.post(UPLOAD_URL.format(project_id), cookies=self._cookie, params=params, files=files)
|
|
241
314
|
|
|
242
|
-
|
|
315
|
+
# status_code is an int; comparing to str(200) was always False here,
|
|
316
|
+
# so this reported failure on every call regardless of the real
|
|
317
|
+
# result. Harmless today only because callers don't check the return
|
|
318
|
+
# value, but worth fixing since it's the only signal this method
|
|
319
|
+
# gives back.
|
|
320
|
+
return r.status_code == 200 and json.loads(r.content)["success"]
|
|
243
321
|
|
|
244
322
|
def delete_file(self, project_id, project_infos, file_name):
|
|
245
323
|
"""
|
|
@@ -280,7 +358,10 @@ class OverleafClient(object):
|
|
|
280
358
|
|
|
281
359
|
r = reqs.delete(DELETE_URL.format(project_id, file['_id']), cookies=self._cookie, headers=headers, json={})
|
|
282
360
|
|
|
283
|
-
|
|
361
|
+
# status_code is an int; comparing to str(204) was always False
|
|
362
|
+
# regardless of the real result, same bug class as upload_file and
|
|
363
|
+
# create_folder above.
|
|
364
|
+
return r.status_code == 204
|
|
284
365
|
|
|
285
366
|
def download_pdf(self, project_id):
|
|
286
367
|
"""
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
# Description: Overleaf Two-Way Sync
|
|
7
7
|
# Author: Moritz Glöckl
|
|
8
8
|
# License: MIT
|
|
9
|
-
# Version: 1.2.0
|
|
10
9
|
##################################################
|
|
11
10
|
|
|
12
11
|
import click
|
|
13
12
|
import os
|
|
13
|
+
import sys
|
|
14
14
|
from yaspin import yaspin
|
|
15
15
|
import pickle
|
|
16
16
|
import zipfile
|
|
@@ -24,11 +24,21 @@ from pathlib import Path
|
|
|
24
24
|
try:
|
|
25
25
|
# Import for pip installation / wheel
|
|
26
26
|
from olsync.olclient import OverleafClient
|
|
27
|
-
import olsync.olbrowserlogin as olbrowserlogin
|
|
28
27
|
except ImportError:
|
|
29
28
|
# Import for development
|
|
30
29
|
from olclient import OverleafClient
|
|
31
|
-
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def configure_console():
|
|
33
|
+
"""
|
|
34
|
+
Windows consoles often default to a legacy codepage (e.g. cp1252) that can't
|
|
35
|
+
encode the emoji/braille characters used for status output and the spinner,
|
|
36
|
+
which crashes stdout.write() with UnicodeEncodeError. Force UTF-8 output.
|
|
37
|
+
Done when the CLI starts rather than on import, so importing olsync has no side effects.
|
|
38
|
+
"""
|
|
39
|
+
for stream in (sys.stdout, sys.stderr):
|
|
40
|
+
if hasattr(stream, "reconfigure"):
|
|
41
|
+
stream.reconfigure(encoding="utf-8", errors="replace")
|
|
32
42
|
|
|
33
43
|
|
|
34
44
|
@click.group(invoke_without_command=True)
|
|
@@ -48,6 +58,7 @@ except ImportError:
|
|
|
48
58
|
@click.version_option(package_name='overleaf-sync')
|
|
49
59
|
@click.pass_context
|
|
50
60
|
def main(ctx, local, remote, project_name, cookie_path, sync_path, olignore_path, verbose):
|
|
61
|
+
configure_console()
|
|
51
62
|
if ctx.invoked_subcommand is None:
|
|
52
63
|
if not os.path.isfile(cookie_path):
|
|
53
64
|
raise click.ClickException(
|
|
@@ -126,8 +137,9 @@ def login(cookie_path, verbose):
|
|
|
126
137
|
if os.path.isfile(cookie_path) and not click.confirm(
|
|
127
138
|
'Persisted Overleaf cookie already exist. Do you want to override it?'):
|
|
128
139
|
return
|
|
140
|
+
olbrowserlogin = load_browser_login()
|
|
129
141
|
click.clear()
|
|
130
|
-
execute_action(lambda: login_handler(cookie_path), "Login",
|
|
142
|
+
execute_action(lambda: login_handler(olbrowserlogin, cookie_path), "Login",
|
|
131
143
|
"Login successful. Cookie persisted as `" + click.format_filename(
|
|
132
144
|
cookie_path) + "`. You may now sync your project.",
|
|
133
145
|
"Login failed. Please try again.", verbose)
|
|
@@ -203,7 +215,29 @@ def download_pdf(project_name, download_path, cookie_path, verbose):
|
|
|
203
215
|
"Downloading project's PDF failed. Please try again.", verbose)
|
|
204
216
|
|
|
205
217
|
|
|
206
|
-
def
|
|
218
|
+
def load_browser_login():
|
|
219
|
+
"""
|
|
220
|
+
Import the login window module. PySide6 is an optional dependency (the "gui" extra),
|
|
221
|
+
so it is only imported when logging in.
|
|
222
|
+
"""
|
|
223
|
+
try:
|
|
224
|
+
try:
|
|
225
|
+
# Import for pip installation / wheel
|
|
226
|
+
import olsync.olbrowserlogin as olbrowserlogin
|
|
227
|
+
except ImportError as e:
|
|
228
|
+
if (e.name or "").startswith("PySide6"):
|
|
229
|
+
raise
|
|
230
|
+
# Import for development
|
|
231
|
+
import olbrowserlogin
|
|
232
|
+
except ImportError as e:
|
|
233
|
+
if not (e.name or "").startswith("PySide6"):
|
|
234
|
+
raise
|
|
235
|
+
raise click.ClickException(
|
|
236
|
+
"The login window needs PySide6. Install it with: pip install \"overleaf-sync[gui]\"")
|
|
237
|
+
return olbrowserlogin
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def login_handler(olbrowserlogin, path):
|
|
207
241
|
store = olbrowserlogin.login()
|
|
208
242
|
if store is None:
|
|
209
243
|
return False
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["flit_core >=3.4,<4"]
|
|
3
|
+
build-backend = "flit_core.buildapi"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "overleaf-sync"
|
|
7
|
+
authors = [{ name = "Moritz Glöckl", email = "moritzgloeckl@users.noreply.github.com" }]
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
license = { file = "LICENSE" }
|
|
10
|
+
classifiers = [
|
|
11
|
+
"License :: OSI Approved :: MIT License",
|
|
12
|
+
"Intended Audience :: Science/Research",
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
]
|
|
15
|
+
keywords = ["overleaf", "sync", "latex", "tex"]
|
|
16
|
+
requires-python = ">=3.11"
|
|
17
|
+
dynamic = ["version", "description"]
|
|
18
|
+
dependencies = [
|
|
19
|
+
"requests >=2.31,<3",
|
|
20
|
+
"beautifulsoup4 >=4.12,<5",
|
|
21
|
+
"yaspin >=3,<4",
|
|
22
|
+
"python-dateutil >=2.8,<3",
|
|
23
|
+
"click >=8.1,<9",
|
|
24
|
+
"socketIO-client ==0.5.7.2", # Do not upgrade, see AGENTS.md
|
|
25
|
+
"websocket-client >=1,<2",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.optional-dependencies]
|
|
29
|
+
gui = ["PySide6 >=6.5,<7"]
|
|
30
|
+
dev = ["pytest >=8", "pytest-cov >=5", "responses >=0.25", "ruff >=0.6"]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://github.com/moritzgloeckl/overleaf-sync"
|
|
34
|
+
Issues = "https://github.com/moritzgloeckl/overleaf-sync/issues"
|
|
35
|
+
|
|
36
|
+
[project.scripts]
|
|
37
|
+
ols = "olsync.olsync:main"
|
|
38
|
+
overleaf-sync = "olsync.olsync:main"
|
|
39
|
+
|
|
40
|
+
[tool.flit.module]
|
|
41
|
+
name = "olsync"
|
|
42
|
+
|
|
43
|
+
[tool.pytest.ini_options]
|
|
44
|
+
testpaths = ["tests"]
|
|
45
|
+
addopts = "-m 'not integration and not smoke'"
|
|
46
|
+
filterwarnings = ["ignore:color, on_color and attrs are not supported:UserWarning:yaspin"]
|
|
47
|
+
markers = [
|
|
48
|
+
"integration: needs the Overleaf Community Edition container (tests/integration/compose.yml)",
|
|
49
|
+
"smoke: runs against overleaf.com with a real session, local only (see tests/smoke/)",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
[tool.ruff]
|
|
53
|
+
target-version = "py311"
|
|
54
|
+
line-length = 120
|
|
55
|
+
|
|
56
|
+
[tool.ruff.lint]
|
|
57
|
+
select = ["E9", "F"]
|
|
58
|
+
|
|
59
|
+
[tool.ruff.lint.per-file-ignores]
|
|
60
|
+
"olsync/olbrowserlogin.py" = ["F403", "F405"]
|
overleaf-sync-1.2.0/.gitignore
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
# Byte-compiled / optimized / DLL files
|
|
2
|
-
__pycache__/
|
|
3
|
-
*.py[cod]
|
|
4
|
-
*$py.class
|
|
5
|
-
|
|
6
|
-
# C extensions
|
|
7
|
-
*.so
|
|
8
|
-
|
|
9
|
-
# Distribution / packaging
|
|
10
|
-
.Python
|
|
11
|
-
build/
|
|
12
|
-
develop-eggs/
|
|
13
|
-
dist/
|
|
14
|
-
downloads/
|
|
15
|
-
eggs/
|
|
16
|
-
.eggs/
|
|
17
|
-
lib/
|
|
18
|
-
lib64/
|
|
19
|
-
parts/
|
|
20
|
-
sdist/
|
|
21
|
-
var/
|
|
22
|
-
wheels/
|
|
23
|
-
*.egg-info/
|
|
24
|
-
.installed.cfg
|
|
25
|
-
*.egg
|
|
26
|
-
MANIFEST
|
|
27
|
-
pip-wheel-metadata/
|
|
28
|
-
|
|
29
|
-
# PyInstaller
|
|
30
|
-
# Usually these files are written by a python script from a template
|
|
31
|
-
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
-
*.manifest
|
|
33
|
-
*.spec
|
|
34
|
-
|
|
35
|
-
# Installer logs
|
|
36
|
-
pip-log.txt
|
|
37
|
-
pip-delete-this-directory.txt
|
|
38
|
-
|
|
39
|
-
# Unit test / coverage reports
|
|
40
|
-
htmlcov/
|
|
41
|
-
.tox/
|
|
42
|
-
.coverage
|
|
43
|
-
.coverage.*
|
|
44
|
-
.cache
|
|
45
|
-
nosetests.xml
|
|
46
|
-
coverage.xml
|
|
47
|
-
*.cover
|
|
48
|
-
.hypothesis/
|
|
49
|
-
.pytest_cache/
|
|
50
|
-
|
|
51
|
-
# Translations
|
|
52
|
-
*.mo
|
|
53
|
-
*.pot
|
|
54
|
-
|
|
55
|
-
# Django stuff:
|
|
56
|
-
*.log
|
|
57
|
-
local_settings.py
|
|
58
|
-
db.sqlite3
|
|
59
|
-
|
|
60
|
-
# Flask stuff:
|
|
61
|
-
instance/
|
|
62
|
-
.webassets-cache
|
|
63
|
-
|
|
64
|
-
# Scrapy stuff:
|
|
65
|
-
.scrapy
|
|
66
|
-
|
|
67
|
-
# Sphinx documentation
|
|
68
|
-
docs/_build/
|
|
69
|
-
|
|
70
|
-
# PyBuilder
|
|
71
|
-
target/
|
|
72
|
-
|
|
73
|
-
# Jupyter Notebook
|
|
74
|
-
.ipynb_checkpoints
|
|
75
|
-
|
|
76
|
-
# pyenv
|
|
77
|
-
.python-version
|
|
78
|
-
|
|
79
|
-
# celery beat schedule file
|
|
80
|
-
celerybeat-schedule
|
|
81
|
-
|
|
82
|
-
# SageMath parsed files
|
|
83
|
-
*.sage.py
|
|
84
|
-
|
|
85
|
-
# Environments
|
|
86
|
-
.env
|
|
87
|
-
.venv
|
|
88
|
-
env/
|
|
89
|
-
venv/
|
|
90
|
-
ENV/
|
|
91
|
-
env.bak/
|
|
92
|
-
venv.bak/
|
|
93
|
-
|
|
94
|
-
# Spyder project settings
|
|
95
|
-
.spyderproject
|
|
96
|
-
.spyproject
|
|
97
|
-
|
|
98
|
-
# Rope project settings
|
|
99
|
-
.ropeproject
|
|
100
|
-
|
|
101
|
-
# mkdocs documentation
|
|
102
|
-
/site
|
|
103
|
-
|
|
104
|
-
# mypy
|
|
105
|
-
.mypy_cache/
|
|
106
|
-
|
|
107
|
-
#PyCharm
|
|
108
|
-
.idea/
|
|
109
|
-
|
|
110
|
-
# vscode
|
|
111
|
-
.vscode
|
|
112
|
-
.DS_Store
|
|
113
|
-
|
|
114
|
-
# dev testing
|
|
115
|
-
setup.py
|
|
116
|
-
test*
|
|
117
|
-
.olauth
|
|
118
|
-
.olignore
|
overleaf-sync-1.2.0/PKG-INFO
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
[build-system]
|
|
2
|
-
requires = ["flit"]
|
|
3
|
-
build-backend = "flit.buildapi"
|
|
4
|
-
|
|
5
|
-
[tool.flit.metadata]
|
|
6
|
-
module = "olsync"
|
|
7
|
-
dist-name = "overleaf-sync"
|
|
8
|
-
description-file = "README.md"
|
|
9
|
-
author = "Moritz Glöckl"
|
|
10
|
-
author-email = "moritzgloeckl@users.noreply.github.com"
|
|
11
|
-
home-page = "https://github.com/moritzgloeckl/overleaf-sync"
|
|
12
|
-
classifiers = ["License :: OSI Approved :: MIT License", "Intended Audience :: Science/Research", "Programming Language :: Python :: 3"]
|
|
13
|
-
requires-python = ">=3"
|
|
14
|
-
requires = [
|
|
15
|
-
"requests == 2.*",
|
|
16
|
-
"beautifulsoup4 == 4.11.1",
|
|
17
|
-
"yaspin == 2.*",
|
|
18
|
-
"python-dateutil~=2.8.1",
|
|
19
|
-
"click == 8.*",
|
|
20
|
-
"socketIO-client == 0.5.7.2",
|
|
21
|
-
"PySide6 == 6.*"
|
|
22
|
-
]
|
|
23
|
-
keywords = "overleaf sync latex tex"
|
|
24
|
-
|
|
25
|
-
[tool.flit.scripts]
|
|
26
|
-
ols = "olsync.olsync:main"
|
overleaf-sync-1.2.0/setup.py
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# setup.py generated by flit for tools that don't yet use PEP 517
|
|
3
|
-
|
|
4
|
-
from distutils.core import setup
|
|
5
|
-
|
|
6
|
-
packages = \
|
|
7
|
-
['olsync']
|
|
8
|
-
|
|
9
|
-
package_data = \
|
|
10
|
-
{'': ['*']}
|
|
11
|
-
|
|
12
|
-
install_requires = \
|
|
13
|
-
['requests == 2.*',
|
|
14
|
-
'beautifulsoup4 == 4.11.1',
|
|
15
|
-
'yaspin == 2.*',
|
|
16
|
-
'python-dateutil~=2.8.1',
|
|
17
|
-
'click == 8.*',
|
|
18
|
-
'socketIO-client == 0.5.7.2',
|
|
19
|
-
'PySide6 == 6.*']
|
|
20
|
-
|
|
21
|
-
entry_points = \
|
|
22
|
-
{'console_scripts': ['ols = olsync.olsync:main']}
|
|
23
|
-
|
|
24
|
-
setup(name='overleaf-sync',
|
|
25
|
-
version='1.2.0',
|
|
26
|
-
description='Overleaf Two-Way Sync Tool',
|
|
27
|
-
author='Moritz Glöckl',
|
|
28
|
-
author_email='moritzgloeckl@users.noreply.github.com',
|
|
29
|
-
url='https://github.com/moritzgloeckl/overleaf-sync',
|
|
30
|
-
packages=packages,
|
|
31
|
-
package_data=package_data,
|
|
32
|
-
install_requires=install_requires,
|
|
33
|
-
entry_points=entry_points,
|
|
34
|
-
python_requires='>=3',
|
|
35
|
-
)
|
|
File without changes
|