Пример #1
0
def read(path, linea_inicio=0, total_lineas=None):
    """
    Lee el contenido de un archivo y devuelve los datos
    @param path: ruta del fichero
    @type path: str
    @param linea_inicio: primera linea a leer del fichero
    @type linea_inicio: int positivo
    @param total_lineas: numero maximo de lineas a leer. Si es None, 0 o superior al total de lineas se leera el
        fichero hasta el final.
    @type total_lineas: int positivo
    @rtype: str
    @return: datos que contiene el fichero
    """
    path = encode(path)
    data = ""
    n_line = 0
    line_count = 0
    if total_lineas <= 0:
        total_lineas = None

    if path.lower().startswith("smb://"):
        from sambatools.smb.smb_structs import OperationFailure

        try:
            f = samba.get_file_handle_for_reading(os.path.basename(path),
                                                  os.path.dirname(path))
            for line in f:
                if n_line >= linea_inicio:
                    data += line
                    line_count += 1
                n_line += 1
                if total_lineas is not None and line_count == int(
                        total_lineas):
                    break
            f.close()

        except OperationFailure:
            logger.info(
                "deportesalacarta.core.filetools read: ERROR al leer el archivo: {0}"
                .format(path))

    else:
        try:
            f = open(path, "rb")
            for line in f:
                if n_line >= linea_inicio:
                    data += line
                    line_count += 1
                n_line += 1
                if total_lineas is not None and line_count == int(
                        total_lineas):
                    break
            f.close()

        except EnvironmentError:
            logger.info(
                "deportesalacarta.core.filetools read: ERROR al leer el archivo: %s"
                % path)

    return data
Пример #2
0
def read(path):
    """
    Lee el contenido de un archivo y devuelve los datos
    @param path: ruta del fichero
    @type path: str
    @rtype: str
    @return: datos que contiene el fichero
    """
    path = encode(path)
    data = ""
    if path.lower().startswith("smb://"):
        from sambatools.smb.smb_structs import OperationFailure

        try:
            f = samba.get_file_handle_for_reading(os.path.basename(path), os.path.dirname(path)).read()
            for line in f:
                data += line
            f.close()

        except OperationFailure:
            logger.info("pelisalacarta.core.filetools read: ERROR al leer el archivo: {0}".format(path))

    else:
        try:
            f = open(path, "rb")
            for line in f:
                data += line
            f.close()
        except EnvironmentError:
            logger.info("pelisalacarta.core.filetools read: ERROR al leer el archivo: {0}".format(path))

    return data
Пример #3
0
def readbookmark(filename, readpath=BOOKMARK_PATH):
    logger.info("deportesalacarta.channels.favoritos readbookmark")

    if samba.usingsamba(readpath):
        bookmarkfile = samba.get_file_handle_for_reading(filename, readpath)
    else:
        filepath = os.path.join(readpath, filename)

        # Lee el fichero de configuracion
        logger.info("deportesalacarta.channels.favoritos filepath=" + filepath)
        bookmarkfile = open(filepath)
    lines = bookmarkfile.readlines()

    try:
        titulo = urllib.unquote_plus(lines[0].strip())
    except:
        titulo = lines[0].strip()

    try:
        url = urllib.unquote_plus(lines[1].strip())
    except:
        url = lines[1].strip()

    try:
        thumbnail = urllib.unquote_plus(lines[2].strip())
    except:
        thumbnail = lines[2].strip()

    try:
        server = urllib.unquote_plus(lines[3].strip())
    except:
        server = lines[3].strip()

    try:
        plot = urllib.unquote_plus(lines[4].strip())
    except:
        plot = lines[4].strip()

    # Campos fulltitle y canal añadidos
    if len(lines) >= 6:
        try:
            fulltitle = urllib.unquote_plus(lines[5].strip())
        except:
            fulltitle = lines[5].strip()
    else:
        fulltitle = titulo

    if len(lines) >= 7:
        try:
            canal = urllib.unquote_plus(lines[6].strip())
        except:
            canal = lines[6].strip()
    else:
        canal = ""

    bookmarkfile.close()

    return canal, titulo, thumbnail, plot, server, url, fulltitle
