当前位置: 首页>>代码示例>>Python>>正文


Python text.get_valid_filename方法代码示例

本文整理汇总了Python中django.utils.text.get_valid_filename方法的典型用法代码示例。如果您正苦于以下问题:Python text.get_valid_filename方法的具体用法?Python text.get_valid_filename怎么用?Python text.get_valid_filename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.utils.text的用法示例。


在下文中一共展示了text.get_valid_filename方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_job_results

# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_valid_filename [as 别名]
def get_job_results(request, job_id):
    """
    Just download all the output of the job into a tarball.
    """
    job = get_object_or_404(models.Job.objects.select_related('recipe',).prefetch_related('step_results'), pk=job_id)
    perms = Permissions.job_permissions(request.session, job)
    if not perms['can_see_results']:
        return HttpResponseForbidden('Not allowed to see results')

    response = HttpResponse(content_type='application/x-gzip')
    base_name = 'results_{}_{}'.format(job.pk, get_valid_filename(job.recipe.name))
    response['Content-Disposition'] = 'attachment; filename="{}.tar.gz"'.format(base_name)
    tar = tarfile.open(fileobj=response, mode='w:gz')
    for result in job.step_results.all():
        info = tarfile.TarInfo(name='{}/{:02}_{}'.format(base_name, result.position, get_valid_filename(result.name)))
        s = BytesIO(result.plain_output().replace('\u2018', "'").replace("\u2019", "'").encode("utf-8", "replace"))
        buf = s.getvalue()
        info.size = len(buf)
        info.mtime = time.time()
        tar.addfile(tarinfo=info, fileobj=s)
    tar.close()
    return response 
开发者ID:idaholab,项目名称:civet,代码行数:24,代码来源:views.py

示例2: _calculate_remote_path

# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_valid_filename [as 别名]
def _calculate_remote_path(self, job_exe):
        """Returns the remote path for storing the manifest

        :param job_exe: The job execution model (with related job and job_type fields) that is storing the files
        :type job_exe: :class:`job.models.JobExecution`
        :returns: The remote path for storing the manifest
        :rtype: str
        """

        remote_path = ''
        if job_exe.job.recipe:
            recipe = job_exe.job.recipe
            recipe_type_path = get_valid_filename(recipe.recipe_type.name)
            recipe_version_path = get_valid_filename(recipe.recipe_type.revision_num)
            remote_path = os.path.join(remote_path, 'recipes', recipe_type_path, recipe_version_path)
        job_type_path = get_valid_filename(job_exe.job.job_type.name)
        job_version_path = get_valid_filename(job_exe.job.job_type.version)
        remote_path = os.path.join(remote_path, 'jobs', job_type_path, job_version_path)

        the_date = now()
        year_dir = str(the_date.year)
        month_dir = '%02d' % the_date.month
        day_dir = '%02d' % the_date.day
        return os.path.join(remote_path, year_dir, month_dir, day_dir, 'job_exe_%i' % job_exe.id) 
开发者ID:ngageoint,项目名称:scale,代码行数:26,代码来源:scale_pre_steps.py

示例3: test_fails

# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_valid_filename [as 别名]
def test_fails(self, mock_makedirs, mock_getsize):
        """Tests calling ScaleFileManager.upload_files() when Workspace.upload_files() fails"""
        def new_getsize(path):
            return 100
        mock_getsize.side_effect = new_getsize

        upload_dir = os.path.join('upload', 'dir')
        work_dir = os.path.join('work', 'dir')

        workspace = storage_test_utils.create_workspace()
        file_1 = ScaleFile()
        file_1.media_type = None  # Scale should auto-detect text/plain
        remote_path_1 = 'my/remote/path/file.txt'
        local_path_1 = 'my/local/path/file.txt'
        file_2 = ScaleFile()
        file_2.media_type = 'application/json'
        remote_path_2 = 'my/remote/path/2/file.json'
        local_path_2 = 'my/local/path/2/file.json'
        workspace.upload_files = MagicMock()
        workspace.upload_files.side_effect = Exception
        workspace.delete_files = MagicMock()
        delete_work_dir = os.path.join(work_dir, 'delete', get_valid_filename(workspace.name))

        files = [(file_1, local_path_1, remote_path_1), (file_2, local_path_2, remote_path_2)]
        self.assertRaises(Exception, ScaleFile.objects.upload_files, upload_dir, work_dir, workspace, files) 
开发者ID:ngageoint,项目名称:scale,代码行数:27,代码来源:test_models.py

示例4: get_valid_name

# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_valid_filename [as 别名]
def get_valid_name(self, name):
        """
        Returns a filename, based on the provided filename, that's suitable for
        use in the target storage system.
        """
        return get_valid_filename(name) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:8,代码来源:storage.py

示例5: download_spark_job

# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_valid_filename [as 别名]
def download_spark_job(request, id):
    """
    Download the notebook file for the scheduled Spark job with the given ID.
    """
    spark_job = SparkJob.objects.get(pk=id)
    response = StreamingHttpResponse(
        spark_job.notebook_s3_object["Body"].read().decode("utf-8"),
        content_type="application/x-ipynb+json",
    )
    response["Content-Disposition"] = "attachment; filename=%s" % get_valid_filename(
        spark_job.notebook_name
    )
    response["Content-Length"] = spark_job.notebook_s3_object["ContentLength"]
    return response 
