Пример #1
0
def verify_ffmpeg_existence(RepositoryRoot):
    commandPath = os.path.join(RepositoryRoot, FFMPEG_PATH_SUFFIX)
    if ryw.is_valid_file(commandPath, 'verify_ffmpeg_existence'):
        return commandPath
    ryw.give_news('Cannot find ffmpeg.  Advise you to install it.',
                  logging.info)
    return commandPath
Пример #2
0
def copy_queue_file(tmpdir, name):
    
    rfpath = os.path.join(RepositoryRoot, 'QUEUES', name)
    if not ryw.is_valid_file(rfpath, 'copy_queue_file'):
        ryw.give_bad_news('copy_queue_file: queue file invalid: ' + rfpath,
                          logging.error)
        return (0, '')
    
    freeKB = ryw.free_MB(tmpdir) * 1024
    success,bytes = ryw.get_file_size(rfpath)
    if not success:
        return (0, '')
    kB = math.ceil(bytes / 1024.0)

    if pretty_much_out_of_space(kB, freeKB):
        ryw.give_bad_news(
            'user_error: nearly out of space while uploading queue, KB: ' + repr(kB), logging.error)
        return (0, '')

    #appendedName = name + '_selection'
    appendedName = 'saved_selection'
    tmpFileName = os.path.join(tmpdir, appendedName)
    try:
        shutil.copyfile(rfpath, tmpFileName)
    except:
        ryw.give_bad_news('copy_queue_file: failed to copy queue file: ' +
                          rfpath + ' -> ' + tmpFileName,
                          logging.critical)
        return (0, '')

    return (bytes, appendedName)
def copy_reverse_lists(repDir):
    ryw.give_news2('copying reverse lists...   ', logging.info)
    logging.debug('copy_reverse_lists: ' + repDir)

    reverseListsFile = os.path.join(RepositoryRoot, 'ReverseLists')
    if not ryw.is_valid_file(reverseListsFile, 'copy_reverse_lists:'):
        ryw.give_news2('not found: ' + reverseListsFile + '<BR>',
                       logging.info)
        return True

    success,reverseLists = ReverseLists.open_reverse_lists(
        'AddRobotWriteRequests.copy_reverse_lists:',
        '', '', reverseListsFile, False,
        allowNullSearchFile = True)
    if not success:
        return False

    dst = os.path.join(repDir, 'ReverseLists')
    
    try:
        shutil.copyfile(reverseListsFile, dst)
    except:
        ryw.give_bad_news('copy_reverse_lists failed: ' +
                          reverseListsFile + ' ' + dst, logging.critical)
        if reverseLists:
            reverseLists.done()
        return False

    if reverseLists:
        reverseLists.done()
    
    logging.debug('copy_reverse_lists: ' + reverseListsFile + ' ' + dst)
    ryw.give_news2('done.<BR>', logging.info)
    return True    
Пример #4
0
def merge_incoming(existingName, incomingName, repositoryRoot,
                   searchFile=None):
    """called by ProcessDiscs.py"""

    logging.info('merge_incoming: ' + existingName + ' <- ' + incomingName)
    
    if not ryw.is_valid_file(incomingName, 'copy_reverse_lists:'):
        ryw.give_news3('merge_incoming: incoming ReverseLists not found.',
                       logging.info)
        return True

    if not searchFile:
        success,searchFile = ryw.open_search_file(
            'merge_incoming:',
            os.path.join(RepositoryRoot, 'WWW', 'logs'),
            'upload.log',
            os.path.join(RepositoryRoot, 'SearchFile'),
            False)
        if not success:
            if searchFile:
                searchFile.done()
            ryw.give_bad_news('merge_incoming: open search file failed. ',
                              logging.critical)
            return False

    success,existingRL = open_reverse_lists('ReverseLists.merge_incoming:',
                                            '', '', existingName, True,
                                            searchFile = searchFile,
                                            repositoryRoot = repositoryRoot)
    if not success:
        ryw.give_bad_news('merge_incoming: failed to open existing list.',
                          logging.critical)
        if existingRL:
            existingRL.done()
        return False

    success,incomingRL = open_reverse_lists('ReverseLists.merge_incoming:',
                                            '', '', incomingName, False,
                                            skipLk = True,
                                            allowNullSearchFile = True)
    if not success:
        ryw.give_bad_news('merge_incoming: failed to open incoming list.',
                          logging.error)
        if incomingRL:
            incomingRL.done()
        return False
        
    success = existingRL.merge(incomingRL, repositoryRoot)

    existingRL.done()
    incomingRL.done()

    if searchFile:
        searchFile.done()
    return success
