Exemple #1
0
    def update_project(self, request):
        """updates project translation files from version control,
        retaining uncommitted translations"""

        if not check_permission("commit", request):
            raise PermissionDenied(_("You do not have rights to update from version control here"))

        old_stats = self.getquickstats()
        remote_stats = {}

        for store in self.stores.iterator():
            try:
                oldstats, remotestats, newstats = self.update_file_from_version_control(store)
                remote_stats = dictsum(remote_stats, remotestats)
            except VersionControlError:
                pass

        project_tree.scan_translation_project_files(self)
        new_stats = self.getquickstats()

        request.user.message_set.create(message=unicode(_("Updated %s files from version control", self.fullname)))
        request.user.message_set.create(message=stats_message("working copy", old_stats))
        request.user.message_set.create(message=stats_message("remote copy", remote_stats))
        request.user.message_set.create(message=stats_message("merged copy", new_stats))

        post_vc_update.send(sender=self, oldstats=old_stats, remotestats=remote_stats, newstats=new_stats)
Exemple #2
0
    def handle_noargs(self, **options):
        refresh_path = options.get('directory', '')
        recompute = options.get('recompute', False)

        # reduce size of parse pool early on
        from pootle_store.fields import  TranslationStoreFieldFile
        TranslationStoreFieldFile._store_cache.maxsize = 2
        TranslationStoreFieldFile._store_cache.cullsize = 2


        for translation_project in TranslationProject.objects.filter(real_path__startswith=refresh_path).iterator():
            if not os.path.isdir(translation_project.abs_real_path):
                # translation project no longer exists
                translation_project.delete()
                continue

            # rescan translation_projects
            project_tree.scan_translation_project_files(translation_project)
            if recompute:
                for store in translation_project.stores.iterator():
                    # We force stats and indexing information to be recomputed by
                    # updating the mtimes of the files whose information we want
                    # to update.
                    logging.info("Resetting mtime for %s to now", store.real_path)
                    os.utime(store.abs_real_path, None)

            # This will force the indexer of a TranslationProject to be
            # initialized. The indexer will update the text index of the
            # TranslationProject if it is out of date.
            translation_project.indexer

            logging.info("Updating stats for %s", translation_project.fullname)
            translation_project.getcompletestats()
            translation_project.getquickstats()
Exemple #3
0
    def do_upload(self, request, translation_project, directory):
        if self.form.is_valid() and 'file' in request.FILES:
            django_file = self.form.cleaned_data['file']
            overwrite = self.form.cleaned_data['overwrite']
            scan_translation_project_files(translation_project)
            oldstats = translation_project.getquickstats()
            # The URL relative to the URL of the translation project. Thus, if
            # directory.pootle_path == /af/pootle/foo/bar, then
            # relative_root_dir == foo/bar.
            if django_file.name.endswith('.zip'):
                archive = True
                upload_archive(request, directory, django_file, overwrite)
            else:
                archive = False
                upload_file(request, directory, django_file, overwrite)
            scan_translation_project_files(translation_project)
            newstats = translation_project.getquickstats()

            # create a submission, doesn't fix stats but at least
            # shows up in last activity column
            s = Submission(creation_time=datetime.datetime.utcnow(),
                           translation_project=translation_project,
                           submitter=get_profile(request.user))
            s.save()

            post_file_upload.send(sender=translation_project, user=request.user, oldstats=oldstats,
                                  newstats=newstats, archive=archive)
        return {'upload': self}
Exemple #4
0
def tp_admin_files(request, translation_project):
    queryset = translation_project.stores.all()
    try:
        template_translation_project = TranslationProject.objects.get(project=translation_project.project,
                                                                      language__code='templates')
        if 'template_update' in request.GET:
            convert_templates(template_translation_project, translation_project)
    except TranslationProject.DoesNotExist:
        pass

    if 'scan_files' in request.GET:
        scan_translation_project_files(translation_project)
        for store in translation_project.stores.exclude(file='').iterator():
            store.sync(update_translation=True)
            store.update(update_structure=True, update_translation=True, conservative=False)

    model_args = {
        'title': _("Files"),
        'submitname': "changestores",
        'formid': "stores",
        'navitems': [navbar_dict.make_directory_navbar_dict(request, translation_project.directory)],
        'feed_path': translation_project.directory.pootle_path[1:],
        'translation_project': translation_project,
        'language': translation_project.language,
        'project': translation_project.project,
        'directory': translation_project.directory,
        }
    link = "%s/translate/"
    return util.edit(request, 'translation_project/tp_admin_files.html', Store, model_args,
                     link, linkfield='pootle_path', queryset=queryset,
                     formset=StoreFormset, can_delete=True, extra=0)
Exemple #5
0
def create_translation_project(language, project):
    if project_tree.translation_project_should_exist(language, project):
        try:
            translation_project, created = TranslationProject.objects.get_or_create(language=language, project=project)
            project_tree.scan_translation_project_files(translation_project)
            return translation_project
        except OSError:
            return None
        except IndexError:
            return None
Exemple #6
0
    def update_file(self, request, store):
        """updates file from version control, retaining uncommitted
        translations"""
        if not check_permission("commit", request):
            raise PermissionDenied(_("You do not have rights to update from version control here"))

        try:
            oldstats, remotestats, newstats = self.update_file_from_version_control(store)
            request.user.message_set.create(message=unicode(_("Updated file %s from version control", store.file.name)))
            request.user.message_set.create(message=stats_message("working copy", oldstats))
            request.user.message_set.create(message=stats_message("remote copy", remotestats))
            request.user.message_set.create(message=stats_message("merged copy", newstats))
            post_vc_update.send(sender=self, oldstats=oldstats, remotestats=remotestats, newstats=newstats)
        except VersionControlError:
            request.user.message_set.create(message=unicode(_("Failed to update %s from version control", store.file.name)))

        project_tree.scan_translation_project_files(self)
Exemple #7
0
def overwrite_file(request, relative_root_dir, django_file, upload_path):
    """overwrite with uploaded file"""
    upload_dir = os.path.dirname(absolute_real_path(upload_path))
    # Ensure that there is a directory into which we can dump the
    # uploaded file.
    if not os.path.exists(upload_dir):
        os.makedirs(upload_dir)

    # Get the file extensions of the uploaded filename and the
    # current translation project
    _upload_base, upload_ext = os.path.splitext(django_file.name)
    _local_base,  local_ext  = os.path.splitext(upload_path)
    # If the extension of the uploaded file matches the extension
    # used in this translation project, then we simply write the
    # file to the disc.
    if upload_ext == local_ext:
        outfile = open(absolute_real_path(upload_path), "wb")
        try:
            outfile.write(django_file.read())
        finally:
            outfile.close()
            try:
                #FIXME: we need a way to delay reparsing
                store = Store.objects.get(file=upload_path)
                store.update(update_structure=True, update_translation=True, conservative=False)
            except Store.DoesNotExist:
                # newfile, delay parsing
                pass
    else:
        # If the extension of the uploaded file does not match the
        # extension of the current translation project, we create
        # an empty file (with the right extension)...
        empty_store = factory.getobject(absolute_real_path(upload_path), classes=factory_classes)
        # And save it...
        empty_store.save()
        scan_translation_project_files(request.translation_project)
        # Then we open this newly created file and merge the
        # uploaded file into it.
        store = Store.objects.get(file=upload_path)
        newstore = factory.getobject(django_file, classes=factory_classes)
        #FIXME: maybe there is a faster way to do this?
        store.mergefile(newstore, request.user.username, allownewstrings=True, suggestions=False, notranslate=False, obsoletemissing=False)