コード例 #1
0
def open_output_text_file():
    """modeled after setting up temporary output file in rebuildSearchFile.py.
    """

    resourcesPath = os.path.join(RepositoryRoot, "Resources.txt")
    try:
        resources = ryw.get_resources(resourcesPath)
        tmpOutDir = ryw.get_resource_str(resources, "tmpout")
        if not tmpOutDir:
            ryw.give_bad_news("SelectTexts.py: failed to get tmpout resource.", logging.error)
            return None
    except:
        ryw.give_bad_news("SelectTexts.py: failed to get resources.", logging.error)
        return None

    dateTimeRand = ryw.date_time_rand()
    textfilePath = os.path.join(tmpOutDir, "Texts2Trans" + dateTimeRand)
    ryw.give_news("PHP file is generated at: ", logging.info)
    ryw.give_news(textfilePath, logging.info)

    try:
        outf = open(textfilePath, "w")
        outf.write("<?\n")
        outf.write("$trans_source = array(")
    except:
        ryw.give_bad_news("SelectTexts.py: unable to open output text file: " + textfilePath, logging.error)
        return None

    return outf
コード例 #2
0
def get_save_search_name():

    badResult = (False, None, None)
    tmpSearchResultDir = decide_search_result_dir()
    if not tmpSearchResultDir:
        ryw.give_bad_news('decide_search_result_dir failed.', logging.error)
        return badResult

    if not os.path.exists(tmpSearchResultDir):
        try:
            os.makedirs(tmpSearchResultDir)
        except:
            ryw.give_bad_news(
                'get_save_search_name: failed to create temporary ' +
                'search results directory: '+
                tmpSearchResultDir, logging.critical)
            return badResult

    if ryw_upload.check_free_space(tmpSearchResultDir,
				   supressWarning = True) <= 0:
        ryw.give_bad_news(
            'get_save_search_name: failed space check :' +
            tmpSearchResultDir, logging.error)
        return badResult

    name = ryw.date_time_rand()
    return (True, tmpSearchResultDir, name)
コード例 #3
0
def make_tmp_name(prefix1, prefix2, suffix):
    """
    prefix1 = oldDir = mywww = c:\Postmanet\nihao\WWW\repository?
    prefix2 = 'SearchFile_incoming'
    suffix = ''
    objPrefix = 'SearchFile_incoming' + dateTimeRand
    tmpdir = c:\Postmanet\nihao\WWW\repository\'SearchFile_incoming' + dateTimeRand
    """
    
    dateTimeRand = ryw.date_time_rand()
    objPrefix = prefix2 + dateTimeRand
    tmpdir = os.path.join(prefix1, objPrefix + suffix)
    return (tmpdir, objPrefix)
コード例 #4
0
def decide_path():
    resourcesPath = os.path.join(RepositoryRoot, 'Resources.txt')

    try:
        resources = ryw.get_resources(resourcesPath)
        tmpOutDir = ryw.get_resource_str(resources, 'tmpout')
        objectStoreRoot = ryw.get_resource_str(resources, 'objectstore')
        if not tmpOutDir or not objectStoreRoot:
            raise NameError('rebuildSearchFile: failed to get resources.')
        dateTimeRand = ryw.date_time_rand()
        newReverseListsFile = os.path.join(
            tmpOutDir, 'NewReverseLists' + dateTimeRand)
        return (True, newReverseListsFile, objectStoreRoot)
    except:
        ryw.give_bad_news('rebuildSearchFile: failed to get resources.')
        success = (False, None, None)
コード例 #5
0
def attempt_just_make_tmpdir(prefix1, prefix2, suffix):
    """attempts to make a temporary directory."""
    
    dateTimeRand = ryw.date_time_rand()

    objPrefix = prefix2 + dateTimeRand
    tmpdir = os.path.join(prefix1, objPrefix + suffix)

    try:
        os.makedirs(tmpdir)
    except:
        ryw.give_bad_news('fatal_error: failed to make temporary directory:'
                          + tmpdir, logging.critical)
        return (None, None)

    logging.debug('attempt_just_make_tmpdir: ' + tmpdir)
    return (tmpdir, objPrefix)