def get_reqs(rfpath):
    if not os.path.exists(rfpath):
        #logging.debug('get_reqs: no existing request found.')
        return set('')

    if not ryw.is_valid_file(rfpath, msg='get_reqs'):
        ryw.give_bad_news('get_reqs: not a valid file: ' + rfpath,
                          logging.error)
        return set('')

    try:
        reqs = su.pickload(rfpath)
        logging.debug('get_reqs: get_reqs succeeded.')
        return reqs
    except:
        ryw.give_bad_news(
            'fatal_error: get_reqs: failed to load requests :' + rfpath, 
            logging.critical)
        return None
Пример #6
0
    def __read_reverse_lists_file(self):
        """lock held if instantiate for write.
        lock released if instantiate for read.
        skipLk is True when dealing with merging
        incoming ReverseLists file"""
        
        assert(self.reverseListsFile != None)

        if not ryw.is_valid_file(self.reverseListsFile,
                                 msg='__read_reverse_lists_file'):
            ryw.give_bad_news('__read_reverse_lists_file: '+
                              'not a valid file: ' + self.reverseListsFile,
                              logging.error)
            return False

        if not self.skipLock:
            if not self._ReverseLists__lock():
                self._ReverseLists__unlock()
                return False

        try:
            self.reverseDict = su.pickload(self.reverseListsFile)
        except:
            ryw.give_bad_news(
                '__read_reverse_lists_file: ' +
                'failed to open reverse lists file: ' +
                self.reverseListsFile, logging.critical)
            self._ReverseLists__unlock()
            return False

        if not self.skipLock:
            if not self.exclusive:
                self._ReverseLists__unlock()

        #logging.debug('ReverseLists.__read_reverse_lists_file: ' +
        #              repr(self.reverseDict))
        return True
Пример #7
0
def verify_ffmpeg_existence(RepositoryRoot):
    commandPath = r"/usr/bin/ffmpeg"
    if ryw.is_valid_file(commandPath, "verify_ffmpeg_existence"):
        return commandPath
    ryw.give_news("Cannot find ffmpeg.  Advise you to install it.", logging.info)
    return None
Пример #8
0
def sudo_chmod(path, smode="777", imode=0777, repositoryRoot=None):
    """from ryw.chmod_tree(). smode is a string, like '666' or '777'
    imode is a numbr, like 0666 or 0777.
    smode is used on Linux.
    imode is used on XP.
    caller should supply both.
    """

    if repositoryRoot == None:
        repositoryRoot = RepositoryRoot

    # chmodPath = os.path.join(repositoryRoot, 'etc', 'chmod')
    chmodPath = os.path.join("/usr/local/bin", "cmod2")

    if not ryw.is_valid_file(chmodPath):
        ryw.give_bad_news("Cannot find suid chmod. Advise you to fix this.", logging.error)
        return

    command = chmodPath + " " + smode + " " + path
    ret = subprocess.call(command, shell=True)

    if ret != 0:
        ryw.give_bad_news("sudo_chmod failed on " + path, logging.error)


#
# moved from ryw_ffmpeg.py
#
def verify_ffmpeg_existence(RepositoryRoot):
    commandPath = r"/usr/bin/ffmpeg"