def handle_project(self, db_project): # Pull changes from VCS and update what we know about the files. if not self.no_pull: update_from_repository(db_project) vcs_project = VCSProject(db_project) self.update_resources(db_project, vcs_project) # Collect all entities across VCS and the database and get their # keys so we can match up matching entities. vcs_entities = self.get_vcs_entities(vcs_project) db_entities = self.get_db_entities(db_project) entity_keys = set().union(db_entities.keys(), vcs_entities.keys()) changeset = ChangeSet(db_project, vcs_project) for key in entity_keys: db_entity = db_entities.get(key, None) vcs_entity = vcs_entities.get(key, None) self.handle_entity(changeset, db_project, key, db_entity, vcs_entity) # Apply the changeset to the files, commit them, and update stats # entries in the DB. changeset.execute() if not self.no_commit: self.commit_changes(db_project, vcs_project, changeset) self.update_stats(db_project, vcs_project, changeset) # Clear out the list of changed locales for entity in this # project now that we've finished syncing. (ChangedEntityLocale.objects.filter( entity__resource__project=db_project).delete()) self.log(u'Synced project {0}', db_project.slug)
def handle_project(self, db_project): if not db_project.can_commit: self.log("Skipping project {0}, cannot commit to repository.".format(db_project.name)) return # Pull changes from VCS and update what we know about the files. update_from_repository(db_project) vcs_project = VCSProject(db_project) self.update_resources(db_project, vcs_project) # Collect all entities across VCS and the database and get their # keys so we can match up matching entities. vcs_entities = self.get_vcs_entities(vcs_project) db_entities = self.get_db_entities(db_project) entity_keys = set().union(db_entities.keys(), vcs_entities.keys()) changeset = ChangeSet(db_project, vcs_project) for key in entity_keys: db_entity = db_entities.get(key, None) vcs_entity = vcs_entities.get(key, None) self.handle_entity(changeset, db_project, key, db_entity, vcs_entity) # Apply the changeset to the files and then commit them. changeset.execute() self.commit_changes(db_project, changeset) # Once we've successfully committed, update the last_synced date. db_project.last_synced = timezone.now() db_project.save() self.log("Synced project {0}", db_project.slug)
def handle_project(self, db_project): # Pull changes from VCS and update what we know about the files. if not self.no_pull: update_from_repository(db_project) vcs_project = VCSProject(db_project) self.update_resources(db_project, vcs_project) # Collect all entities across VCS and the database and get their # keys so we can match up matching entities. vcs_entities = self.get_vcs_entities(vcs_project) db_entities = self.get_db_entities(db_project) entity_keys = set().union(db_entities.keys(), vcs_entities.keys()) changeset = ChangeSet(db_project, vcs_project) for key in entity_keys: db_entity = db_entities.get(key, None) vcs_entity = vcs_entities.get(key, None) self.handle_entity(changeset, db_project, key, db_entity, vcs_entity) # Apply the changeset to the files, commit them, and update stats # entries in the DB. changeset.execute() if not self.no_commit: self.commit_changes(db_project, vcs_project, changeset) self.update_stats(db_project, vcs_project, changeset) # Clear out the list of changed locales for entity in this # project now that we've finished syncing. (ChangedEntityLocale.objects.filter(entity__resource__project=db_project).delete()) self.log(u"Synced project {0}", db_project.slug)
def update_from_repository(request, template=None): """Update all project locales from repository.""" log.debug("Update all project locales from repository.") if not request.user.has_perm('base.can_manage'): return render(request, '403.html', status=403) if request.method != 'POST': log.error("Non-POST request") raise Http404 try: pk = request.POST['pk'] except MultiValueDictKeyError as e: log.error(str(e)) return HttpResponse(json.dumps({ 'type': 'error', 'message': 'Project primary key not provided.', }), mimetype='application/json') try: project = Project.objects.get(pk=pk) except Project.DoesNotExist as e: log.error(str(e)) return HttpResponse(json.dumps({ 'type': 'error', 'message': str(e), }), mimetype='application/json') try: files.update_from_repository(project) files.extract_to_database(project) except Exception as e: log.error("Exception: " + str(e)) log.debug(traceback.format_exc()) return HttpResponse(json.dumps({ 'type': 'error', 'message': str(e), }), mimetype='application/json') except IOError as e: log.error("IOError: " + str(e)) log.debug(traceback.format_exc()) return HttpResponse(json.dumps({ 'type': 'error', 'message': str(e), }), mimetype='application/json') return HttpResponse("200")
def update_from_repository(request, template=None): """Update all project locales from repository.""" log.debug("Update all project locales from repository.") if not request.user.has_perm('base.can_manage'): return render(request, '403.html', status=403) if request.method != 'POST': log.error("Non-POST request") raise Http404 try: pk = request.POST['pk'] except MultiValueDictKeyError as e: log.error(str(e)) return HttpResponse(json.dumps({ 'type': 'error', 'message': 'Project primary key not provided.', }), content_type='application/json') try: project = Project.objects.get(pk=pk) except Project.DoesNotExist as e: log.error(str(e)) return HttpResponse(json.dumps({ 'type': 'error', 'message': str(e), }), content_type='application/json') try: files.update_from_repository(project) files.extract_to_database(project) except Exception as e: log.error("Exception: " + str(e)) log.debug(traceback.format_exc()) return HttpResponse(json.dumps({ 'type': 'error', 'message': str(e), }), content_type='application/json') except IOError as e: log.error("IOError: " + str(e)) log.debug(traceback.format_exc()) return HttpResponse(json.dumps({ 'type': 'error', 'message': str(e), }), content_type='application/json') return HttpResponse("200")
def handle(self, *args, **options): def output(text): self.stdout.write(text.encode('utf8') + u'\n') output('UPDATE PROJECTS: start') projects = Project.objects.filter(disabled=False) if args: projects = projects.filter(pk__in=args) for project in projects: try: update_from_repository(project) extract_to_database(project) output('Updated project %s' % project) except Exception as e: raise CommandError(u'Update error: %s\n' % unicode(e)) output('UPDATE PROJECTS: done')
def handle(self, *args, **options): def output(text): now = datetime.datetime.now() self.stdout.write('[%s]: %s\n' % (now, text.encode('utf8'))) output('UPDATE PROJECTS: start') projects = Project.objects.all() if args: projects = projects.filter(pk__in=args) for project in projects: try: update_from_repository(project) extract_to_database(project) output('Updated project %s' % project) except Exception as e: now = datetime.datetime.now() raise CommandError( '[%s]: Update error: %s\n' % (now, unicode(e))) output('UPDATE PROJECTS: done')
def handle(self, *args, **options): def output(text): self.stdout.write(text + u'\n') output('COMMIT PROJECTS: start') projects = Project.objects.filter(disabled=False) if args: projects = projects.filter(pk__in=args) for project in projects: repo_type = project.repository_type if repo_type not in ('git', 'hg', 'svn'): output('Committing project %s failed: Not a VCS project' % (project)) continue # Update project from VCS to ensure the directory exists. try: update_from_repository(project) extract_to_database(project) output('Updated project %s' % project) except Exception as e: raise CommandError(u'Update error: %s\n' % unicode(e)) for locale in project.locales.all(): # Dump files from database path = dump_from_database(project, locale) if not path: error = 'Repository path not found' output('Committing project %s for %s (%s) failed: %s' % (project, locale.name, locale.code, error)) continue message = 'Pontoon: Update %s (%s) localization of %s.' \ % (locale.name, locale.code, project.name) # Set latest translation author as commit author if available user = User.objects.filter(is_superuser=True)[0] translations = Translation.objects.exclude(user=None).filter( locale=locale, entity__obsolete=False, entity__resource__project=project) \ .order_by('-date') if translations: user = translations[0].user # Commit files to VCS try: r = commit_to_vcs(repo_type, path, message, user, project.repository_url) except Exception as e: output('Committing project %s for %s (%s) failed: %s' % (project, locale.name, locale.code, unicode(e))) continue if r is not None: output('Committing project %s for %s (%s) failed: %s' % (project, locale.name, locale.code, r["message"])) continue output('Commited project %s for %s (%s)' % (project, locale.name, locale.code)) output('COMMIT PROJECTS: done')