pycurl和MLST

由于多种原因,我们想使用pycurl来获取MLST command上FTP服务器上存储的文件的信息。

使用以下代码,我们几乎可以满足需求:

# More or less equivalent to: curl --list -X MLST -D /tmp/headers ftp://ftp.ncbi.nlm.nih.gov/genomes/genbank/archaea/assembly_summary.txt 
import pycurl
try:
    from io import BytesIO
except ImportError:
    from StringIO import StringIO as BytesIO
c = pycurl.Curl()
c.setopt(c.URL,r'ftp://ftp.ncbi.nlm.nih.gov/genomes/genbank/archaea/assembly_summary.txt')
c.setopt(pycurl.DIRLISTONLY,True)
# Use MLST
c.setopt(c.CUSTOMREQUEST,"MLST")
# Write header to buffer
output = BytesIO()
c.setopt(pycurl.HEADERFUNCTION,output.write)
# Perform request
c.perform()
# Print header
result = output.getvalue()
result = result.decode('ISO-8859-1')

perform()失败,出现CURLE_FTP_COULDNT_RETR_FILE,但result(标题)包含了我们所需的内容。如果尝试使用CLI版本,则返回代码也是CURLE_FTP_COULDNT_RETR_FILE,但是文件/tmp/headers包含数据。

我们认为这与MLST使用控制连接而不是数据连接有关。

有什么想法吗?

编辑1

如果没有DIRLISTONLY(这很奇怪),我们还没有找到一种获取结果的方法。另外,如果我们使用NOBODY,我们将无法获得答案。

编辑2

事实证明,result包含有关目录(ftp://ftp.ncbi.nlm.nih.gov/genomes/genbank/archaea/)的信息,而不是文件,因此此处的代码不正确

tangfeng1212 回答:pycurl和MLST

事实证明,这样做很难(如果不是不可能的话)(请参阅 EDIT 2 )。但是,简单的代码可以获取最重要的信息(文件大小和最后修改时间)。

代码基于getinfo方法(和OPT_FILETIME选项):

RecyclerView

当然,我们使用NOBODY来避免下载文件。

这与命令大致相同:

...
@Override
public void onBindViewHolder(ViewHolder holder,final int position) {
    ...

    int bottomHeight = 0;
    int itemHeight = holder.itemView.getMeasuredHeight();
    // if it's the last item then add a bottom margin that is enough to bring it to the top
    if (position == mDataSet.length - 1) {
        bottomHeight = Math.max(0,mRootView.getMeasuredHeight() - itemHeight);
    }
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams)holder.itemView.getLayoutParams();
    params.setMargins(0,params.rightMargin,bottomHeight);
    holder.itemView.setLayoutParams(params);

    ...
} 
...
本文链接:https://www.f2er.com/3150039.html

大家都在问