Notes: does not synchronize sub-directory of doc-dir.
(sourceforge_project, doc_dir,
user=None, sftp='sftp')
| 200 | return stdout |
| 201 | |
| 202 | def 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, """ |
| 208 | cd htdocs |
| 209 | dir |
| 210 | exit |
| 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 |
| 232 | rm %s |
| 233 | exit""" % ' '.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 |
| 245 | lcd %s |
| 246 | mput %s |
| 247 | exit""" % (doc_dir, ' '.join(paths)), retry=3) |
| 248 | |
| 249 | def sourceforge_release_tarball(sourceforge_project, paths, user=None, sftp='sftp'): |
| 250 | userhost = '%s,%s@frs.sourceforge.net' % (user, sourceforge_project) |
no test coverage detected