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


Python FilePath.getsize方法代码示例

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


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

示例1: Recording

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import getsize [as 别名]
class Recording(BackendItem):

    logCategory = 'dvbd_store'

    def __init__(self,store,
                 id,parent_id,
                 file,title,
                 date,duration,
                 mimetype):

        self.store = store
        self.id = 'recording.%s' % id
        self.parent_id = parent_id
        self.real_id = id
    
        path = unicode(file)
        # make sure path is an absolute local path (and not an URL)
        if path.startswith("file://"):
        		path = path[7:]
        self.location = FilePath(path)

        self.title = unicode(title)
        self.mimetype = str(mimetype)
        self.date = datetime.fromtimestamp(int(date))
        self.duration = int(duration)
        try:
            self.size = self.location.getsize()
        except Exception, msg:
            self.size = 0
        self.bitrate = 0
        self.url = self.store.urlbase + str(self.id)
开发者ID:BlackHole,项目名称:coherence,代码行数:33,代码来源:dvbd_storage.py

示例2: render_POST

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import getsize [as 别名]
 def render_POST(self, request):
     
     context = self._context(request)
     
     form, status, appstruct = self._validate_form(request)
     
     if status == 'ok':
         filename = context['renderer'](appstruct)
         
         fileobj = FilePath(filename)
         
         request.setHeader('content-disposition', 'attachment; filename="output.pdf"')
         request.setHeader('content-length', str(fileobj.getsize()))
         request.setHeader('content-type', 'application/pdf')
         
         producer = NoRangeStaticProducer(request, fileobj.open('r'))
         
         producer.start()
         
         return NOT_DONE_YET
     
     data['renderer_form'] = form.render(appstruct)
     
     self.render_template(data, request)
     
     return NOT_DONE_YET
开发者ID:jjmojojjmojo,项目名称:jira-autoprint,代码行数:28,代码来源:__init__.py

示例3: get_index

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import getsize [as 别名]
 def get_index(self, path):
     index = {}
     for root, dirs, files in os.walk(path):
         index[root] = {}
         for f in files:
             path = os.path.join(root, f)
             filepath = FilePath(path)
             try:
                 index[path] = {
                     'mtime': filepath.getModificationTime(),
                     'size': filepath.getsize(),
                 }
             except OSError:
                 # file could be a broken symlink, or deleted mid-scan
                 continue
     return index
开发者ID:priestd09,项目名称:backtrac,代码行数:18,代码来源:client.py

示例4: getDirectory

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import getsize [as 别名]
    def getDirectory(self, path='/'):

        self.fs = yield FilePath(path)

        if not self.fs.getPermissions():
            defer.returnValue(False)

        files = []

        for f in self.fs.listdir():
            if f == '/':
                continue

            fp = path+f
            fs = FilePath(fp)

            # dont follow symlinks
            if fs.realpath().path != fp:
                continue

            perm = None
            isdir = fs.isdir()
            size = fs.getsize()
            modified = datetime.utcfromtimestamp(fs.getModificationTime())

            df = DiscoveredFile(
                resource_id=self.data['resource_id'],
                file_path=path,
                file_name=f,
                file_isdir=isdir,
                file_size=size,
                file_modified=modified,
                file_perm=perm
            )

            print '[%s] LIST %s.' % (self.data['resource_name'], fp if not fp.endswith('.') else fp)
            files.append(df)

        defer.returnValue(files)
开发者ID:pombredanne,项目名称:findex-crawl,代码行数:41,代码来源:filesystem.py

示例5: Recording

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import getsize [as 别名]
class Recording(BackendItem):

    logCategory = 'dvbd_store'

    def __init__(self,store,
                 id,parent_id,
                 file,title,
                 date,duration,
                 mimetype):

        self.store = store
        self.id = 'recording.%s' % id
        self.parent_id = parent_id
        self.real_id = id

        self.location = FilePath(unicode(file))
        self.title = unicode(title)
        self.mimetype = str(mimetype)
        self.date = datetime.fromtimestamp(int(date))
        self.duration = int(duration)
        self.size = self.location.getsize()
        self.bitrate = 0
        self.url = self.store.urlbase + str(self.id)

    def get_children(self, start=0, end=0):
        return []

    def get_child_count(self):
        return 0

    def get_item(self, parent_id=None):

        self.debug("Recording get_item %r @ %r" %(self.id,self.parent_id))

        # create item
        item = DIDLLite.VideoBroadcast(self.id,self.parent_id)
        item.date = self.date
        item.title = self.title

        # add http resource
        res = DIDLLite.Resource(self.url, 'http-get:*:%s:*' % self.mimetype)
        if self.size > 0:
            res.size = self.size
        if self.duration > 0:
            res.duration = str(self.duration)
        if self.bitrate > 0:
            res.bitrate = str(bitrate)
        item.res.append(res)

        # add internal resource
        res = DIDLLite.Resource('file://'+ urllib.quote(self.get_path()), 'internal:%s:%s:*' % (self.store.server.coherence.hostname,self.mimetype))
        if self.size > 0:
            res.size = self.size
        if self.duration > 0:
            res.duration = str(self.duration)
        if self.bitrate > 0:
            res.bitrate = str(bitrate)
        item.res.append(res)

        return item

    def get_id(self):
        return self.id

    def get_name(self):
        return self.title

    def get_url(self):
        return self.url

    def get_path(self):
        return self.location.path
