def get_apache_path(): ryw.db_raise_or_print3("ryw_linux:get_apache_path() called.", 50) try: output = get_subprocess_output_line(["/usr/bin/which", "apache2"]) except: ryw.give_bad_news3("can't find apache.") output = "/dev/null" return output
def append_to_new_search_file(searchfileHandle, meta): f = searchfileHandle try: pickle.dump(meta, f) except: ryw.give_bad_news3('append_to_new_search_file : failed to append ' + repr(meta) + ' to search file: ' + searchfile) return False return True
def change_meta(meta, newObjStoreRoot): if not meta.has_key('objectstore'): ryw.give_bad_news3( 'meta has no object store: ' + meta['id'] + '#' + str(meta['version'])) ryw.give_bad_news3(' but continuing...') oldObjStore = '' else: oldObjStore = meta['objectstore'] ryw.db_print3(meta['id'] + '#' + str(meta['version']), 64) ryw.db_print3(oldObjStore, 64) meta['objectstore'] = newObjStoreRoot ryw.give_news3(meta['id'] + '#' + str(meta['version']) + ': ' + oldObjStore + ' -> ' + newObjStoreRoot)
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)