コード例 #1
0
ファイル: download.py プロジェクト: nxmirrors/miro
 def move_to_directory(self, directory):
     check_f(directory)
     if self.channelName:
         channel_name = filter_directory_name(self.channelName)
         # bug 10769: shutil and windows has problems with long
         # filenames, so we clip the directory name.
         if len(channel_name) > 80:
             channel_name = channel_name[:80]
         directory = os.path.join(directory, channel_name)
         if not os.path.exists(directory):
             try:
                 fileutil.makedirs(directory)
             except (SystemExit, KeyboardInterrupt):
                 raise
             except:
                 pass
     newfilename = os.path.join(directory, self.shortFilename)
     if newfilename == self.filename:
         return
     newfilename, fp = next_free_filename(newfilename)
     def callback():
         self.filename = newfilename
         self.update_client()
     fileutil.migrate_file(self.filename, newfilename, callback)
     fp.close()
コード例 #2
0
ファイル: download.py プロジェクト: nxmirrors/miro
def migrate_download(dlid, directory):
    check_f(directory)
    try:
        download = _downloads[dlid]
    except KeyError:
        # There is no download with this id
        return

    if download.state in (u"finished", u"uploading", u"uploading-paused"):
        download.move_to_directory(directory)
コード例 #3
0
ファイル: utiltest.py プロジェクト: zjmmjzzjm/miro
        def test_name(text):
            correct_type = FilenameType(text)
            util.check_f(correct_type)

            if sys.platform == 'win32':
                incorrect_type = str(text)
            else:
                incorrect_type = unicode(text)

            self.assertRaises(util.MiroUnicodeError, util.check_f,
                              incorrect_type)
コード例 #4
0
ファイル: download_utils.py プロジェクト: cool-RR/Miro
def check_filename_extension(filename, content_type):
    """If a filename doesn't have an extension, this tries to find a
    suitable one based on the HTTP content-type info and add it if one
    is available.
    """
    check_f(filename)
    if content_type is not None and not filetypes.is_allowed_filename(filename):
        guessed_ext = filetypes.guess_extension(content_type)
        if guessed_ext is not None:
            filename += guessed_ext
    return filename
コード例 #5
0
ファイル: utiltest.py プロジェクト: codito/miro
        def test_name(text):
            correct_type = FilenameType(text)
            util.check_f(correct_type)

            if sys.platform == 'win32':
                incorrect_type = str(text)
            else:
                incorrect_type = unicode(text)

            self.assertRaises(util.MiroUnicodeError,
                              util.check_f, incorrect_type)
コード例 #6
0
ファイル: utiltest.py プロジェクト: cool-RR/Miro
        def testName(text):
            from miro.plat.utils import FilenameType

            correctType = FilenameType(text)
            util.check_f(correctType)

            incorrectType = text
            if FilenameType == str:
                incorrectType = unicode(text)

            self.assertRaises(util.MiroUnicodeError, util.check_f, incorrectType)
コード例 #7
0
ファイル: download_utils.py プロジェクト: zjmmjzzjm/miro
def check_filename_extension(filename, content_type):
    """If a filename doesn't have an extension, this tries to find a
    suitable one based on the HTTP content-type info and add it if one
    is available.
    """
    check_f(filename)
    if content_type is not None and not filetypes.is_allowed_filename(filename):
        guessed_ext = filetypes.guess_extension(content_type)
        if guessed_ext is not None:
            filename += guessed_ext
    return filename
コード例 #8
0
ファイル: download.py プロジェクト: nxmirrors/miro
def start_new_download(url, dlid, contentType, channelName):
    """Creates a new downloader object.

    Returns id on success, None on failure.
    """
    check_u(url)
    check_u(contentType)
    if channelName:
        check_f(channelName)
    dl = create_downloader(url, contentType, dlid)
    dl.channelName = channelName
    _downloads[dlid] = dl