开发者ID:mozilla,项目名称:telemetry-analysis-service,代码行数:16,代码来源:views.py

示例6: setUp

# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_valid_filename [as 别名]
def setUp(self):
        django.setup()

        self.workspace_1 = Workspace.objects.create(name='Test workspace 1')
        self.workspace_2 = Workspace.objects.create(name='Test workspace 2', is_active=False)

        manifest = job_utils.create_seed_manifest(name='Type-1')
        job_type = job_utils.create_seed_job_type(manifest=manifest)

        event = TriggerEvent.objects.create_trigger_event('TEST', None, {}, now())
        self.job = job_utils.create_job(job_type=job_type, event=event, status='RUNNING', last_status_change=now())
        self.job_exe = job_utils.create_job_exe(job=self.job, status='RUNNING', timeout=1, queued=now())
        self.remote_base_path = os.path.join('jobs', get_valid_filename(self.job.job_type.name),
                                             get_valid_filename(self.job.job_type.version)) 
开发者ID:ngageoint,项目名称:scale,代码行数:16,代码来源:test_product_data_file.py

示例7: output_path

# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_valid_filename [as 别名]
def output_path(self):
        return os.path.join(djangui_settings.DJANGUI_FILE_DIR, get_valid_filename(self.user.username if self.user is not None else ''),
                            get_valid_filename(self.script.slug if not self.script.save_path else self.script.save_path), str(self.pk)) 
开发者ID:Chris7,项目名称:django-djangui,代码行数:5,代码来源:core.py

示例8: get_valid_filename

# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_valid_filename [as 别名]
def get_valid_filename(s):
    """
    like the regular get_valid_filename, but also slugifies away
    umlauts and stuff.
    """
    s = get_valid_filename_django(s)
    filename, ext = os.path.splitext(s)
    filename = slugify(filename)
    ext = slugify(ext)
    if ext:
        return "%s.%s" % (filename, ext)
    else:
        return "%s" % (filename,) 
开发者ID:django-leonardo,项目名称:django-leonardo,代码行数:15,代码来源:utils.py

示例9: save_dead_letter

# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_valid_filename [as 别名]
def save_dead_letter(data, file_suffix, directory="/tmp/zentral_dead_letters"):
    now = timezone.now()
    filename = "{}_{}.json".format(
        now.strftime("%Y-%m-%d_%H.%M.%S.%f"),
        file_suffix
    )
    dirpath = os.path.join(directory, now.strftime("%Y/%m/%d"))
    try:
        os.makedirs(dirpath, exist_ok=True)
        with open(os.path.join(dirpath, get_valid_filename(filename)), "w", encoding="utf-8") as f:
            json.dump(data, f, indent="  ")
    except Exception:
        logger.error("Could not save dead letter %s", file_suffix) 
开发者ID:zentralopensource,项目名称:zentral,代码行数:15,代码来源:json.py

示例10: test_get_valid_filename

# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_valid_filename [as 别名]
def test_get_valid_filename(self):
        filename = "^&'@{}[],$=!-#()%+~_123.txt"
        self.assertEqual(text.get_valid_filename(filename), "-_123.txt")
        self.assertEqual(text.get_valid_filename(lazystr(filename)), "-_123.txt") 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:test_text.py

示例11: _calculate_remote_path

# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_valid_filename [as 别名]
def _calculate_remote_path(self, job_exe, input_file_ids):
        """Returns the remote path for storing the products

        :param job_exe: The job execution model (with related job and job_type fields) that is storing the files
        :type job_exe: :class:`job.models.JobExecution`
        :param input_file_ids: Set of input file IDs
        :type input_file_ids: set of int
        :returns: The remote path for storing the products
        :rtype: str
        """

        remote_path = ''
        job_recipe = Recipe.objects.get_recipe_for_job(job_exe.job_id)
        if job_recipe:
            recipe = job_recipe.recipe
            recipe_type_path = get_valid_filename(recipe.recipe_type.name)
            recipe_revision = RecipeTypeRevision.objects.get_revision(recipe.recipe_type.name, recipe.recipe_type.revision_num).revision_num
            recipe_version_path = get_valid_filename('revision_%i' % recipe.recipe_type.revision_num)
            remote_path = os.path.join(remote_path, 'recipes', recipe_type_path, recipe_version_path)
        job_type_path = get_valid_filename(job_exe.job.job_type.name)
        job_version_path = get_valid_filename(job_exe.job.job_type.version)
        remote_path = os.path.join(remote_path, 'jobs', job_type_path, job_version_path)

        # Try to use source start time from the job
        the_date = job_exe.job.source_started

        if not the_date:
            # Try to grab source started the old way through the source ancestor file
            for source_file in FileAncestryLink.objects.get_source_ancestors(list(input_file_ids)):
                if source_file.data_started:
                    if not the_date or source_file.data_started < the_date:
                        the_date = source_file.data_started

        # No data start time populated, use current time
        if not the_date:
            remote_path = os.path.join(remote_path, 'unknown_source_data_time')
            the_date = now()

        year_dir = str(the_date.year)
        month_dir = '%02d' % the_date.month
        day_dir = '%02d' % the_date.day
        return os.path.join(remote_path, year_dir, month_dir, day_dir, 'job_exe_%i' % job_exe.id) 
开发者ID:ngageoint,项目名称:scale,代码行数:44,代码来源:product_data_file.py


注:本文中的django.utils.text.get_valid_filename方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。