snose

Check-in [1fe8adea90]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:More Python 3 and 2 compatibility - UTF-8 write files

I suspect I didn't get everything quite as good as I could in simplenote.py I
wish Python 2 would go away - it's so messy trying to do both.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | master
Files: files | file ages | folders
SHA3-256: 1fe8adea90b267cb1e5884352f44fdbc626f68b9e7edb9b82a7fbee1b0670b62
User & Date: simon 2018-10-13 10:40:20
Context
2018-10-13
10:57
I give in - switch to spaces instead of tabs check-in: 5dee798315 user: simon tags: trunk, master
10:40
More Python 3 and 2 compatibility - UTF-8 write files

I suspect I didn't get everything quite as good as I could in simplenote.py I
wish Python 2 would go away - it's so messy trying to do both. check-in: 1fe8adea90 user: simon tags: trunk, master

2018-10-11
10:25
Add ability to determine filename from first few lines of a file

Wanted to do this for awhile, but was too lazy until now.

Most of my snose files have the filepath as the first or second line in the
file (in a comment). This makes it easier to sneeze files out. check-in: ba8e456fb6 user: simon tags: trunk, master

Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to snose.py.

145
146
147
148
149
150
151

152



153
154
155
156
157
158
159
160
...
196
197
198
199
200
201
202

203



204
205
206
207
208
209
210
211
...
284
285
286
287
288
289
290

291



292
293
294
295
296
297
298
299
...
314
315
316
317
318
319
320

321



322
323
324
325
326
327
328
329
				except AttributeError:
					pass
			if filename is None:
				print("Failed to identify filename within note, please provide on command line")
				exit
		filename = os.path.expanduser(filename)
		try:

			with open(filename, 'w') as f:



				f.write(remote[0]['content'])
		except IOError as e:
			print("Failed to create local copy of that note")
			print(e)
		else:
			#Update index
			try:
				snose[filename] = {'key': remote[0]['key'], 'version': remote[0]['version'], 'modifydate': float(os.path.getmtime(filename)) } #Need to set as local modified date as otherwise will want to sync it straight away.
................................................................................
			remote = snclient.get_note(key)
			rollback = snclient.get_note(key, remote[0]['version']-1)
		except IOError as e:
			print("Failed to fetch previous version")
		else:
			try: 
				#3) Write it out locally

				with open(filename, 'w') as f:



					f.write(rollback[0]['content'])
				print("Rolled back local copy")
			except IOError as e:
				print("Failed to rollback local copy of that note")
				print(e)
			else:
				#Since rollback doesn't include full meta data, update remote accordingly
				try:
................................................................................
						else:
							#Get returned metadata
							snose[name]['version'] = returned[0]['version']
							snose[name]['modifydate'] = sysmodifydate #Use local value to avoid differences in accuracy (decimal places. etc) between local and remote timestamps
							#Update local file if merged content
							if 'content' in returned[0]:
								try:

									with open(name, 'w') as f:



										f.write(returned[0]['content'])
									print("Merged local content for %s" % name)
									#Override the returned value? As otherwise next sync will immediately update the remote version for no reason.
									snose[name]['modifydate'] = os.path.getmtime(name) 
								except IOError as e:
									print("Failed to merge content locally for %s" % name)
									print("Therefore skipping updating the index for this note")#I think this is a good idea?
							#Update the index file
................................................................................
			except IOError as e:
				print("Failed to fetch remote copy of note %s" % name)
				print("Skipping synchronisation for this file")
			else:
				if remote[0]['version'] > local['version']:
					if not dry:
						try: 

							with open(name, 'w') as f:



								f.write(remote[0]['content'])
							print("Updated local version of %s" % name)
						except IOError as e:
							print("Failed to update local note %s with remote content" % name)
							print("Will not updatet the .snose index file for this file")
						else:
							#Also update .snose index
							snose[name]['version'] = remote[0]['version']







>
|
>
>
>
|







 







>
|
>
>
>
|







 







>
|
>
>
>
|







 







>
|
>
>
>
|







145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
...
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
...
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
...
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
				except AttributeError:
					pass
			if filename is None:
				print("Failed to identify filename within note, please provide on command line")
				exit
		filename = os.path.expanduser(filename)
		try:
			if sys.version_info < (3, 0):
				with open(filename, 'w') as f:
					f.write(remote[0]['content'].encode("utf-8"))
			else:
				with open(filename, 'w', encoding="utf-8") as f:
					f.write(remote[0]['content'])
		except IOError as e:
			print("Failed to create local copy of that note")
			print(e)
		else:
			#Update index
			try:
				snose[filename] = {'key': remote[0]['key'], 'version': remote[0]['version'], 'modifydate': float(os.path.getmtime(filename)) } #Need to set as local modified date as otherwise will want to sync it straight away.
................................................................................
			remote = snclient.get_note(key)
			rollback = snclient.get_note(key, remote[0]['version']-1)
		except IOError as e:
			print("Failed to fetch previous version")
		else:
			try: 
				#3) Write it out locally
				if sys.version_info < (3, 0):
					with open(filename, 'w') as f:
						f.write(rollback[0]['content'].encode("utf-8"))
				else:
					with open(filename, 'w', encoding="utf-8") as f:
						f.write(rollback[0]['content'])
				print("Rolled back local copy")
			except IOError as e:
				print("Failed to rollback local copy of that note")
				print(e)
			else:
				#Since rollback doesn't include full meta data, update remote accordingly
				try:
................................................................................
						else:
							#Get returned metadata
							snose[name]['version'] = returned[0]['version']
							snose[name]['modifydate'] = sysmodifydate #Use local value to avoid differences in accuracy (decimal places. etc) between local and remote timestamps
							#Update local file if merged content
							if 'content' in returned[0]:
								try:
									if sys.version_info < (3, 0):
										with open(filename, 'w') as f:
											f.write(returned[0]['content'].encode("utf-8"))
									else:
										with open(filename, 'w', encoding="utf-8") as f:
											f.write(returned[0]['content'])
									print("Merged local content for %s" % name)
									#Override the returned value? As otherwise next sync will immediately update the remote version for no reason.
									snose[name]['modifydate'] = os.path.getmtime(name) 
								except IOError as e:
									print("Failed to merge content locally for %s" % name)
									print("Therefore skipping updating the index for this note")#I think this is a good idea?
							#Update the index file
................................................................................
			except IOError as e:
				print("Failed to fetch remote copy of note %s" % name)
				print("Skipping synchronisation for this file")
			else:
				if remote[0]['version'] > local['version']:
					if not dry:
						try: 
							if sys.version_info < (3, 0):
								with open(name, 'w') as f:
									f.write(remote[0]['content'].encode("utf-8"))
							else:
								with open(filename, 'w', encoding="utf-8") as f:
									f.write(remote[0]['content'])
							print("Updated local version of %s" % name)
						except IOError as e:
							print("Failed to update local note %s with remote content" % name)
							print("Will not updatet the .snose index file for this file")
						else:
							#Also update .snose index
							snose[name]['version'] = remote[0]['version']