コード例 #9
0
ファイル: utiltest.py プロジェクト: zjmmjzzjm/miro
    def test_check_f(self):
        def test_name(text):
            correct_type = FilenameType(text)
            util.check_f(correct_type)

            if sys.platform == 'win32':
                incorrect_type = str(text)
            else:
                incorrect_type = unicode(text)

            self.assertRaises(util.MiroUnicodeError, util.check_f,
                              incorrect_type)

        util.check_f(None)
        test_name("")
        test_name("abc.txt")
        test_name("./xyz.avi")
コード例 #10
0
ファイル: utiltest.py プロジェクト: codito/miro
    def test_check_f(self):
        def test_name(text):
            correct_type = FilenameType(text)
            util.check_f(correct_type)

            if sys.platform == 'win32':
                incorrect_type = str(text)
            else:
                incorrect_type = unicode(text)

            self.assertRaises(util.MiroUnicodeError,
                              util.check_f, incorrect_type)

        util.check_f(None)
        test_name("")
        test_name("abc.txt")
        test_name("./xyz.avi")
コード例 #11
0
ファイル: utiltest.py プロジェクト: cool-RR/Miro
    def test_check_f(self):

        def testName(text):
            from miro.plat.utils import FilenameType

            correctType = FilenameType(text)
            util.check_f(correctType)

            incorrectType = text
            if FilenameType == str:
                incorrectType = unicode(text)

            self.assertRaises(util.MiroUnicodeError, util.check_f, incorrectType)

        util.check_f(None)
        testName("")
        testName("abc.txt")
        testName("./xyz.avi")
コード例 #12
0
ファイル: download_utils.py プロジェクト: nxmirrors/miro
def next_free_filename(name):
    """Finds a filename that's unused and similar the the file we want
    to download and returns an open file handle to it.
    """ 
    check_f(name)
    mask = os.O_CREAT | os.O_EXCL | os.O_RDWR
    # Try with the name supplied.
    try:
        fd = os.open(expand_filename(name), mask)
        fp = os.fdopen(fd, 'wb')
        return expand_filename(name), fp
    except OSError:
        pass

    # Boh boh ... did't work.  Let's try to create a variant name and 
    # open that instead.
    parts = name.split('.')
    count = 1
    if len(parts) == 1:
        newname = "%s.%s" % (name, count)
        while True:
            try:
                fd = os.open(expand_filename(newname), mask)
                fp = os.fdopen(fd, 'wb')
                break
            except OSError:
                count += 1
                newname = "%s.%s" % (name, count)
                continue
    else:
        parts[-1:-1] = [str(count)]
        newname = '.'.join(parts)
        while True:
            try:
                fd = os.open(expand_filename(newname), mask)
                fp = os.fdopen(fd, 'wb')
                break
            except OSError:
                count += 1
                parts[-2] = str(count)
                newname = '.'.join(parts)
                continue
    return (expand_filename(newname), fp)
コード例 #13
0
ファイル: download_utils.py プロジェクト: kmshi/miro
def next_free_filename(name):
    """Finds a filename that's unused and similar the the file we want
    to download and returns an open file handle to it.
    """ 
    check_f(name)
    mask = os.O_CREAT | os.O_EXCL | os.O_RDWR
    # On Windows we need to pass in O_BINARY, fdopen() even with 'b' 
    # specified is not sufficient.
    if sys.platform == 'win32':
        mask |= os.O_BINARY

    candidates = next_free_filename_candidates(name)
    while True:
        # Try with the name supplied.
        newname = candidates.next()
        try:
            fd = os.open(expand_filename(newname), mask)
            fp = os.fdopen(fd, 'wb')
            return expand_filename(newname), fp
        except OSError:
            continue
    return (expand_filename(newname), fp)
コード例 #14
0
ファイル: downloader.py プロジェクト: dankamongmen/miro
 def set_channel_name(self, channel_name):
     if self.channel_name is None:
         if channel_name:
             check_f(channel_name)
         self.channel_name = channel_name
コード例 #15
0
 def set_channel_name(self, channel_name):
     if self.channel_name is None:
         if channel_name:
             check_f(channel_name)
         self.channel_name = channel_name