def readbookmark(filename, readpath=BOOKMARK_PATH):
    logger.info("streamondemand.channels.favoritos readbookmark")

    if samba.usingsamba(readpath):
        bookmarkfile = samba.get_file_handle_for_reading(filename, readpath)
    else:
        filepath = os.path.join(readpath, filename)

        # Lee el fichero de configuracion
        logger.info("streamondemand.channels.favoritos filepath="+filepath)
        bookmarkfile = open(filepath)
    lines = bookmarkfile.readlines()

    try:
        titulo = urllib.unquote_plus(lines[0].strip())
    except:
        titulo = lines[0].strip()
    
    try:
        url = urllib.unquote_plus(lines[1].strip())
    except:
        url = lines[1].strip()
    
    try:
        thumbnail = urllib.unquote_plus(lines[2].strip())
    except:
        thumbnail = lines[2].strip()
    
    try:
        server = urllib.unquote_plus(lines[3].strip())
    except:
        server = lines[3].strip()
        
    try:
        plot = urllib.unquote_plus(lines[4].strip())
    except:
        plot = lines[4].strip()

    # Campos fulltitle y canal añadidos
    if len(lines) >= 6:
        try:
            fulltitle = urllib.unquote_plus(lines[5].strip())
        except:
            fulltitle = lines[5].strip()
    else:
        fulltitle = titulo

    if len(lines) >= 7:
        try:
            canal = urllib.unquote_plus(lines[6].strip())
        except:
            canal = lines[6].strip()
    else:
        canal = ""

    bookmarkfile.close()

    return canal, titulo, thumbnail, plot, server, url, fulltitle
Пример #5
0
def read(path, linea_inicio=0, total_lineas=None):
    """
    Lee el contenido de un archivo y devuelve los datos
    @param path: ruta del fichero
    @type path: str
    @param linea_inicio: primera linea a leer del fichero
    @type linea_inicio: int positivo
    @param total_lineas: numero maximo de lineas a leer. Si es None, 0 o superior al total de lineas se leera el
        fichero hasta el final.
    @type total_lineas: int positivo
    @rtype: str
    @return: datos que contiene el fichero
    """
    path = encode(path)
    data = ""
    n_line = 0
    line_count = 0
    if total_lineas <= 0:
        total_lineas = None

    if path.lower().startswith("smb://"):
        from sambatools.smb.smb_structs import OperationFailure

        try:
            f = samba.get_file_handle_for_reading(os.path.basename(path), os.path.dirname(path))
            for line in f:
                if n_line >= linea_inicio:
                    data += line
                    line_count += 1
                n_line += 1
                if total_lineas is not None and line_count == int(total_lineas):
                    break
            f.close()

        except OperationFailure:
            logger.info("pelisalacarta.core.filetools read: ERROR al leer el archivo: {0}".format(path))

    else:
        try:
            f = open(path, "rb")
            for line in f:
                if n_line >= linea_inicio:
                    data += line
                    line_count += 1
                n_line += 1
                if total_lineas is not None and line_count == int(total_lineas):
                    break
            f.close()

        except EnvironmentError:
            logger.info("pelisalacarta.core.filetools read: ERROR al leer el archivo: %s" % path)

    return data
Пример #6
0
def open_for_reading(path):
    """
    Abre un archivo para leerlo
    @param path: ruta
    @type path: str
    @rtype: str
    @return: datos del fichero
    """
    path = encode(path)
    if path.lower().startswith("smb://"):
        return samba.get_file_handle_for_reading(os.path.basename(path), os.path.dirname(path))
    else:
        return open(path, "rb")
Пример #7
0
def open_for_reading(path):
    """
    Abre un archivo para leerlo
    @param path: ruta
    @type path: str
    @rtype: str
    @return: datos del fichero
    """
    path = encode(path)
    if path.lower().startswith("smb://"):

        return samba.get_file_handle_for_reading(os.path.basename(path), os.path.dirname(path))
    else:
        return open(path, "rb")
Пример #8
0
def open_for_reading(path):
    """
    Abre un archivo para leerlo
    @param path: ruta
    @type path: str
    @rtype: str
    @return: datos del fichero
    """
    path = encode(path)
    try:
      if path.lower().startswith("smb://"):
          return samba.get_file_handle_for_reading(os.path.basename(path), os.path.dirname(path))
      else:
          return open(path, "rb")
    except:
      import traceback
      logger.info("pelisalacarta.core.open_for_reading mkdir: Error al abrir el archivo " + traceback.format_exc())
      platformtools.dialog_notification("Error al abrir", path)
      return False
def read(path):
    """
    Lee el contenido de un archivo y devuelve los datos
    @param path: ruta del fichero
    @type path: str
    @rtype: str
    @return: datos que contiene el fichero
    """
    path = encode(path)
    data = ""
    if path.lower().startswith("smb://"):
        from sambatools.smb.smb_structs import OperationFailure

        try:
            f = samba.get_file_handle_for_reading(
                os.path.basename(path), os.path.dirname(path)).read()
            for line in f:
                data += line


#            f.close()

        except OperationFailure:
            logger.info(
                "pelisalacarta.core.filetools read: ERROR al leer el archivo: {0}"
                .format(path))

    else:
        try:
            f = open(path, "rb")
            for line in f:
                data += line
            f.close()
        except EnvironmentError:
            logger.info(
                "pelisalacarta.core.filetools read: ERROR al leer el archivo: {0}"
                .format(path))

    return data