コード例 #6
0
def process_tricky_attributes(form, meta, filename):
    """hidden and obscure attributes."""

    meta['upload_datetime'] = repr(datetime.datetime.now())
    meta['upload_datetime_real'] = repr(datetime.datetime.now())
    #meta['upload_datetime'] = datetime.datetime.now()
    logging.debug('process_tricky_attributes: ' +
                  repr(meta['upload_datetime']))

    if not process_date_time(form, meta):
        return False    
    
    objectID = form.getfirst('object_ID', '')
    if not objectID:
        try:
            objectID = objectstore.generateNewObjectID()
        except:
            ryw.give_bad_news('fatal_error: unable to obtain new object ID.',
                              logging.critical)
            return False
    meta['id'] = objectID

    path = form.getfirst('path', '')
    if not path:
        contentType = form.getfirst('content_type', '')
        if not contentType:
            ryw.give_bad_news('fatal_error: unable to determine content type.',
                              logging.critical)
            return False
        now = datetime.datetime.now()
        monthStr = now.strftime('%y%m/')

        dateTimeRand = ryw.date_time_rand()
        filename = dateTimeRand + '_' + filename
        
        path = os.path.join('/upload', monthStr, contentType, filename)
    meta['path'] = os.path.normpath(path)
    ryw.db_print2('process_tricky_attributes: path is: ' + meta['path'], 57)
    
    return True
コード例 #7
0
def main():

    dateTimeRand = ryw.date_time_rand()
    searchfile = os.path.join(tmpOutDir, 'NewSearchFile' + dateTimeRand)
    osr = ObjectStoreRoot
    
    #ryw.give_news2('ObjectStore is at: ' + osr + '<BR>', logging.info)
    ryw.give_news2('new SearchFile at: ' + searchfile + '<BR>', logging.info)
    ryw.give_news2('generating... &nbsp;&nbsp;', logging.info)
    
    l = glob.glob(osr + "/?/?/?/?/*_META")
    for filename in l:
        meta = loadMeta(filename)
        append_to_new_search_file(searchfile,meta)

    ryw.give_news2('done.<BR>', logging.info)

    osf = OriginalSearchFile
    ryw.give_news2('comparing against ' + osf + ' ... <BR>', logging.info)
    compareSearchFile(osf, searchfile)

    ryw_view.print_footer()
コード例 #8
0
def main():

    #
    # get all the path names straight.
    #
    try:
        ntfsRoot = sys.argv[1]
    except:
        ryw.give_bad_news3(
            'usage: python reformat_ntfs.py /mnt/usb0/Postmanet ' +
            '[new_object_store_path]')
        sys.exit(-1)

    if len(sys.argv) >= 3:
        newObjStoreRoot = sys.argv[2]
    else:
        newObjStoreRoot = NEW_OBJECT_STORE_ROOT

    ryw.db_print3('newObjectStoreRoot is: ' + newObjStoreRoot, 62)
        
    if (not ntfsRoot) or (not os.path.exists(ntfsRoot)):
        ryw.give_bad_news3("can't find NTFS root: " + ntfsRoot)
        sys.exit(-1)

    ryw.db_print3('NTFS root is at: ' + ntfsRoot, 61)

    repositoryRoot = os.path.join(ntfsRoot, 'repository')
    oldSearchFileName = os.path.join(repositoryRoot, 'SearchFile')
    dateTimeRand = ryw.date_time_rand()
    newSearchFileName = os.path.join(repositoryRoot,
                                     'NewSearchFile' + dateTimeRand)

    objectStoreRoot = os.path.join(repositoryRoot, 'WWW',
                                   'ObjectStore')
    if (not os.path.exists(objectStoreRoot)):
        ryw.give_bad_news3("can't find object store: " + objectStoreRoot)
        sys.exit(-1)
    ryw.db_print3('object store root is at: ' + objectStoreRoot, 61)


    #
    # open the new search file.
    #
    try:
        newSearchFileHandle = open(newSearchFileName, 'ab')
    except:
        ryw.give_bad_news3('failed to open new search file: %s\n' % \
                           (searchfile,))
        sys.exit(-1)
    

    #
    # go through all the individual meta files.
    #
    l = glob.glob(objectStoreRoot + "/?/?/?/?/*_META")
    ryw.give_news3('rewriting meta data files...')
    for filename in l:
        ryw.db_print3('found meta: ' + filename, 61)
        meta = load_meta(filename)
        change_meta(meta, newObjStoreRoot)
        rewrite_meta(filename, meta)
        append_to_new_search_file(newSearchFileHandle, meta)



    #
    # replacing the old search file.
    #

    #ryw.copy_file_carefully('/u/rywang/tmp/x1',
    #                        '/u/rywang/tmp/x2',
    #                        '/u/rywang/tmp',
    #                        None,
    #                        'SearchFile_reformat')

    newSearchFileHandle.close()
    ryw.copy_file_carefully(oldSearchFileName, newSearchFileName,
                            repositoryRoot, None, 'SearchFile_reformat')
    ryw.give_news3('replacing search file: ' + oldSearchFileName +
                   ' <- ' + newSearchFileName)