Exemplo n.º 1
0
def add_nzbfile(nzbfile,
                pp=None,
                script=None,
                cat=None,
                priority=NORMAL_PRIORITY,
                nzbname=None,
                reuse=False):
    """ Add disk-based NZB file, optional attributes,
        'reuse' flag will suppress duplicate detection
    """
    if pp and pp == "-1": pp = None
    if script and script.lower() == 'default': script = None
    if cat and cat.lower() == 'default': cat = None

    if isinstance(nzbfile, str):
        # File coming from queue repair
        filename = nzbfile
        keep = True
    else:
        # File coming from API/TAPI
        # Consider reception of Latin-1 names for non-Windows platforms
        # When an OSX/Unix server receives a file from Windows platform
        filename = encoding.special_fixer(nzbfile.filename)
        keep = False

    if not sabnzbd.WIN32:
        # If windows client sends file to Unix server backslashed may
        # be included, so convert these
        filename = filename.replace('\\', '/')

    filename = os.path.basename(filename)
    root, ext = os.path.splitext(filename)

    logging.info('Adding %s', filename)

    if isinstance(nzbfile, str):
        path = nzbfile
    else:
        try:
            f, path = tempfile.mkstemp(suffix=ext, text=False)
            os.write(f, nzbfile.value)
            os.close(f)
        except:
            logging.error(Ta('Cannot create temp file for %s'), filename)
            logging.info("Traceback: ", exc_info=True)

    if ext.lower() in ('.zip', '.rar'):
        ProcessArchiveFile(filename, path, pp, script, cat, priority=priority)
    else:
        ProcessSingleFile(filename,
                          path,
                          pp,
                          script,
                          cat,
                          priority=priority,
                          nzbname=nzbname,
                          keep=keep,
                          reuse=reuse)
Exemplo n.º 2
0
def fix_unix_encoding(folder):
    """ Fix bad name encoding for Unix systems """
    if not sabnzbd.WIN32 and not sabnzbd.DARWIN and gUTF:
        for root, dirs, files in os.walk(folder.encode('utf-8')):
            for name in files:
                new_name = special_fixer(name).encode('utf-8')
                if name != new_name:
                    try:
                        shutil.move(os.path.join(root, name), os.path.join(root, new_name))
                    except:
                        logging.info('Cannot correct name of %s', os.path.join(root, name))
Exemplo n.º 3
0
def fix_unix_encoding(folder):
    """ Fix bad name encoding for Unix systems """
    if not sabnzbd.WIN32 and not sabnzbd.DARWIN and gUTF:
        for root, dirs, files in os.walk(folder.encode('utf-8')):
            for name in files:
                new_name = special_fixer(name).encode('utf-8')
                if name != new_name:
                    try:
                        shutil.move(os.path.join(root, name), os.path.join(root, new_name))
                    except:
                        logging.info('Cannot correct name of %s', os.path.join(root, name))
Exemplo n.º 4
0
def add_nzbfile(nzbfile, pp=None, script=None, cat=None, priority=NORMAL_PRIORITY, nzbname=None, reuse=False):
    """ Add disk-based NZB file, optional attributes,
        'reuse' flag will suppress duplicate detection
    """
    if pp and pp=="-1": pp = None
    if script and script.lower()=='default': script = None
    if cat and cat.lower()=='default': cat = None

    if isinstance(nzbfile, str):
        # File coming from queue repair
        filename = nzbfile
        keep = True
    else:
        # File coming from API/TAPI
        # Consider reception of Latin-1 names for non-Windows platforms
        # When an OSX/Unix server receives a file from Windows platform
        filename = encoding.special_fixer(nzbfile.filename)
        keep = False

    if not sabnzbd.WIN32:
        # If windows client sends file to Unix server backslashed may
        # be included, so convert these
        filename = filename.replace('\\', '/')

    filename = os.path.basename(filename)
    root, ext = os.path.splitext(filename)

    logging.info('Adding %s', filename)

    if isinstance(nzbfile, str):
        path = nzbfile
    else:
        try:
            f, path = tempfile.mkstemp(suffix=ext, text=False)
            os.write(f, nzbfile.value)
            os.close(f)
        except:
            logging.error(Ta('Cannot create temp file for %s'), filename)
            logging.info("Traceback: ", exc_info = True)

    if ext.lower() in ('.zip', '.rar'):
        ProcessArchiveFile(filename, path, pp, script, cat, priority=priority)
    else:
        ProcessSingleFile(filename, path, pp, script, cat, priority=priority, nzbname=nzbname, keep=keep, reuse=reuse)
