@@ -66,8 +66,9 @@ def __get_changes(self, update = False): # -1 for need download, 1 for need uplo
66
66
if self .ls .lastUpdate < eNote [1 ]:
67
67
r .append ((nbName + '/' + lNote [0 ], - 1 ))
68
68
else :
69
+ pass
69
70
# debug
70
- r .append ((nbName + '/' + lNote [0 ], 2 ))
71
+ # r.append((nbName+'/'+lNote[0], 2))
71
72
delIndex .append (i )
72
73
break
73
74
else : # note exists locally not online
@@ -91,14 +92,14 @@ def _download_note(noteFullPath):
91
92
return
92
93
contentDict = self .ec .get_attachment (noteFullPath )
93
94
if contentDict .get (noteFullPath .split ('/' )[1 ]+ '.md' ) is None :
94
- if contentDict .get (noteFullPath .split ('/' )[1 ]+ '.txt ' ) is None :
95
- contentDict [noteFullPath .split ('/' )[1 ]+ '.txt ' ] = self .ec .get_content (noteFullPath )
95
+ if contentDict .get (noteFullPath .split ('/' )[1 ]+ '.html ' ) is None :
96
+ contentDict [noteFullPath .split ('/' )[1 ]+ '.html ' ] = self .ec .get_content (noteFullPath )
96
97
else : # avoid mistaken overwrite of attachment
97
98
fileNum = 1
98
99
while 1 :
99
- if contentDict .get (noteFullPath .split ('/' )[1 ]+ '(%s).txt ' % fileNum ) is None :
100
- contentDict [noteFullPath .split ('/' )[1 ]+ '(%s).txt ' % fileNum ] = contentDict [noteFullPath .split ('/' )[1 ]+ '.txt ' ]
101
- contentDict [noteFullPath .split ('/' )[1 ]+ '.txt ' ] = self .ec .get_content (noteFullPath )
100
+ if contentDict .get (noteFullPath .split ('/' )[1 ]+ '(%s).html ' % fileNum ) is None :
101
+ contentDict [noteFullPath .split ('/' )[1 ]+ '(%s).html ' % fileNum ] = contentDict [noteFullPath .split ('/' )[1 ]+ '.html ' ]
102
+ contentDict [noteFullPath .split ('/' )[1 ]+ '.html ' ] = self .ec .get_content (noteFullPath )
102
103
break
103
104
else :
104
105
fileNum += 1
@@ -116,7 +117,7 @@ def _download_note(noteFullPath):
116
117
for note in notes : _download_note (noteFullPath + '/' + note [0 ])
117
118
self .ls .update_config (lastUpdate = time .time ())
118
119
return True
119
- def upload_file (self , update = True ):
120
+ def upload_files (self , update = True ):
120
121
if not self .available : return False
121
122
def encode_content (content ):
122
123
try :
@@ -125,52 +126,34 @@ def encode_content(content):
125
126
try :
126
127
content = content .decode (chardet .detect (content )).encode ('utf8' )
127
128
except :
128
- # DEBUG
129
- print ('Encode failed' )
130
129
content = 'Upload encode failed, I\' m sorry! Please contact [email protected] with this file.'
131
130
return content
132
- def _upload_file (noteFullPath , attachmentDict ):
131
+ def _upload_files (noteFullPath , attachmentDict ):
133
132
nbName , nName = noteFullPath .split ('/' )
134
133
if not attachmentDict :
135
134
self .ec .delete_note (noteFullPath )
136
135
elif nName + '.md' in attachmentDict .keys ():
137
136
content = encode_content (attachmentDict [nName + '.md' ])
138
137
self .ec .update_note (noteFullPath , markdown (content ), attachmentDict )
139
- elif nName + '.txt ' in attachmentDict .keys ():
140
- content = encode_content (attachmentDict [nName + '.txt ' ])
141
- del attachmentDict [nName + '.txt ' ]
138
+ elif nName + '.html ' in attachmentDict .keys ():
139
+ content = encode_content (attachmentDict [nName + '.html ' ])
140
+ del attachmentDict [nName + '.html ' ]
142
141
self .ec .update_note (noteFullPath , content , attachmentDict )
143
142
for noteFullPath , status in self .__get_changes (update ):
144
143
if status not in (1 , 0 ): continue
145
144
if '/' in noteFullPath :
146
145
attachmentDict = self .ls .read_note (noteFullPath )
147
- _upload_file (noteFullPath , attachmentDict )
146
+ _upload_files (noteFullPath , attachmentDict )
148
147
else :
149
- if os .path .exists (noteFullPath ):
148
+ lns = self .ls .get_file_dict ().get (noteFullPath )
149
+ ens = self .es .get_note_dict ().get (noteFullPath )
150
+ if lns is None :
151
+ for note in ens or []: self .ec .delete_note (noteFullPath + '/' + note [0 ])
152
+ self .ec .delete_notebook (noteFullPath )
153
+ else :
150
154
self .ec .create_notebook (noteFullPath )
151
- for note in self . ls . get_file_dict ()[ noteFullPath ] :
155
+ for note in lns :
152
156
attachmentDict = self .ls .read_note (noteFullPath + '/' + note [0 ])
153
- _upload_file (noteFullPath + '/' + note [0 ], attachmentDict )
154
- else :
155
- self .ec .delete_notebook (noteFullPath )
157
+ _upload_files (noteFullPath + '/' + note [0 ], attachmentDict )
156
158
self .__get_changes (update = True )
157
159
return True
158
-
159
- def __check_file (self , noteName , notebookName , note ):
160
- # -1 for need download, 1 for need upload, 0 for can be uploaded and downloaded, 2 for updated
161
- if os .path .exists (self .__str_c2l (os .path .join (notebookName , noteName + '.md' ))):
162
- fileDir = self .__str_c2l (os .path .join (notebookName , noteName + '.md' ))
163
- elif os .path .exists (os .path .join (notebookName , noteName + '.txt' )):
164
- fileDir = self .__str_c2l (os .path .join (notebookName , noteName + '.txt' ))
165
- else :
166
- return - 1
167
- if self .lastUpdate < note .updated / 1000 :
168
- if self .lastUpdate < os .stat (fileDir ).st_mtime :
169
- return 0
170
- else :
171
- return - 1
172
- else :
173
- if self .lastUpdate < os .stat (fileDir ).st_mtime :
174
- return 1
175
- else :
176
- return 2
0 commit comments