小编bar*_*mar的帖子

如何只删除python中的文件内容

我有一个包含一些内容的临时文件和一个生成此文件的输出的python脚本.我想要重复N次,所以我需要重用该文件(实际上是文件数组).我正在删除整个内容,因此临时文件将在下一个周期中为空.要删除内容,请使用以下代码:

def deleteContent(pfile):

    pfile.seek(0)
    pfile.truncate()
    pfile.seek(0) # I believe this seek is redundant

    return pfile

tempFile=deleteContent(tempFile)
Run Code Online (Sandbox Code Playgroud)

我的问题是:是否还有其他(更好,更短或更安全)的方法来删除整个内容而不实际从磁盘中删除临时文件?

有点像tempFile.truncateAll()

python file-io seek

35
推荐指数
2
解决办法
9万
查看次数

如何在 Google Cloud HTTP 负载均衡器日志记录中记录 X-Forwarded-For 以导出到 BigQuery

我正在将所有日志从Google Cloud HTTP Loadbalancer导出到BigQuery,但缺少自定义 http 标头,例如X-Forwarded-For来自Cloudflare的原始 ip 。

我在Stackdriver日志记录中也没有看到这些标头,因此这可能不是接收器导出到BigQuery的问题。

我在哪里启用此日志记录?

谢谢

cloudflare google-bigquery google-cloud-platform stackdriver

5
推荐指数
1
解决办法
3121
查看次数

除了Jenkins Job DSL中的命名分支外,还添加了抑制自动scm触发功能吗?

如何添加默认的Suppress自动scm触发,但命名分支-Job DSL中的开发除外?

我尝试了文档 https://jenkinsci.github.io/job-dsl-plugin/#path/multibranchPipelineJob。没多说。似乎不被支持。

因此,我想我唯一的方法是通过configure块将自定义属性直接添加到XML。

我想要的是:

    <strategy class="jenkins.branch.NamedExceptionsBranchPropertyStrategy">
      <defaultProperties class="java.util.Arrays$ArrayList">
        <a class="jenkins.branch.BranchProperty-array">
          <jenkins.branch.NoTriggerBranchProperty/>
        </a>
      </defaultProperties>
      <namedExceptions class="java.util.Arrays$ArrayList">
        <a class="jenkins.branch.NamedExceptionsBranchPropertyStrategy$Named-array">
          <jenkins.branch.NamedExceptionsBranchPropertyStrategy_-Named>
            <props class="empty-list"/>
            <name>development</name>
          </jenkins.branch.NamedExceptionsBranchPropertyStrategy_-Named>
        </a>
      </namedExceptions>
    </strategy>
Run Code Online (Sandbox Code Playgroud)

我尝试过的

multibranchPipelineJob(jobName) {    
    branchSources {
        git {
            remote(gitRepo)
            credentialsId(credentials)
            includes('*')
            configure {
             it / "sources  class='jenkins.branch.MultiBranchProject$BranchSourceList'" / 'data' / 'jenkins.branch.BranchSource' / "strategy class='jenkins.branch.DefaultBranchPropertyStrategy'" << name('development')               
            }        
        }           
    }
}
Run Code Online (Sandbox Code Playgroud)

这很有用,但会不断崩溃http://job-dsl.herokuapp.com/ 这不是很有用https://github.com/jenkinsci/job-dsl-plugin/blob/master/docs/The-Configure-块.md

我不知道我在做什么,文档,手册和教程根本没有帮助。

编辑:

现在我有了这个。它可以工作,有点...

我能够生成作业,但是当我尝试重新保存作业时,詹金斯抛出错误。输出XML有所不同。

multibranchPipelineJob(jobName) {

        configure { 
            it / sources(class: 'jenkins.branch.MultiBranchProject$BranchSourceList') / 'data' / 'jenkins.branch.BranchSource' << {
                source(class: …
Run Code Online (Sandbox Code Playgroud)

jenkins jenkins-job-dsl jenkins-groovy jenkins-pipeline

5
推荐指数
1
解决办法
1785
查看次数

如何在Cloudflare后面的Google存储桶中托管React应用?

我在React中有一个小型静态网站,希望将其部署到Google Storage Bucket。

我有一个与此类似的router.jsx

<Route component={App}>            
  <Route path="/" component={AuthenticationFirewall(AccessSecurity(MainPanel), Login)}>
     <IndexRoute component={Homepage} />
     <Route path="/companies" component={Companies}>
       <IndexRoute component={CompaniesTable} />  
       <Route path="/companies/:id" component={CompaniesDetail} />
     </Route> 
  </Route> 
</Route>
Run Code Online (Sandbox Code Playgroud)

当我访问索引页面并单击所有内容(例如/ companies / 12)时,一切似乎正常。

但是,当我直接从链接访问domain.com/companies/12时(没有之前的单击到达此链接),出现404错误

Bucket的网络服务器不允许我设置我在Nginx中设置的内容

 location / {
    root /var/www/;
    try_files $uri /index.html;
   }
Run Code Online (Sandbox Code Playgroud)

正确处理路线。

我还希望使用https作为Cloudflare的 http代理,并且我觉得他们在为其自定义404错误页面提供服务时可能存在问题。

问题:

  • 如何设置Bucket的网络服务器以正确提供js应用程序路由?
  • 我需要在Cloudflare的网络服务器部分上进行设置吗?

cloudflare google-cloud-storage reactjs react-router

2
推荐指数
1
解决办法
820
查看次数