Exemplo n.º 5
0
def add_nzbfile(nzbfile,
                pp=None,
                script=None,
                cat=None,
                priority=NORMAL_PRIORITY,
                nzbname=None,
                reuse=False,
                password=None):
    """ Add disk-based NZB file, optional attributes,
        'reuse' flag will suppress duplicate detection
    """
    if pp and pp == "-1":
        pp = None
    if script and script.lower() == 'default':
        script = None
    if cat and cat.lower() == 'default':
        cat = None

    if isinstance(nzbfile, basestring):
        # File coming from queue repair
        filename = nzbfile
        keep = True
    else:
        # File coming from API/TAPI
        # Consider reception of Latin-1 names for non-Windows platforms
        # When an OSX/Unix server receives a file from Windows platform
        # CherryPy delivers filename as UTF-8 disguised as Unicode!
        try:
            filename = nzbfile.filename.encode('cp1252').decode('utf-8')
        except:
            # Correct encoding after all!
            filename = nzbfile.filename
        filename = encoding.special_fixer(filename)
        keep = False

    if not sabnzbd.WIN32:
        # If windows client sends file to Unix server backslashes may
        # be included, so convert these
        filename = filename.replace('\\', '/')

    filename = os.path.basename(filename)
    ext = os.path.splitext(filename)[1]
    if ext.lower() in VALID_ARCHIVES:
        suffix = ext.lower()
    else:
        suffix = '.nzb'

    logging.info('Adding %s', filename)

    if isinstance(nzbfile, basestring):
        path = nzbfile
    else:
        try:
            f, path = tempfile.mkstemp(suffix=suffix, text=False)
            # More CherryPy madness, sometimes content is in 'value', sometimes not.
            if nzbfile.value:
                os.write(f, nzbfile.value)
            elif hasattr(nzbfile, 'file'):
                # CherryPy 3.2.2 object
                if hasattr(nzbfile.file, 'file'):
                    os.write(f, nzbfile.file.file.read())
                else:
                    os.write(f, nzbfile.file.read())
            os.close(f)
        except:
            logging.error(T('Cannot create temp file for %s'), filename)
            logging.info("Traceback: ", exc_info=True)

    if ext.lower() in VALID_ARCHIVES:
        return ProcessArchiveFile(filename,
                                  path,
                                  pp,
                                  script,
                                  cat,
                                  priority=priority,
                                  nzbname=nzbname,
                                  password=password)
    else:
        return ProcessSingleFile(filename,
                                 path,
                                 pp,
                                 script,
                                 cat,
                                 priority=priority,
                                 nzbname=nzbname,
                                 keep=keep,
                                 reuse=reuse,
                                 password=password)
Exemplo n.º 6
0
def add_nzbfile(nzbfile, pp=None, script=None, cat=None, priority=NORMAL_PRIORITY, nzbname=None, reuse=False, password=None):
    """ Add disk-based NZB file, optional attributes,
        'reuse' flag will suppress duplicate detection
    """
    if pp and pp == "-1":
        pp = None
    if script and script.lower() == 'default':
        script = None
    if cat and cat.lower() == 'default':
        cat = None

    if isinstance(nzbfile, basestring):
        # File coming from queue repair
        filename = nzbfile
        keep = True
    else:
        # File coming from API/TAPI
        # Consider reception of Latin-1 names for non-Windows platforms
        # When an OSX/Unix server receives a file from Windows platform
        # CherryPy delivers filename as UTF-8 disguised as Unicode!
        try:
            filename = nzbfile.filename.encode('cp1252').decode('utf-8')
        except:
            # Correct encoding afterall!
            filename = nzbfile.filename
        filename = encoding.special_fixer(filename)
        keep = False

    if not sabnzbd.WIN32:
        # If windows client sends file to Unix server backslashed may
        # be included, so convert these
        filename = filename.replace('\\', '/')

    filename = os.path.basename(filename)
    ext = os.path.splitext(filename)[1]
    if ext.lower() in VALID_ARCHIVES:
        suffix = ext.lower()
    else:
        suffix = '.nzb'

    logging.info('Adding %s', filename)

    if isinstance(nzbfile, basestring):
        path = nzbfile
    else:
        try:
            f, path = tempfile.mkstemp(suffix=suffix, text=False)
            # More CherryPy madness, sometimes content is in 'value', sometimes not.
            if nzbfile.value:
                os.write(f, nzbfile.value)
            elif hasattr(nzbfile, 'file'):
                # CherryPy 3.2.2 object
                if hasattr(nzbfile.file, 'file'):
                    os.write(f, nzbfile.file.file.read())
                else:
                    os.write(f, nzbfile.file.read())
            os.close(f)
        except:
            logging.error(T('Cannot create temp file for %s'), filename)
            logging.info("Traceback: ", exc_info=True)

    if ext.lower() in VALID_ARCHIVES:
        return ProcessArchiveFile(filename, path, pp, script, cat, priority=priority, nzbname=nzbname,
                                  password=password)
    else:
        return ProcessSingleFile(filename, path, pp, script, cat, priority=priority, nzbname=nzbname,
                                 keep=keep, reuse=reuse, password=password)