MCPcopy Create free account
hub / github.com/SOUI2/soui / sourceforge_web_synchro

Function sourceforge_web_synchro

third-part/jsoncpp/makerelease.py:202–247  ·  view source on GitHub ↗

Notes: does not synchronize sub-directory of doc-dir.

(sourceforge_project, doc_dir,
                             user=None, sftp='sftp')

Source from the content-addressed store, hash-verified

200 return stdout
201
202def sourceforge_web_synchro(sourceforge_project, doc_dir,
203 user=None, sftp='sftp'):
204 """Notes: does not synchronize sub-directory of doc-dir.
205 """
206 userhost = '%s,%s@web.sourceforge.net' % (user, sourceforge_project)
207 stdout = run_sftp_batch(userhost, sftp, """
208cd htdocs
209dir
210exit
211""")
212 existing_paths = set()
213 collect = 0
214 for line in stdout.split('\n'):
215 line = line.strip()
216 if not collect and line.endswith('> dir'):
217 collect = True
218 elif collect and line.endswith('> exit'):
219 break
220 elif collect == 1:
221 collect = 2
222 elif collect == 2:
223 path = line.strip().split()[-1:]
224 if path and path[0] not in ('.', '..'):
225 existing_paths.add(path[0])
226 upload_paths = set([os.path.basename(p) for p in antglob.glob(doc_dir)])
227 paths_to_remove = existing_paths - upload_paths
228 if paths_to_remove:
229 print('Removing the following file from web:')
230 print('\n'.join(paths_to_remove))
231 stdout = run_sftp_batch(userhost, sftp, """cd htdocs
232rm %s
233exit""" % ' '.join(paths_to_remove))
234 print('Uploading %d files:' % len(upload_paths))
235 batch_size = 10
236 upload_paths = list(upload_paths)
237 start_time = time.time()
238 for index in range(0,len(upload_paths),batch_size):
239 paths = upload_paths[index:index+batch_size]
240 file_per_sec = (time.time() - start_time) / (index+1)
241 remaining_files = len(upload_paths) - index
242 remaining_sec = file_per_sec * remaining_files
243 print('%d/%d, ETA=%.1fs' % (index+1, len(upload_paths), remaining_sec))
244 run_sftp_batch(userhost, sftp, """cd htdocs
245lcd %s
246mput %s
247exit""" % (doc_dir, ' '.join(paths)), retry=3)
248
249def sourceforge_release_tarball(sourceforge_project, paths, user=None, sftp='sftp'):
250 userhost = '%s,%s@frs.sourceforge.net' % (user, sourceforge_project)

Callers 1

mainFunction · 0.85

Calls 4

run_sftp_batchFunction · 0.85
setFunction · 0.50
addMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected