def sync_project(self, project_pk, sync_log_pk, no_pull=False, no_commit=False, force=False): """Fetch the project with the given PK and perform sync on it.""" db_project = get_or_fail( Project, pk=project_pk, message='Could not sync project with pk={0}, not found.'.format( project_pk)) sync_log = get_or_fail( SyncLog, pk=sync_log_pk, message=( 'Could not sync project {0}, log with pk={1} not found.'.format( db_project.slug, sync_log_pk))) log.info('Syncing project {0}.'.format(db_project.slug)) # Mark "now" at the start of sync to avoid messing with # translations submitted during sync. now = timezone.now() project_sync_log = ProjectSyncLog.objects.create(sync_log=sync_log, project=db_project, start_time=now) if not no_pull: repos_changed = pull_changes(db_project) else: repos_changed = True # Assume changed. # If the repos haven't changed since the last sync and there are # no Pontoon-side changes for this project, quit early. if not force and not repos_changed and not db_project.needs_sync: log.info('Skipping project {0}, no changes detected.'.format( db_project.slug)) project_sync_log.skipped = True project_sync_log.skipped_end_time = timezone.now() project_sync_log.save(update_fields=('skipped', 'skipped_end_time')) return perform_sync_project(db_project, now) for repo in db_project.repositories.all(): sync_project_repo.delay(project_pk, repo.pk, project_sync_log.pk, now, no_pull=no_pull, no_commit=no_commit) log.info('Synced resources for project {0}.'.format(db_project.slug))
def sync_project(self, project_pk, sync_log_pk, no_pull=False, no_commit=False, force=False): """Fetch the project with the given PK and perform sync on it.""" db_project = get_or_fail(Project, pk=project_pk, message='Could not sync project with pk={0}, not found.'.format(project_pk)) sync_log = get_or_fail(SyncLog, pk=sync_log_pk, message=('Could not sync project {0}, log with pk={1} not found.' .format(db_project.slug, sync_log_pk))) log.info('Syncing project {0}.'.format(db_project.slug)) # Mark "now" at the start of sync to avoid messing with # translations submitted during sync. now = timezone.now() project_sync_log = ProjectSyncLog.objects.create( sync_log=sync_log, project=db_project, start_time=now ) if not no_pull: repos_changed = pull_changes(db_project) else: repos_changed = True # Assume changed. # If the repos haven't changed since the last sync and there are # no Pontoon-side changes for this project, quit early. if not force and not repos_changed and not db_project.needs_sync: log.info('Skipping project {0}, no changes detected.'.format(db_project.slug)) project_sync_log.skipped = True project_sync_log.skipped_end_time = timezone.now() project_sync_log.save(update_fields=('skipped', 'skipped_end_time')) return perform_sync_project(db_project, now) for repo in db_project.repositories.all(): sync_project_repo.delay( project_pk, repo.pk, project_sync_log.pk, now, no_pull=no_pull, no_commit=no_commit ) log.info('Synced resources for project {0}.'.format(db_project.slug))
def sync_project(self, project_pk, sync_log_pk, no_pull=False, no_commit=False, force=False): """Fetch the project with the given PK and perform sync on it.""" db_project = get_or_fail(Project, pk=project_pk, message='Could not sync project with pk={0}, not found.'.format(project_pk)) sync_log = get_or_fail(SyncLog, pk=sync_log_pk, message=('Could not sync project {0}, log with pk={1} not found.' .format(db_project.slug, sync_log_pk))) log.info('Syncing project {0}.'.format(db_project.slug)) # Mark "now" at the start of sync to avoid messing with # translations submitted during sync. now = timezone.now() project_sync_log = ProjectSyncLog.objects.create( sync_log=sync_log, project=db_project, start_time=now ) if not no_pull: repos_changed = pull_changes(db_project) else: repos_changed = True # Assume changed. # If the repos haven't changed since the last sync and there are # no Pontoon-side changes for this project, quit early. if not force and not repos_changed and not db_project.needs_sync: log.info('Skipping project {0}, no changes detected.'.format(db_project.slug)) project_sync_log.skip() return try: obsolete_vcs_entities, obsolete_vcs_resources = perform_sync_project(db_project, now) except MissingSourceDirectoryError, e: log.error(e) project_sync_log.skip() return
def sync_project(self, project_pk, sync_log_pk, locale=None, no_pull=False, no_commit=False, force=False): """Fetch the project with the given PK and perform sync on it.""" db_project = get_or_fail(Project, pk=project_pk, message='Could not sync project with pk={0}, not found.'.format(project_pk)) sync_log = get_or_fail(SyncLog, pk=sync_log_pk, message=('Could not sync project {0}, log with pk={1} not found.' .format(db_project.slug, sync_log_pk))) log.info('Syncing project {0}.'.format(db_project.slug)) # Mark "now" at the start of sync to avoid messing with # translations submitted during sync. now = timezone.now() project_sync_log = ProjectSyncLog.objects.create( sync_log=sync_log, project=db_project, start_time=now ) # We have to cache changed files before last revision is overriden by pull if no_pull: repos_changed = True # Assume changed. else: repos_changed, _ = pull_changes(db_project) # If the repos haven't changed since the last sync and there are # no Pontoon-side changes for this project, quit early. if not force and not repos_changed and not db_project.needs_sync: log.info('Skipping project {0}, no changes detected.'.format(db_project.slug)) project_sync_log.skip() return # Do not sync resources if locale specified if locale: repo = locale.get_repository(db_project) if repo: sync_project_repo.delay( project_pk, repo.pk, project_sync_log.pk, now, locale=locale, no_pull=no_pull, no_commit=no_commit, full_scan=force ) else: try: obsolete_vcs_entities, obsolete_vcs_resources = perform_sync_project(db_project, now, full_scan=force) except MissingSourceDirectoryError, e: log.error(e) project_sync_log.skip() return log.info('Synced resources for project {0}.'.format(db_project.slug)) # No need to sync translations if it's a source repository for repo in db_project.repositories.exclude(source_repo=True): sync_project_repo.delay( project_pk, repo.pk, project_sync_log.pk, now, obsolete_vcs_entities, obsolete_vcs_resources, no_pull=no_pull, no_commit=no_commit, full_scan=force ) for repo in db_project.repositories.filter(source_repo=True): repo.set_current_last_synced_revisions()
def sync_project(self, project_pk, sync_log_pk, locale=None, no_pull=False, no_commit=False, force=False): """Fetch the project with the given PK and perform sync on it.""" db_project = get_or_fail( Project, pk=project_pk, message='Could not sync project with pk={0}, not found.'.format( project_pk)) sync_log = get_or_fail( SyncLog, pk=sync_log_pk, message=( 'Could not sync project {0}, log with pk={1} not found.'.format( db_project.slug, sync_log_pk))) log.info('Syncing project {0}.'.format(db_project.slug)) # Mark "now" at the start of sync to avoid messing with # translations submitted during sync. now = timezone.now() project_sync_log = ProjectSyncLog.objects.create(sync_log=sync_log, project=db_project, start_time=now) # We have to cache changed files before last revision is overriden by pull if no_pull: repos_changed = True # Assume changed. else: repos_changed, _ = pull_changes(db_project) # If the repos haven't changed since the last sync and there are # no Pontoon-side changes for this project, quit early. if not force and not repos_changed and not db_project.needs_sync: log.info('Skipping project {0}, no changes detected.'.format( db_project.slug)) project_sync_log.skip() return # Do not sync resources if locale specified if locale: repo = locale.get_repository(db_project) if repo: sync_project_repo.delay(project_pk, repo.pk, project_sync_log.pk, now, locale=locale, no_pull=no_pull, no_commit=no_commit, full_scan=force) else: try: obsolete_vcs_entities, obsolete_vcs_resources, new_paths = perform_sync_project( db_project, now, full_scan=force) except MissingSourceDirectoryError, e: log.error(e) project_sync_log.skip() return log.info('Synced resources for project {0}.'.format(db_project.slug)) # No need to sync translations if it's a source repository for repo in db_project.repositories.exclude(source_repo=True): sync_project_repo.delay(project_pk, repo.pk, project_sync_log.pk, now, obsolete_vcs_entities, obsolete_vcs_resources, new_paths, no_pull=no_pull, no_commit=no_commit, full_scan=force) for repo in db_project.repositories.filter(source_repo=True): repo.set_current_last_synced_revisions()