开发者ID:palfrey,项目名称:coherence,代码行数:74,代码来源:dvbd_storage.py

示例6: FSItem

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import getsize [as 别名]
class FSItem(BackendItem):
    logCategory = 'fs_item'

    def __init__(self, object_id, parent, path, mimetype, urlbase, UPnPClass,update=False):
        self.id = object_id
        self.parent = parent
        if parent:
            parent.add_child(self,update=update)
        if mimetype == 'root':
            self.location = unicode(path)
        else:
            if mimetype == 'item' and path is None:
                path = os.path.join(parent.get_path(),unicode(self.id))
            #self.location = FilePath(unicode(path))
            self.location = FilePath(path)
        self.mimetype = mimetype
        if urlbase[-1] != '/':
            urlbase += '/'
        self.url = urlbase + str(self.id)


        if parent == None:
            parent_id = -1
        else:
            parent_id = parent.get_id()

        self.item = UPnPClass(object_id, parent_id, self.get_name())
        if isinstance(self.item, Container):
            self.item.childCount = 0
        self.child_count = 0
        self.children = []


        if mimetype in ['directory','root']:
            self.update_id = 0
            self.get_url = lambda : self.url
            self.get_path = lambda : None
            #self.item.searchable = True
            #self.item.searchClass = 'object'
            if(isinstance(self.location,FilePath) and
               self.location.isdir() == True):
                self.check_for_cover_art()
                if hasattr(self, 'cover'):
                    _,ext =  os.path.splitext(self.cover)
                    """ add the cover image extension to help clients not reacting on
                        the mimetype """
                    self.item.albumArtURI = ''.join((urlbase,str(self.id),'?cover',ext))
        else:
            self.get_url = lambda : self.url

            if self.mimetype.startswith('audio/'):
                if hasattr(parent, 'cover'):
                    _,ext =  os.path.splitext(parent.cover)
                    """ add the cover image extension to help clients not reacting on
                        the mimetype """
                    self.item.albumArtURI = ''.join((urlbase,str(self.id),'?cover',ext))

            _,host_port,_,_,_ = urlsplit(urlbase)
            if host_port.find(':') != -1:
                host,port = tuple(host_port.split(':'))
            else:
                host = host_port

            try:
                size = self.location.getsize()
            except:
                size = 0

            if mimetype != 'item':
                res = Resource('file://'+ urllib.quote(self.get_path()), 'internal:%s:%s:*' % (host,self.mimetype))
                res.size = size
                self.item.res.append(res)

            if mimetype != 'item':
                res = Resource(self.url, 'http-get:*:%s:*' % self.mimetype)
            else:
                res = Resource(self.url, 'http-get:*:*:*')

            res.size = size
            self.item.res.append(res)


            """ if this item is an image and we want to add a thumbnail for it
                we have to follow these rules:

                create a new Resource object, at least a 'http-get'
                and maybe an 'internal' one too

                for an JPG this looks like that

                res = Resource(url_for_thumbnail,
                        'http-get:*:image/jpg:%s'% ';'.join(simple_dlna_tags+('DLNA.ORG_PN=JPEG_TN',)))
                res.size = size_of_thumbnail
                self.item.res.append(res)

                and for a PNG the Resource creation is like that

                res = Resource(url_for_thumbnail,
                        'http-get:*:image/png:%s'% ';'.join(simple_dlna_tags+('DLNA.ORG_PN=PNG_TN',)))

#.........这里部分代码省略.........
开发者ID:AndyThirtover,项目名称:wb_gateway,代码行数:103,代码来源:fs_storage.py

示例7: timedelta

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import getsize [as 别名]
import os
import re
import sys

from datetime import datetime, timedelta
from twisted.python.filepath import FilePath

date = datetime.now() - timedelta(days=1)
datestr = date.strftime("%Y-%m-%d")

os.system("wget -c http://eve-central.com/dumps/%s.dump.gz" % (datestr,))
os.system("gunzip %s.dump.gz" % (datestr,))

transactionsFilePath = FilePath("%s.dump" % (datestr,))
#transactionsFilePath = FilePath("transactions.csv")
size = float(transactionsFilePath.getsize())
fp = transactionsFilePath.open("r")

db = MySQLdb.connect("localhost", "root", db="frisky-iskies")
c = db.cursor()

c.execute("truncate table transactions")
c.execute("alter table transactions disable keys")

durationRe = re.compile(r"\D.*")

with open("transactions.csv") as csvfile:
    csvreader = csv.reader(csvfile)
    csvreader.next()
    i = 0
    for row in csvreader:
开发者ID:robhaswell,项目名称:frisky-iskies,代码行数:33,代码来源:import.py


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