Esempio n. 1
0
    def test_random_string(self):
        ret = util.random_string(0)
        self.assertEquals(len(ret), 0)

        for length in (1, 5, 10):
            ret = util.random_string(length)
            self.assertEquals(len(ret), length)
            self.assertEquals(ret.isalpha(), True)
Esempio n. 2
0
    def test_random_string(self):
        ret = util.random_string(0)
        self.assertEquals(len(ret), 0)

        for length in (1, 5, 10):
            ret = util.random_string(length)
            self.assertEquals(len(ret), length)
            self.assertEquals(ret.isalpha(), True)
Esempio n. 3
0
 def _make_thumbnail_path(self):
     # add a random string to the filename to ensure it's unique.
     # Two videos can have the same basename if they're in
     # different directories.
     video_base = os.path.basename(self.video_path)
     filename = '%s.%s.png' % (video_base, util.random_string(5))
     return os.path.join(self.image_directory('extracted'), filename)
Esempio n. 4
0
 def _make_thumbnail_path(self):
     # add a random string to the filename to ensure it's unique.
     # Two videos can have the same basename if they're in
     # different directories.
     video_base = os.path.basename(self.video_path)
     filename = '%s.%s.png' % (video_base, util.random_string(5))
     return os.path.join(self.image_directory('extracted'), filename)
Esempio n. 5
0
    def _make_cover_art_file(self, filename, objects):
        if not isinstance(objects, list):
            objects = [objects]

        images = []
        for image_object in objects:
            try:
               image = Image(image_object)
            except UnknownImageObjectException:
               logging.debug("Couldn't parse image object of type %s",
                             type(image_object))
            else:
               images.append(image)

        cover_image = None
        for candidate in images:
            if candidate.is_cover_art:
                cover_image = candidate
                break
        if cover_image is None:
            # no attached image is definitively cover art. use the first one.
            cover_image = images[0]

        cover_filename = "{0}.{1}.{2}".format(os.path.basename(filename),
                         util.random_string(5), image.extension)
        cover_path = os.path.join(image_directory('cover-art'), cover_filename)
        try:
            file_handle = fileutil.open_file(cover_path, 'wb')
            file_handle.write(image.data) 
        except IOError:
            logging.warn(
                "Couldn't write cover art file: {0}".format(cover_path))
            cover_path = None
        return cover_path
Esempio n. 6
0
def XPCOMifyCallback(callback):
    global _callbacks
    # This assumes that n/(52^50) == 0 when n is small
    idstring = random_string(50)
    _callbacks[idstring] = callback
    c = makeComp("@participatoryculture.org/dtv/pycallback;1",
                 components.interfaces.pcfIDTVPyCallback, True, False)
    c.setCallbackId(idstring)
    return c
Esempio n. 7
0
def XPCOMifyCallback(callback):
    global _callbacks
    # This assumes that n/(52^50) == 0 when n is small
    idstring = random_string(50)
    _callbacks[idstring] = callback
    c = makeComp("@participatoryculture.org/dtv/pycallback;1",
                 components.interfaces.pcfIDTVPyCallback, True, False)
    c.setCallbackId(idstring)
    return c
Esempio n. 8
0
 def _get_destination_path(extension, track_path):
     filename = "{0}.{1}.{2}".format(os.path.basename(track_path),
                                     util.random_string(5), extension)
     directory = app.config.get(prefs.COVER_ART_DIRECTORY)
     # make the directory if necessary:
     try:
         fileutil.makedirs(directory)
     except StandardError:
         pass
     return os.path.join(directory, filename)
Esempio n. 9
0
 def _get_destination_path(extension, track_path):
     filename = "{0}.{1}.{2}".format(os.path.basename(track_path),
                util.random_string(5), extension)
     directory = app.config.get(prefs.COVER_ART_DIRECTORY)
     # make the directory if necessary:
     try:
         fileutil.makedirs(directory)
     except StandardError:
         pass
     return os.path.join(directory, filename)
Esempio n. 10
0
 def __init__(self, item):
     self.item = item
     self.video_path = item.get_filename()
     if self.video_path is None:
         self._program_info = None
         return
     # add a random string to the filename to ensure it's unique.
     # Two videos can have the same basename if they're in
     # different directories.
     thumbnail_filename = '%s.%s.png' % (os.path.basename(self.video_path),
                                         util.random_string(5))
     self.thumbnail_path = os.path.join(thumbnail_directory(),
                                        thumbnail_filename)
     if hasattr(app, 'in_unit_tests'):
         self._program_info = None