當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。