def iter_print_tree(s, tree, key, indent): branch = tree[key] for doc in branch['documents']: nameData = DCC.prop_get(s, doc, InfoSet='DocBasic') print(indent + doc) print(indent + ' DCC Title: ', nameData['title'], sep='') print(indent + ' TMT Doc. Num.: ', nameData['tmtnum'], sep='') print(indent + ' Owner: ', nameData['owner-name']) print(indent + ' Filename: ', nameData['filename'], sep='') print(indent + ' Date Modified: ', nameData['date'], sep='') print(indent + ' URL: ', 'https://docushare.tmt.org/docushare/dsweb/ServicesLib/', doc, '/View', sep='') for other in branch['others']: nameData = DCC.prop_get(s, other, InfoSet='Title') print(indent + other, ':', nameData['title']) for col in branch['collections']: nameData = DCC.prop_get(s, col, InfoSet='Title') print(indent + col, ':', nameData['title']) print(indent + ' URL: ', 'https://docushare.tmt.org/docushare/dsweb/ServicesLib/', col, sep='') iter_print_tree(s, tree, col, indent + ' ')
def move_object(s): obj = input("Enter Object Handle: ") source = input("Enter Collection Handle to Move From: ") dest = input("Enter Collection Handle to Move To: ") DCC.dcc_move(s, obj, source, dest) return
def fix_set(s, handle, set, **kwargs): # kwargs # ask = True | False, Do/Don't ask if changes should be made (!!! Dangerous !!!) # default is ask if 'Document-' in handle: fd = DCC.prop_get(s, handle, InfoSet = 'DocBasic') elif 'Collection-' in handle: fd = DCC.prop_get(s, handle, InfoSet = 'CollData') else: fd = DCC.prop_get(s, handle, InfoSet = 'Title') permdata = DCC.prop_get(s, handle, InfoSet = 'Perms') print(fd['handle'], ':', fd['title']) fd['permissions'] = permdata [removelist, changelist, addlist] = id_perm_changes(s,handle, fd, permdata, set) ch_flag = False if len(removelist) or len(changelist) or len(addlist): print('\n############## ENTRY ##############') if 'Document-' in handle: DCC.print_doc_basic(fd) elif 'Collection-' in handle: DCC.print_coll_data(fd) else: print('Not Document or Collection:', handle, ':', fd['title']) print('https://docushare.tmt.org/docushare/dsweb/ServicesLib/',handle,'/Permissions',sep='') DCC.print_perms(permdata) print('\nSuggested Changes...') print_perm_changes(removelist, changelist, addlist) make_perm_changes(s, handle, permdata, removelist, changelist, addlist, **kwargs)
def modify_dcc_perms(s, handle, permdata, **kwargs): ask_flag = kwargs.get('Ask',True) print('\n Modifying Permissions to:',handle) DCC.print_perms(permdata) if ask_flag == False or MyUtil.get_yn('Change Permissions (Y/N)?'): print('Changing permissions...') DCC.set_permissions(s, handle, permdata)
def make_cid(dirpath, CID_coll, htmlfile, outroot): # Get list of DCC documents from a Word file saved as html GetUrlWord.get_url_word(dirpath + outroot, dirpath + htmlfile) # Login to DCC prod = ['prod', 'production', 'p', ' '] tes = ['test', 'tes', 't'] checker = False print("Would you like to log into the production site or the test site?") print("Valid Inputs are as follows: Production, prod, p, test, t :", end="") choice = input().lower() #while loop to continue asking the user for input until a correct input has been entered while (checker == False): #Production site login choice if(choice in prod): print("You are now logging into the Production version of DocuShare") s = DCC.login(Site ='Production') checker = True #test site login choice elif(choice in tes): print("You are now logging into the test VM DocuShare") s = DCC.login(Site ='Test') checker = True #cf.dcc_url + cf.dcc_login #error message alerting user to enter a valid choice else: print("Please enter a valid choice, (P)roduction or (T)est") choice = input().lower() json_handlelist = dirpath + outroot + 'bothlist.txt' json_ssdata = dirpath + outroot + 'CID.txt' get_cid_ssdata(s, json_handlelist, json_ssdata) xlfile = dirpath + outroot + 'CID_Analysis.xls' write_spreadsheet(json_ssdata, xlfile) json_verlist = dirpath + outroot + 'ver_list.txt' json_doclist = dirpath + outroot + 'doc_list.txt' make_handle_lists(json_ssdata, json_doclist, json_verlist) ## Remove the files that are currently located in the collection for the CID if MyUtil.get_yn('Remove location (not delete) of files from ' + CID_coll[0] +'(Y/N)?: '): doclist = DCC.list_obj_in_coll(s, CID_coll[0],Print=True,Jwrite=False,Depth='infinity',Type='Doc') for doc in doclist: DCC.dcc_remove_doc_from_coll(s, doc, CID_coll[0]) ## Add CID files to the collection fh = open(json_doclist, 'r') dl = json.load(fh) fh.close() if MyUtil.get_yn('Add CID files to ' + CID_coll[0] +' (Y/N)?: '): DCC.add_docs_2_collections(s, dl, CID_coll) # Check that the expected docs are in the collection DCC.check_docs_in_coll(s, dl, CID_coll)
def id_perm_changes(s, handle, fd, permdata, set): removelist = [] changelist = [] addlist = [] if not check_fd_sel(fd, set) or not check_perm_sel(permdata, set): return([removelist,changelist,addlist]) for perm_act in set['PermAct']: # pass if no action is defined if not perm_act['Action']: pass elif perm_act['Action']['Action'] == 'Remove': for perm in permdata['perms']: if Match.parse(perm_act['Criteria'], perm): removelist.append(perm) elif perm_act['Action']['Action'] == 'Change': for perm in permdata['perms']: if Match.parse(perm_act['Criteria'], perm): # delete the old permission newperm = perm.copy() if 'Read' in perm: del(newperm['Read']) if 'Write'in perm: del(newperm['Write']) if 'Manage' in perm: del(newperm['Manage']) for key,val in perm_act['Action']['Perms'].items(): newperm[key] = val changelist.append(newperm) elif perm_act['Action']['Action'] == 'Add': addFlag = True for perm in permdata['perms']: if not Match.parse(perm_act['Criteria'], perm): addFlag = False if addFlag: pEntry = {} pEntry['handle'] = perm_act['Action']['Handle'] grpdata = DCC.prop_get(s, pEntry['handle'], InfoSet = 'Title') pEntry['name'] = grpdata['title'] if 'Read' in perm_act['Action']['Perms']: pEntry['Read'] = perm_act['Action']['Perms']['Read'] if 'Write' in perm_act['Action']['Perms']: pEntry['Write'] = perm_act['Action']['Perms']['Write'] if 'Manage' in perm_act['Action']['Perms']: pEntry['Manage'] = perm_act['Action']['Perms']['Manage'] addlist.append(pEntry) elif perm_act['Action']['Action'] == 'Message': for perm in permdata['perms']: if Match.parse(perm_act['Criteria'], perm): print(perm_act['Action']['Message']) DCC.print_perm(perm, LF = True) return([removelist, changelist, addlist])
def fix_permact(s, fd, handle, set, **kwargs): # kwargs # ask = True | False, Do/Don't ask if changes should be made (!!! Dangerous !!!) # default is ask [removelist, changelist, addlist] = id_perm_changes(s,handle, fd, fd['permissions'], set) ch_flag = False if len(removelist) or len(changelist) or len(addlist): DCC.print_perms(fd['permissions']) print('\nSuggested Changes...') print_perm_changes(removelist, changelist, addlist) make_perm_changes(s, handle, fd['permissions'], removelist, changelist, addlist, **kwargs)
def reviewColls(): set = top_level #creates sets that define the user choice to cover miscellaneous cases prod = ['prod', 'production', 'p', ' '] tes = ['test', 'tes', 't'] checker = False print("Would you like to log into the production site or the test site?") print("Valid Inputs are as follows: Production, prod, p, test, t :", end="") choice = input().lower() #while loop to continue asking the user for input until a correct input has been entered while (checker == False): #Production site login choice if(choice in prod): print("You are now logging into the Production version of DocuShare") s = DCC.login(Site ='Production') checker = True #test site login choice elif(choice in tes): print("You are now logging into the test VM DocuShare") s = DCC.login(Site ='Test') checker = True #cf.dcc_url + cf.dcc_login #error message alerting user to enter a valid choice else: print("Please enter a valid choice, (P)roduction or (T)est") choice = input().lower() yes = ['yes', 'y', 'ye'] #creates a new boolean variable to allow user to break from loop checker1 = False print("Please enter a collection number that you would like to create a sub-collection under") #checker1 only true when user enters correct information while(checker1 == False): col = input() parent = 'Collection-' + col fd = DCC.prop_get(s, parent , InfoSet = 'CollData', Print = True) print("Please enter the name of this new collection:") name = input() # double checks user to make sure that they would like to create this collection print("Are you sure that you want to create: " + name + " under " + parent) print("Valid Inputs are as follows: Yes, Y, No, N") ans = input().lower() # checks that user input is correct, if the answer is a valid form of yes # then the collection will be made and the user will break from the loop if(ans in yes): print("You are now making a collection named: " + name + " under " + parent ) checker1 = True createReviewColls(s, parent, set, name) else: print("Please re-enter a Collection number and Collection name")
def make_cid(dirpath, CID_coll, htmlfile, outroot): # Get list of DCC documents from a Word file saved as html GetUrlWord.get_url_word(dirpath + outroot, dirpath + htmlfile) # Login to DCC s = DCC.login(CF.dcc_url + CF.dcc_login) json_handlelist = dirpath + outroot + 'bothlist.txt' json_ssdata = dirpath + outroot + 'CID.txt' get_cid_ssdata(s, json_handlelist, json_ssdata) xlfile = dirpath + outroot + 'CID_Analysis.xls' write_spreadsheet(json_ssdata, xlfile) json_verlist = dirpath + outroot + 'ver_list.txt' json_doclist = dirpath + outroot + 'doc_list.txt' make_handle_lists(json_ssdata, json_doclist, json_verlist) ## Remove the files that are currently located in the collection for the CID if MyUtil.get_yn('Remove location (not delete) of files from ' + CID_coll[0] +'(Y/N)?: '): doclist = DCC.list_obj_in_coll(s, CID_coll[0],Print=True,Jwrite=False,Depth='infinity',Type='Doc') for doc in doclist: DCC.dcc_remove_doc_from_coll(s, doc, CID_coll[0]) ## Add CID files to the collection fh = open(json_doclist, 'r') dl = json.load(fh) fh.close() if MyUtil.get_yn('Add CID files to ' + CID_coll[0] +' (Y/N)?: '): DCC.add_docs_2_collections(s, dl, CID_coll) # Check that the expected docs are in the collection DCC.check_docs_in_coll(s, dl, CID_coll)
def check_perms(s, set, handles, **kwargs): ask_flag = kwargs.get('Ask', True) if not ask_flag: if not MyUtil.get_yn('!!! Warning !!! ask = False: Will not ask to make changes, okay? Enter N to Exit, Y to Continue:'): print('exiting...') sys.exit(0) for handle in handles: if 'Document-' in handle: fd = DCC.prop_get(s, handle, InfoSet = 'DocBasic') elif 'Collection-' in handle: fd = DCC.prop_get(s, handle, InfoSet = 'CollData') else: fd = DCC.prop_get(s, handle, InfoSet = 'Title') fd['permissions'] = DCC.prop_get(s, handle, InfoSet = 'Perms') # print(fd['handle'], ':', fd['title']) print('\n>>>>>>>>>>>>>> DCC Information <<<<<<<<<<<<<<') if 'Document-' in handle: DCC.print_doc_basic(fd) elif 'Collection-' in handle: DCC.print_coll_data(fd) else: print('Not Document or Collection:', handle, ':', fd['title']) print('\n\tDoc Properties URL: ',Tree.url_view(handle)) print('\tPermissions URL: ',Tree.url_perm(handle)) print('\tGet Document URL: ',Tree.url_access(handle)) print() fix_objact(s, fd, handle, set, **kwargs) fix_permact(s, fd, handle, set, **kwargs)
def build_tree(s, keyname, target, tree, **kwargs): # kwargs options: # Exclude - List of handles to not be included in the tree excludeList = kwargs.get("Exclude", []) documents = [] collections = [] others = [] dict = {} fd = DCC.prop_get(s, target, InfoSet="CollCont", Depth="1") for idx, d in enumerate(fd): handle = d["name"][1] if not handle in excludeList: if idx == 0: dict["parent"] = handle else: if "Document" in handle: documents.append(handle) elif "Collection" in handle: collections.append(handle) else: others.append(handle) dict["collections"] = collections dict["documents"] = documents dict["others"] = others tree[keyname] = dict for col in collections: if not col in excludeList: tree = build_tree(s, col, col, tree, **kwargs) return tree
def createReviewColls(s,handleParent, collNames, revName): for collName,subColl in collNames: collName = collName.replace('__NAME',revName) print('Creating:',handleParent,'->',collName) handleChild = DCC.make_collection(s, handleParent, collName, '') if len(subColl) > 0: createReviewColls(s, handleChild, subColl, revName)
def test_cache(): # Login to DCC s = DCC.login(CF.dcc_url + CF.dcc_login) handle = 'Collection-286' fname = 'Collection-286_CollData' [flag, fd] = check_cache_fd_json(s, handle, 'CollData', fname) print(flag, fd)
def test_fix_set(): # Login to DCC s = DCC.login(CF.dcc_url + CF.dcc_login) set = PERM_DEFS.setA handle = 'Document-27819' fix_set(s, handle, set)
def iter_print_tree(s, tree, key, indent): branch = tree[key] for doc in branch["documents"]: nameData = DCC.prop_get(s, doc, InfoSet="DocBasic") print(indent + doc) print(indent + " DCC Title: ", nameData["title"], sep="") print(indent + " TMT Doc. Num.: ", nameData["tmtnum"], sep="") print(indent + " Owner: ", nameData["owner-name"]) print(indent + " Filename: ", nameData["filename"], sep="") print(indent + " Date Modified: ", nameData["date"], sep="") print(indent + " URL: ", "https://docushare.tmt.org/docushare/dsweb/ServicesLib/", doc, "/View", sep="") for other in branch["others"]: nameData = DCC.prop_get(s, other, InfoSet="Title") print(indent + other, ":", nameData["title"]) for col in branch["collections"]: nameData = DCC.prop_get(s, col, InfoSet="Title") print(indent + col, ":", nameData["title"]) print(indent + " URL: ", "https://docushare.tmt.org/docushare/dsweb/ServicesLib/", col, sep="") iter_print_tree(s, tree, col, indent + " ")
def xls_tree_iter(s,ws,tree,col, **kwargs): global ssrow # Write and format the headings in Excel xls_tree_headings(ws) collData = DCC.prop_get(s, col, InfoSet = 'Title') branch = tree[col] keyword = kwargs.get('Keyword', '') for doc in branch['documents']: print(col,doc) docData = DCC.prop_get(s, doc, InfoSet = 'DocBasic') docData['Versions'] = DCC.prop_get(s,doc,InfoSet = 'Versions',WriteProp = True) if keyword in docData['keywords']: xls_print_ssrow(ws, collData, docData, ssrow) ssrow += 1 for newcol in branch['collections']: xls_tree_iter(s,ws,tree,newcol,**kwargs)
def iter_print_tree(s, tree, key, indent): branch = tree[key] for doc in branch['documents']: nameData = DCC.prop_get(s, doc, InfoSet = 'DocBasic') print(indent + doc) print(indent+' DCC Title: ',nameData['title'],sep='') print(indent+' TMT Doc. Num.: ',nameData['tmtnum'],sep='') print(indent+' Owner: ',nameData['owner-name']) print(indent+' Filename: ',nameData['filename'],sep='') print(indent+' Date Modified: ',nameData['date'],sep='') print(indent+' URL: ','https://docushare.tmt.org/docushare/dsweb/ServicesLib/',doc,'/View',sep='') for other in branch['others']: nameData = DCC.prop_get(s, other, InfoSet = 'Title') print(indent+other, ':', nameData['title']) for col in branch['collections']: nameData = DCC.prop_get(s, col, InfoSet = 'Title') print(indent+col, ':', nameData['title']) print(indent+' URL: ','https://docushare.tmt.org/docushare/dsweb/ServicesLib/',col,sep='') iter_print_tree(s, tree, col, indent+' ')
def abrir_magizoologo(nombre): with open(parametros.MAGIZOOLOGOS, "r", encoding="UTF-8") as file: for line in file: lista = line.split(",") if lista[0].upper() == nombre.upper(): lista[2] = int(lista[2]) lista[3] = lista[3].split(";") lista_dccriaturas = list() for nombre in lista[3]: criatura = abrir_criatura(nombre) if criatura[1] == parametros.AUGUREY: dccriatura = criaturas.Augurey( criatura[0], *criatura[2:len(criatura)]) elif criatura[1] == parametros.NIFFLER: dccriatura = criaturas.Niffler( criatura[0], *criatura[2:len(criatura)]) elif criatura[1] == parametros.ERKLING: dccriatura = criaturas.Erkling( criatura[0], *criatura[2:len(criatura)]) lista_dccriaturas.append(dccriatura) lista[3] = lista_dccriaturas lista[4] = lista[4].split(";") lista_alimentos = list() for alimento in lista[4]: if alimento == parametros.MALEZA: lista_alimentos.append(DCC.TartaMaleza()) elif alimento == parametros.DRAGON: lista_alimentos.append(DCC.HigadoDragon()) elif alimento == parametros.GUSARAJO: lista_alimentos.append(DCC.BuñueloGusarajo()) lista[4] = lista_alimentos lista[5] = bool(lista[5] == "True") lista[6] = int(lista[6]) lista[7] = int(lista[7]) lista[8] = int(lista[8]) lista[9] = int(lista[9]) lista[10] = bool(lista[10] == "True") return lista return []
def main(): # Login to DCC s = DCC.login(CF.dcc_url + CF.dcc_login) while True: com = input("Enter Command: ") if com.strip() == '': print('Exiting') break if com.upper() == 'COPY': copy_object(s) if com.upper() == 'MOVE': move_object(s)
def xls_tree_iter(s, ws, tree, col, **kwargs): global ssrow # Write and format the headings in Excel xls_tree_headings(ws) collData = DCC.prop_get(s, col, InfoSet='Title') branch = tree[col] keyword = kwargs.get('Keyword', '') for doc in branch['documents']: print(col, doc) docData = DCC.prop_get(s, doc, InfoSet='DocBasic') docData['Versions'] = DCC.prop_get(s, doc, InfoSet='Versions', WriteProp=True) if keyword in docData['keywords']: xls_print_ssrow(ws, collData, docData, ssrow) ssrow += 1 for newcol in branch['collections']: xls_tree_iter(s, ws, tree, newcol, **kwargs)
def make_perm_changes(s, handle, permdata, removelist, changelist, addlist, **kwargs): ask_flag = kwargs.get('Ask',True) mod_flag = False if ask_flag == True: ans = MyUtil.get_all_none_indiv('Make Changes? All/None/Individual (A/N/I)?') if ans == 'All': ask_flag = False elif ans == 'None': return for perm in removelist: print('Remove?: ',end='') DCC.print_perm(perm) if ask_flag == False or MyUtil.get_yn(': (Y/N)?'): if ask_flag == False: print() mod_flag = True MyUtil.remove_dict_from_list(permdata['perms'],'handle',perm['handle']) for chperm in changelist: print('Change?:', end='') DCC.print_perm(chperm) if ask_flag == False or MyUtil.get_yn(': (Y/N)?'): if ask_flag == False: print() mod_flag = True for perm in permdata['perms']: if perm['handle'] == chperm['handle']: if 'Read' in perm: del(perm['Read']) if 'Write'in perm: del(perm['Write']) if 'Manage' in perm: del(perm['Manage']) for key,val in chperm.items(): perm[key] = val for addperm in addlist: print('Add?:', end='') DCC.print_perm(addperm) if ask_flag == False or MyUtil.get_yn(': (Y/N)?'): if ask_flag == False: print() mod_flag = True permdata['perms'].append(addperm) if debug: DCC.print_perms(permdata) if mod_flag: # check ask_flag since it may have been modified from kwargs value if ask_flag == False: modify_dcc_perms(s, handle, permdata, Ask=False) else: modify_dcc_perms(s,handle,permdata, **kwargs)
def check_cache_okay(s, handle, fname, path = CF.dccfilepath): if not '.json' in fname: fname = fname + '.json' if not os.path.isfile(path+fname): return(False) if debug: print('File Exists') if 'NoDateCheck' in cacheMode or 'All' in cacheMode: dccDate = "Sat, 01 Jan 2000 00:00:00 GMT" else: fd = DCC.prop_get(s, handle, InfoSet = 'DocDate') dccDate = fd['date'] if not check_date_okay(dccDate, os.path.getctime(path+fname)): return(False) return(True)
def print_perm_changes(removelist, changelist, addlist): for perm in removelist: print('??? Remove ??? :',end='') DCC.print_perm(perm,LF=True) for perm in changelist: print('??? Change ??? :',end='') DCC.print_perm(perm,LF=True) for perm in addlist: print('??? Add ??? :',end='') DCC.print_perm(perm,LF=True) print()
def test_tree(): collhandle = 'Collection-286' exclude = ['Collection-7337', 'Document-21244', 'Document-26018'] # Login to DCC s = DCC.login(CF.dcc_url + CF.dcc_login) print('excluding:', exclude) tree = get_tree(s, collhandle, Exclude=exclude) print_tree(s, tree) print('\n\n') for branch in tree: print(branch + ': ', tree[branch]) fl = flat_tree(tree, 'root', []) print(fl)
def test_tree(): collhandle = "Collection-286" exclude = ["Collection-7337", "Document-21244", "Document-26018"] # Login to DCC s = DCC.login(CF.dcc_url + CF.dcc_login) print("excluding:", exclude) tree = get_tree(s, collhandle, Exclude=exclude) print_tree(s, tree) print("\n\n") for branch in tree: print(branch + ": ", tree[branch]) fl = flat_tree(tree, "root", []) print(fl)
def test_tree(): collhandle = 'Collection-286' exclude = ['Collection-7337','Document-21244', 'Document-26018'] # Login to DCC s = DCC.login(CF.dcc_url + CF.dcc_login) print('excluding:',exclude) tree = get_tree(s, collhandle, Exclude = exclude) print_tree(s,tree) print('\n\n') for branch in tree: print(branch+': ',tree[branch]) fl = flat_tree(tree, 'root', []) print(fl)
def test_bulletin_post(): # Login to DCC s = DCC.login(CF.dcc_url + CF.dcc_login) handle = 'Bulletin-6185' title = '_DISPOSITION' description = 'This item is open. MELCO made no reply.' # description = 'This can be closed with a tracked action' # description = "The reply doesn't answer directly to the question of the RIX. The reply seems to say that DP04S-A isn't a document to be reviewed. Is DP04S-A a review item of FDRP2? Need more clear reply." keywords = 'Reviewer Disposition' create_bb_post(s, title, description, keywords, handle) title = '_ACTION' description = 'ACTION: TBD (To Be Determined) after issue is addressed by MELCO.' # description = 'ACTION: MELCO to study what is the probability of the scenario.' # description = "ACTION: MELCO to add all the safety related drives to the Table 2.1-1." keywords = 'Reviewer ACTION' create_bb_post(s, title, description, keywords, handle)
def build_tree(s, keyname, target, tree, **kwargs): # kwargs options: # Exclude - List of handles to not be included in the tree excludeList = kwargs.get('Exclude', []) documents = [] collections = [] others = [] dict = {} fd = DCC.prop_get(s, target, InfoSet='CollCont', Depth='1') for idx, d in enumerate(fd): handle = d['name'][1] print(handle) if not handle in excludeList: if idx == 0: dict['parent'] = handle else: if 'Document' in handle: documents.append(handle) elif 'Collection' in handle: collections.append(handle) else: others.append(handle) dict['collections'] = collections dict['documents'] = documents dict['others'] = others tree[keyname] = dict for col in collections: if not col in excludeList: tree = build_tree(s, col, col, tree, **kwargs) return (tree)
def build_tree(s, keyname, target, tree, **kwargs): # kwargs options: # Exclude - List of handles to not be included in the tree excludeList = kwargs.get('Exclude',[]) documents = [] collections = [] others = [] dict = {} fd = DCC.prop_get(s, target, InfoSet = 'CollCont', Depth = '1') for idx,d in enumerate(fd): handle = d['name'][1] print(handle) if not handle in excludeList: if idx == 0: dict['parent'] = handle else: if 'Document' in handle: documents.append(handle) elif 'Collection' in handle: collections.append(handle) else: others.append(handle) dict['collections'] = collections dict['documents'] = documents dict['others'] = others tree[keyname] = dict for col in collections: if not col in excludeList: tree = build_tree(s, col, col, tree, **kwargs) return(tree)
import criaturas import zoologos import DCC import parametros import funciones from random import randint condicion_general = True condicion_menu_inicio = True condicion_elegir_criatura = False condicion_crear_magizoologo = False condicion_menu_acciones = False condicion_menu_dccriaturas = False condicion_menu_dcc = False dcc = DCC.Dcc() print("Bienvenido a DCCriaturas Fantasticas") while condicion_general: while condicion_menu_inicio: print("[1] Crear magizoologo") print("[2] Cargar magizoologo") print("[0] Salir") opcion_seleccionada = input("Seleccione una opcion (1, 2 o 0):") if opcion_seleccionada == "1": condicion_crear = True while condicion_crear: nombre = input("Seleccione un nombre para su magizoologo") if funciones.validar_usuario(nombre): condicion_crear_magizoologo = True while condicion_crear_magizoologo: print("[1] Docencio") print("[2] Tareo")
#!/usr/bin/env python3 # external modules import re # my modules import DCC import Config as CF import Tree import MyUtil s = DCC.login(CF.dcc_url + CF.dcc_login) top_collection = 'Collection-4325' while True: cr_coll = input('\n>>>> Enter a Collection number (e.g. 1234) or Q to quit: ') if 'Q' in cr_coll.upper(): print('\n\n....Quitting') exit(0) # if 'L' in cr_coll.upper(): # print('\n\n....Listing Collections') # tree = Tree.get_tree(s, top_collection) # Tree.print_tree(s,tree) # break cr_coll = 'Collection-' + cr_coll print('\n') fd = DCC.prop_get(s, cr_coll, InfoSet = 'CollData')
continue else: return True return False #配置交换机表 switchtable = { '127.0.0.1:12100':'127.0.0.1:11102', '127.0.0.1:11200':'127.0.0.1:11101' } #初始化路由表 Atable = [] routetable.addTable(('127.0.0.1',12000),("127.0.0.1",12100),1,Atable) a1 = DCC.Unit() #第一个是本地,后两个乱绑定,不会动用它里面的发送函数 local = ('127.0.0.1',11100) a1.debug4(local,('127.0.0.1',19986),('127.0.0.1',19985)) readable = [a1.sk] repeat = '' print('start to host......') while(1): #随机交换路由表 num = randint(1,10) if(num==3): packaged = routetable.packageTables(Atable).encode() waitForChunk = a1.bin2Frames(a1.bytes2Bin(packaged),306) afterChunk = a1.dataWrap(waitForChunk[0],randint(0,254)) a1.datalink = ('127.0.0.1',11102)
def checkPerms(target, permissions): # Login to DCC s = DCC.login(CF.dcc_url + CF.dcc_login) if 'Collection' in target: tr = Tree.get_tree(s,target) Tree.print_tree(s, tr) docList = Tree.get_flat_tree(tr) else: docList = [target] printCheckCriteria(target, permissions) passList = [] failList = [] for doc in docList: checkFlag = True if 'Document' in doc: fd = DCC.prop_get(s, doc, InfoSet = 'DocBasic') fd['permissions'] = DCC.prop_get(s, doc, InfoSet = 'Perms', Depth = '0') print("\n\n*** Document Entry", fd['handle'], "***") print("DCC Name: \"",fd['title'],"\"",sep="") print("TMT Document Number: ", fd['tmtnum']) print("https://docushare.tmt.org/docushare/dsweb/ServicesLib/" + fd['handle'] + "/view") elif 'Collection' in doc: fd = DCC.prop_get(s, doc, InfoSet = 'CollData') fd['permissions'] = DCC.prop_get(s, doc, InfoSet = 'Perms', Depth = '0') print("\n\n*** Collection Entry", fd['handle'], "***") print("https://docushare.tmt.org/docushare/dsweb/ServicesLib/" + fd['handle'] + "/view") else: checkFlag = False print("\nNot checking permissions on object that is not a Collection or Document):",doc) if checkFlag: OkayPerms = [] for perm in sorted(fd["permissions"]["perms"], key = lambda x: x["handle"]): # Go through each set and create a dictionary of entries that have perms okay for sets in permissions: for item,plist in sets.items(): if perm["handle"] == item: if printCheckPerms(perm,plist) == True: OkayPerms.append(item) permFlag = False for sets in permissions: testFlag = True for item in sets: if not item in OkayPerms: testFlag = False if testFlag == True: permFlag = True if permFlag == True: print("*** PERMISSIONS MEET CRITERIA ***") passList.append(doc) else: print("!!! PERMISSIONS DO NOT MEET CRITERIA !!!") failList.append(doc) return([passList,failList])
def get_discussion_rowcol(url, htmlfile, xlfile, ssrow, sscol): # Login to DCC and save the discussion as an html file s = DCC.login(CF.dcc_url + CF.dcc_login) res = s.get(url) res.raise_for_status() webfile = open(CF.dccfilepath + htmlfile, 'wb') for chunk in res.iter_content(100000): webfile.write(chunk) webfile.close # Get the HTML into the Beautiful Soup object dcc = open(CF.dccfilepath + htmlfile, 'r', encoding='utf-8').read() dom = BeautifulSoup(dcc, "html.parser") # Open the spreadsheet try: wb = load_workbook(xlfile) print('Opened existing file :', xlfile) existing_doc = True except: wb = openpyxl.Workbook() print('Created new file :', xlfile) existing_doc = False ws = wb.worksheets[0] # Write and format the headings in Excel if this is a new document set_ss_headings(ws, ssrow, sscol) # Find the Parent of all the original posts (that may have replies) # This is <form name="ToolbarMulti" method="post" action="/docushare/dsweb/ProcessMultipleCommand"> form_tag = dom.find("form", {"name": "ToolbarMulti"}) rowoff = ssrow ssrow = ssrow + 1 # Now find all the children that are Post Entries for idx, postentry in enumerate( form_tag.find_all("div", class_="postentry", recursive=False)): [title, url, author, auth_url, dt, post] = get_postentry_author_info(postentry) # post is the text of the original posting. # Look for replies to posts # The replyposts class is always the next sibling replies = postentry.find_next_sibling() # count the number of replies times = 0 reps = [] r_dates = [dt] r_latest = '' r_title = '' r_disposition = '' r_action = '' for replyentry in replies.find_all("div", class_="postentry"): [r_title, r_url, r_author, r_auth_url, r_dt, r_latest] = get_postentry_author_info(replyentry) # Put results into a list with line breaks reps.append(r_author + ': ' + r_dt.strftime('%y-%m-%d %H:%M')) r_dates.append(r_dt) if '_DISPOSITION' in r_title.upper(): # print('r_disposition is :', r_latest) r_disposition = r_latest if '_ACTION' in r_title.upper(): # print('r_action is :', r_latest) r_action = r_latest times += 1 # Turn the reps list into a single string repstr = ';\n'.join(reps) # Find the latest modified date r_dates.sort() r_date_latest = r_dates[-1] r_date_latest_str = r_date_latest.strftime('%y-%m-%d %H:%M') # Print output print('\nEntry:', idx) print('title:', title) print('url:', url) print('posting:', post) print('author:', author) print('date:', dt.strftime('%y-%m-%d %H:%M')) if repstr != '': print('latest update:', r_date_latest_str) print('replies by:', repstr) print('latest reply title:', r_title) print('latest reply:', r_latest) if r_disposition != '': print('Disposition:', r_disposition) if r_action != '': print('Action:', r_action) # Column 1: ID col = sscol ws.cell(row=ssrow, column=col).value = ssrow - rowoff ws.cell(row=ssrow, column=col).alignment = align_hv_cen_style # Column 2: Title col += 1 ws.cell(row=ssrow, column=col).value = title ws.cell(row=ssrow, column=col).font = font_url_style ws.cell(row=ssrow, column=col).hyperlink = url ws.cell(row=ssrow, column=col).alignment = Alignment(wrap_text=True, vertical='center') # Column 3: Posting col += 1 ws.cell(row=ssrow, column=col).value = clean_string(post) ws.cell(row=ssrow, column=col).alignment = Alignment(wrap_text=True, vertical='center') # Column 4: Author col += 1 ws.cell(row=ssrow, column=col).value = author ws.cell(row=ssrow, column=col).hyperlink = auth_url ws.cell(row=ssrow, column=col).alignment = align_ver_cen_style ws.cell(row=ssrow, column=col).font = font_url_style # Column 5: Post Date col += 1 ws.cell(row=ssrow, column=col).value = dt ws.cell(row=ssrow, column=col).number_format = 'YY-MM-DD HH:MM' ws.cell(row=ssrow, column=col).alignment = align_hv_cen_style # Column 6: # Replies col += 1 ws.cell(row=ssrow, column=col).value = times ws.cell(row=ssrow, column=col).alignment = align_hv_cen_style # Column 7: Replies By col += 1 ws.cell(row=ssrow, column=col).value = repstr ws.cell(row=ssrow, column=col).alignment = Alignment(wrap_text=True, vertical='center') # Column 8: Latest Reply Date col += 1 ws.cell(row=ssrow, column=col).value = r_date_latest_str ws.cell(row=ssrow, column=col).alignment = align_hv_cen_style #Column 9: Latest Reply Text col += 1 ws.cell(row=ssrow, column=col).value = clean_string(r_latest) ws.cell(row=ssrow, column=col).alignment = Alignment(wrap_text=True, vertical='center') #Column 10: Disposition Text col += 1 ws.cell(row=ssrow, column=col).value = clean_string(r_disposition) ws.cell(row=ssrow, column=col).alignment = Alignment(wrap_text=True, vertical='center') #Column 11: Action Text col += 1 ws.cell(row=ssrow, column=col).value = clean_string(r_action) ws.cell(row=ssrow, column=col).alignment = Alignment(wrap_text=True, vertical='center') ssrow += 1 # Set column widths ws.column_dimensions["A"].width = 5.0 ws.column_dimensions["B"].width = 40.0 ws.column_dimensions["C"].width = 60.0 ws.column_dimensions["D"].width = 13.0 ws.column_dimensions["E"].width = 13.0 ws.column_dimensions["F"].width = 13.0 ws.column_dimensions["G"].width = 25.0 ws.column_dimensions["H"].width = 17.0 ws.column_dimensions["I"].width = 60.0 ws.column_dimensions["J"].width = 60.0 ws.column_dimensions["K"].width = 60.0 # Save the spreadsheet wb.save(xlfile)
def get_group_handles(s,grp): fd = DCC.prop_get(s, grp, InfoSet = 'Group', Print = True, WriteProp = True) chandles = [] for c in fd['children']: chandles.append(c[0]) return(chandles)
def make_cid(dirpath, CID_coll, htmlfile, outroot): # Get list of DCC documents from a Word file saved as html GetUrlWord.get_url_word(dirpath + outroot, dirpath + htmlfile) # Login to DCC prod = ['prod', 'production', 'p', ' '] tes = ['test', 'tes', 't'] checker = False print("Would you like to log into the production site or the test site?") print("Valid Inputs are as follows: Production, prod, p, test, t :", end="") choice = input().lower() #while loop to continue asking the user for input until a correct input has been entered while (checker == False): #Production site login choice if (choice in prod): print( "You are now logging into the Production version of DocuShare") s = DCC.login(Site='Production') checker = True #test site login choice elif (choice in tes): print("You are now logging into the test VM DocuShare") s = DCC.login(Site='Test') checker = True #cf.dcc_url + cf.dcc_login #error message alerting user to enter a valid choice else: print("Please enter a valid choice, (P)roduction or (T)est") choice = input().lower() json_handlelist = dirpath + outroot + 'bothlist.txt' json_ssdata = dirpath + outroot + 'CID.txt' get_cid_ssdata(s, json_handlelist, json_ssdata) xlfile = dirpath + outroot + 'CID_Analysis.xls' write_spreadsheet(json_ssdata, xlfile) json_verlist = dirpath + outroot + 'ver_list.txt' json_doclist = dirpath + outroot + 'doc_list.txt' make_handle_lists(json_ssdata, json_doclist, json_verlist) ## Remove the files that are currently located in the collection for the CID if MyUtil.get_yn('Remove location (not delete) of files from ' + CID_coll[0] + '(Y/N)?: '): doclist = DCC.list_obj_in_coll(s, CID_coll[0], Print=True, Jwrite=False, Depth='infinity', Type='Doc') for doc in doclist: DCC.dcc_remove_doc_from_coll(s, doc, CID_coll[0]) ## Add CID files to the collection fh = open(json_doclist, 'r') dl = json.load(fh) fh.close() if MyUtil.get_yn('Add CID files to ' + CID_coll[0] + ' (Y/N)?: '): DCC.add_docs_2_collections(s, dl, CID_coll) # Check that the expected docs are in the collection DCC.check_docs_in_coll(s, dl, CID_coll)
docmodreport.append('dccDocTitle') docmodreport.append('dccShortTitle') docmodreport.append('dccDocNo') docmodreport.append('dccDocRev') docmodreport.append('DocumentRev') docmodreport.append('DocType') docmodreport.append('CADDocumentNo') docmodreport.append('dccDocHandleHyperlink') docmodreport.append('dccDocVersionHyperlink') docmodreport.append('dccDocSignedApproved') docmodreport.append('TMTPublished') docmodreport.append('dccDocStatus') docmodreport.append('dccStatusCheckDate') docmodreport.append('dccDocHandleNo') s = DCC.login(CF.dcc_url + CF.dcc_login) docmodlist = [] pub_coll = 'Collection-8277' tr = Tree.return_tree(s, pub_coll, 'Tree_' + pub_coll) pub_list = Tree.get_flat_tree(tr) docmatch = {} for ref in reflist.items(): print('looking for ', ref[0], ref[1]) for doc in dm.items(): if DocMod.is_in_dict(ref[1],doc[1]): print('\n\n\n############## Found Document Module Object #:', doc[0], '##############\n')
def copy_object(s): obj = input("Enter Object Handle: ") col = input("Enter Collection Handle to Copy To: ") DCC.add_docs_2_collections(s, [obj], [col]) return
def testTraverse(): # Login to DCC s = DCC.login(CF.dcc_url + CF.dcc_login) coll = 'Collection-286' create_DCC_mirror(s, coll, '/Users/sroberts/Box Sync/TMT DCC Files/Test/', SaveFiles = True, MaxFileSize = 2000000)
tree = get_tree(s, collhandle, Exclude=exclude) print_tree(s, tree) print('\n\n') for branch in tree: print(branch + ': ', tree[branch]) fl = flat_tree(tree, 'root', []) print(fl) if __name__ == '__main__': print("Running module test code for", __file__) # test_tree() # Login to DCC s = DCC.login(CF.dcc_url + CF.dcc_login) # froot = 'Listing of Scott Collection' # coll = 'Collection-286' # froot = 'Listing M1CS Preliminary Design Review Collections' # coll = 'Collection-10725' # # tr = return_tree(s, coll, froot) # # print_tree(s,tr) # html_tree(s,tr,froot) # load_flag = True # froot = 'Listing of WFOS for Suijian' # coll = 'Collection-7798'
def hab_especial(self, zoologo): if self.estado_hambre == parametros.SATISFECHA and self.salud == self.salud_max: lista_alimentos = [DCC.TartaMaleza(), DCC.HigadoDragon(), DCC.BuñueloGusarajo()] alimento = lista_alimentos[randint(0, 2)] zoologo.alimentos.append(alimento) print(self.nombre, "te ha traido de regalo:", alimento)
def detect(): parser = argparse.ArgumentParser( description="circular RNA detection", fromfile_prefix_chars="@", ) parser.add_argument("--version", action="version", version=version) parser.add_argument("Command", choices=['detect']) parser.add_argument( "Input", metavar="Input", nargs="+", help= "Input of the Chimeric.out.junction file from STAR. Alternatively, a sample sheet " "specifying where your chimeric.out.junction files are, each sample per line, " "provide with @ prefix (e.g. @samplesheet)") parser.add_argument( "-k", "--keep-temp", dest="temp", action="store_true", default=False, help="Temporary files will not be deleted [default: False]") parser.add_argument( "-T", "--threads", dest="cpu_threads", type=int, default=2, help="Number of CPU threads used for computation [default: 2]") parser.add_argument("-O", "--output", dest="out_dir", default="./", help="DCC output directory [default: .]") parser.add_argument( "-t", "--temp", dest="tmp_dir", default="_tmp_DCC/", help="DCC temporary directory [default: _tmp_DCC/]") group = parser.add_argument_group( "Find circRNA Options", "Options to find circRNAs from STAR output") group.add_argument( "-D", "--detect", action="store_true", dest="detect", default=False, help= "Enable circRNA detection from Chimeric.out.junction files [default: False]" ) group.add_argument( "-ss", action="store_true", dest="secondstrand", default=False, help= "Must be enabled for stranded libraries, aka 'fr-secondstrand' [default: False]" ) group.add_argument( "-N", "--nonstrand", action="store_false", dest="strand", default=True, help="The library is non-stranded [default stranded]") group.add_argument( "-E", "--endTol", dest="endTol", type=int, default=5, choices=range(0, 10), help= "Maximum base pair tolerance of reads extending over junction sites [default: 5]" ) group.add_argument( "-m", "--maximum", dest="max", type=int, default=1000000, help= "The maximum length of candidate circRNAs (including introns) [default: 1000000]" ) group.add_argument( "-n", "--minimum", dest="min", type=int, default=30, help= "The minimum length of candidate circRNAs (including introns) [default 30]" ) group.add_argument( "-an", "--annotation", dest="annotate", help="Gene annotation file in GTF/GFF3 format, to annotate " "circRNAs by their host gene name/identifier") group.add_argument( "-Pi", "--PE-independent", action="store_true", dest="pairedendindependent", default=False, help= "Has to be specified if the paired end mates have also been mapped separately." "If specified, -mt1 and -mt2 must also be provided [default: False]" ) group.add_argument( "-mt1", "--mate1", dest="mate1", nargs="+", help= "For paired end data, Chimeric.out.junction files from mate1 independent mapping result" ) group.add_argument( "-mt2", "--mate2", dest="mate2", nargs="+", help= "For paired end data, Chimeric.out.junction files from mate2 independent mapping result" ) parser.add_argument_group(group) group = parser.add_argument_group( "Filtering Options", "Options to filter the circRNA candidates") group.add_argument( "-F", "--filter", action="store_true", dest="filter", default=False, help= "If specified, the program will perform a recommended filter step on the detection results" ) group.add_argument( "-f", "--filter-only", dest="filteronly", nargs=2, help= "If specified, the program will only filter based on two files provided: " "1) a coordinates file [BED6 format] and 2) a count file. E.g.: -f example.bed counts.txt" ) group.add_argument( "-M", "--chrM", action="store_true", dest="chrM", default=False, help= "If specified, circRNA candidates located on the mitochondrial chromosome will be removed" ) group.add_argument( "-R", "--rep_file", dest="rep_file", help="Custom repetitive region file in GTF format to filter out " "circRNA candidates in repetitive regions") group.add_argument( "-L", "--Ln", dest="length", type=int, default=50, help= "Minimum length in base pairs to check for repetitive regions [default 50]" ) group.add_argument( "-Nr", nargs=2, type=int, metavar=("countthreshold", "replicatethreshold"), default=[2, 5], help="countthreshold replicatethreshold [default: 2,5]") group.add_argument( "-fg", "--filterbygene", action="store_true", dest="filterbygene", default=False, help= "If specified, filter also by gene annotation (candidates are not allowed to span" " more than one gene) default: False") parser.add_argument_group(group) group = parser.add_argument_group( "Host gene count Options", "Options to count host gene expression") group.add_argument( "-G", "--gene", action="store_true", dest="gene", default=False, help= "If specified, the program will count host gene expression given circRNA coordinates " "[default: False]") group.add_argument( "-C", "--circ", dest="circ", help= "User specified circRNA coordinates, any tab delimited file with first three " "columns as circRNA coordinates: chr\tstart\tend, which DCC will use to count " "host gene expression") group.add_argument( "-B", "--bam", dest="bam", nargs="+", help= "A file specifying the mapped BAM files from which host gene expression is computed; " "must have the same order as input chimeric junction files") group.add_argument("-A", "--refseq", dest="refseq", help="Reference sequence FASTA file") parser.add_argument_group(group) import DCC DCC.main(parser)
#!/usr/bin/env python3 import Tree import DCC # This script can be used to create an html list and a spreadsheet of documents below the # specified collection. The main use of the code is to create CID lists in html and spreadsheet # from from a set of collections containing CID files froot = 'Listing of STR CID' coll = 'Collection-10669' # Login to DCC s = DCC.login(Site='Production') tr = Tree.return_tree(s, coll, froot) Tree.xls_tree(s, tr, coll, froot) Tree.html_tree(s, tr, froot)
def iter_html_tree(s, htmlfile, tree, key, indent, **kwargs): branch = tree[key] keyword = kwargs.get('Keyword', '') for doc in branch['documents']: nameData = DCC.prop_get(s, doc, InfoSet='DocBasic') if keyword in nameData['keywords']: print(doc) print('<div style="text-indent: ', str(indent), 'em;">', file=htmlfile, sep='') print('<p>', file=htmlfile, sep='') print(href_str(nameData['title'], url_access(doc)), file=htmlfile, sep='') print('[', file=htmlfile, sep='') print(href_str(doc, url_view(doc)), file=htmlfile, sep='') print(', ', file=htmlfile, sep='') print(href_str('Perm', url_perm(doc)), file=htmlfile, sep='') print(', ', file=htmlfile, sep='') print(href_str('Ver', url_ver(doc)), file=htmlfile, sep='') print(', ', file=htmlfile, sep='') print(href_str('Loc', url_loc(doc)), file=htmlfile, sep='') print(']', file=htmlfile, sep='') print('</p>', file=htmlfile, sep='') print('</div>', file=htmlfile, sep='') print('<div style="text-indent: ', str(indent + 2), 'em;">', file=htmlfile, sep='') print('<p>TMT Doc. Num.: ', nameData['tmtnum'], '</p>', file=htmlfile, sep='') print('<p>Owner: ', nameData['owner-name'], file=htmlfile, sep='') print('<p>Filename: ', nameData['filename'], file=htmlfile, sep='') print('<p>Date Modified: ', nameData['date'], file=htmlfile, sep='') print('</div>', file=htmlfile, sep='') for other in branch['others']: print(other) nameData = DCC.prop_get(s, other, InfoSet='Title') print('<div style="text-indent: ', str(indent), 'em;">', file=htmlfile, sep='') print('<p>', file=htmlfile, sep='') print('[', file=htmlfile, sep='') print(href_str(other, url_access(other)), file=htmlfile, sep='') print(']', file=htmlfile, sep='') print(href_str(nameData['title'], url_view(other)), file=htmlfile, sep='') print('[', file=htmlfile, sep='') print(href_str('Perm', url_perm(other)), file=htmlfile, sep='') print(']', file=htmlfile, sep='') print('</p>', file=htmlfile, sep='') print('</div>', file=htmlfile, sep='') for col in branch['collections']: print(col) nameData = DCC.prop_get(s, col, InfoSet='Title') print('<div style="text-indent: ', str(indent), 'em;">', file=htmlfile, sep='') print('<p></p>', file=htmlfile, sep='') print('<p>', file=htmlfile, sep='') print(href_str(nameData['title'], url_access(col)), file=htmlfile, sep='') print('[', file=htmlfile, sep='') print(href_str(col, url_view(col)), file=htmlfile, sep='') print(', ', file=htmlfile, sep='') print(href_str('Perm', url_perm(col)), file=htmlfile, sep='') print(', ', file=htmlfile, sep='') print(href_str('Ver', url_ver(col)), file=htmlfile, sep='') print(', ', file=htmlfile, sep='') print(href_str('Loc', url_loc(col)), file=htmlfile, sep='') print(']', file=htmlfile, sep='') print('</p>', file=htmlfile, sep='') print('</div>', file=htmlfile, sep='') iter_html_tree(s, htmlfile, tree, col, indent + 2, **kwargs)
args.torchmodel = 'checkpoint_{}.pth.tar'.format(index) extract_feature.main(args, net=net) args.g = 'pretrained.mat' args.out = 'pretrained' args.feat = 'pretrained.pkl' copyGraph.main(args) args.batchsize = cfg.PAIRS_PER_BATCH #args.batchsize = 256 args.resume = False args.level = 180 args.nepoch = 30000 args.M = 20 args.lr = 0.001 out = DCC.main(args, net=net) print('Done') exit(0) # Z=Y initial cur_dir = str(pathlib.Path().absolute()) out = sio.loadmat(cur_dir + '/features') Z = out['Z'] labels = out['gtlabels'].squeeze() ''' feat_cols = [str(i) for i in range(Z.shape[1])] df = pd.DataFrame(Z, columns=feat_cols) df['y'] = labels df['label'] = df['y'].apply(lambda i: str(i))
def get_discussion_rowcol(url, htmlfile, xlfile, ssrow, sscol): # Login to DCC and save the discussion as an html file s = DCC.login(CF.dcc_url + CF.dcc_login) res = s.get(url) res.raise_for_status() webfile = open(CF.dccfilepath + htmlfile,'wb') for chunk in res.iter_content(100000): webfile.write(chunk) webfile.close # Get the HTML into the Beautiful Soup object dcc=open(CF.dccfilepath + htmlfile,'r',encoding='utf-8').read() dom = BeautifulSoup(dcc, "html.parser") # Open the spreadsheet try: wb = load_workbook(xlfile) print('Opened existing file :', xlfile) existing_doc = True except: wb = openpyxl.Workbook() print('Created new file :', xlfile) existing_doc = False ws = wb.worksheets[0] # Write and format the headings in Excel if this is a new document set_ss_headings(ws, ssrow, sscol) # Find the Parent of all the original posts (that may have replies) # This is <form name="ToolbarMulti" method="post" action="/docushare/dsweb/ProcessMultipleCommand"> form_tag = dom.find("form", {"name":"ToolbarMulti"}) rowoff = ssrow ssrow = ssrow + 1 # Now find all the children that are Post Entries for idx, postentry in enumerate(form_tag.find_all("div", class_ = "postentry", recursive = False)): [title, url, author, auth_url, dt, post] = get_postentry_author_info( postentry ) # post is the text of the original posting. # Look for replies to posts # The replyposts class is always the next sibling replies = postentry.find_next_sibling() # count the number of replies times = 0 reps = [] r_dates = [dt] r_latest = '' r_title = '' r_disposition = '' r_action = '' for replyentry in replies.find_all("div", class_ = "postentry"): [r_title, r_url, r_author, r_auth_url, r_dt, r_latest] = get_postentry_author_info( replyentry ) # Put results into a list with line breaks reps.append(r_author + ': ' + r_dt.strftime('%y-%m-%d %H:%M')) r_dates.append(r_dt) if '_DISPOSITION' in r_title.upper(): # print('r_disposition is :', r_latest) r_disposition = r_latest if '_ACTION' in r_title.upper(): # print('r_action is :', r_latest) r_action = r_latest times += 1 # Turn the reps list into a single string repstr = ';\n'.join(reps) # Find the latest modified date r_dates.sort() r_date_latest = r_dates[-1] r_date_latest_str = r_date_latest.strftime('%y-%m-%d %H:%M') # Print output print('\nEntry:', idx) print('title:', title) print('url:', url) print('posting:', post) print('author:', author) print('date:',dt.strftime('%y-%m-%d %H:%M')) if repstr != '': print('latest update:', r_date_latest_str) print('replies by:', repstr) print('latest reply title:', r_title) print('latest reply:', r_latest) if r_disposition != '': print('Disposition:',r_disposition) if r_action != '': print('Action:', r_action) # Column 1: ID col = sscol ws.cell(row = ssrow, column = col).value = ssrow-rowoff ws.cell(row = ssrow, column = col).alignment = align_hv_cen_style # Column 2: Title col += 1 ws.cell(row = ssrow, column = col).value = title ws.cell(row = ssrow, column = col).font = font_url_style ws.cell(row = ssrow, column = col).hyperlink = url ws.cell(row = ssrow, column = col).alignment = Alignment(wrap_text = True, vertical = 'center') # Column 3: Posting col += 1 ws.cell(row = ssrow, column = col).value = clean_string(post) ws.cell(row = ssrow, column = col).alignment = Alignment(wrap_text = True, vertical = 'center') # Column 4: Author col += 1 ws.cell(row = ssrow, column = col).value = author ws.cell(row = ssrow, column = col).hyperlink = auth_url ws.cell(row = ssrow, column = col).alignment = align_ver_cen_style ws.cell(row = ssrow, column = col).font = font_url_style # Column 5: Post Date col += 1 ws.cell(row = ssrow, column = col).value = dt ws.cell(row = ssrow, column = col).number_format = 'YY-MM-DD HH:MM' ws.cell(row = ssrow, column = col).alignment = align_hv_cen_style # Column 6: # Replies col += 1 ws.cell(row = ssrow, column = col).value = times ws.cell(row = ssrow, column = col).alignment = align_hv_cen_style # Column 7: Replies By col += 1 ws.cell(row = ssrow, column = col).value = repstr ws.cell(row = ssrow, column = col).alignment = Alignment(wrap_text = True, vertical = 'center') # Column 8: Latest Reply Date col += 1 ws.cell(row = ssrow, column = col).value = r_date_latest_str ws.cell(row = ssrow, column = col).alignment = align_hv_cen_style #Column 9: Latest Reply Text col += 1 ws.cell(row = ssrow, column = col).value = clean_string(r_latest) ws.cell(row = ssrow, column = col).alignment = Alignment(wrap_text = True, vertical = 'center') #Column 10: Disposition Text col += 1 ws.cell(row = ssrow, column = col).value = clean_string(r_disposition) ws.cell(row = ssrow, column = col).alignment = Alignment(wrap_text = True, vertical = 'center') #Column 11: Action Text col += 1 ws.cell(row = ssrow, column = col).value = clean_string(r_action) ws.cell(row = ssrow, column = col).alignment = Alignment(wrap_text = True, vertical = 'center') ssrow += 1 # Set column widths ws.column_dimensions["A"].width = 5.0 ws.column_dimensions["B"].width = 40.0 ws.column_dimensions["C"].width = 60.0 ws.column_dimensions["D"].width = 13.0 ws.column_dimensions["E"].width = 13.0 ws.column_dimensions["F"].width = 13.0 ws.column_dimensions["G"].width = 25.0 ws.column_dimensions["H"].width = 17.0 ws.column_dimensions["I"].width = 60.0 ws.column_dimensions["J"].width = 60.0 ws.column_dimensions["K"].width = 60.0 # Save the spreadsheet wb.save(xlfile)
def copy_object(s): obj = input("Enter Object Handle: ") col = input("Enter Collection Handle to Copy To: ") DCC.add_docs_2_collections(s,[obj],[col]) return
def traverse(s, tr, collkey, dirpath = './', indent = '', **kwargs): # traverse follows the collection structure on the DCC and replicates it on the local disk pflag = False savefiles = kwargs.get('SaveFiles', False) exclude = kwargs.get('Exclude', []) maxfilesize = kwargs.get('MaxFileSize', sys.maxsize) branch = tr[collkey] collist = branch['collections'] doclist = branch['documents'] cinfo = DCC.prop_get(s, collkey, InfoSet = 'CollData') print(indent,'Files in ', collkey, ': ', cinfo['title']) colname = cinfo['title'] colname = colname.replace('/',' ') dirpath = dirpath + colname + '/' if savefiles: try: os.stat(dirpath) except: os.mkdir(dirpath) for doc in doclist: finfo = DCC.prop_get(s, doc, InfoSet = 'DocBasic') print(indent + '\t',doc) print(indent + '\t\tTitle: ',finfo['title']) print(indent + '\t\tFileName: ',finfo['filename'],' [',finfo['date'],']' ,' [', finfo['size'],' bytes ]') filedirpath = dirpath + finfo.get('title').replace('/',' ') + '/' filename = finfo.get('filename') if savefiles: try: os.stat(filedirpath) except: os.mkdir(filedirpath) if not os.path.isfile(filedirpath+filename): print(indent + "\t\t\tFile doesn't exist") if savefiles: if finfo['size'] < maxfilesize: print(indent + "\t\t\tGetting file") DCC.file_download(s, doc, filedirpath, finfo['filename']) else: print(indent + "\t\t\tFile size exceeds MaxFileSize of ", maxfilesize, "bytes") else: print(indent + "\t\t\tSaveFiles is False, so file will not be downloaded") elif (datetime.strptime(finfo['date'],'%a, %d %b %Y %H:%M:%S %Z') - datetime(1970,1,1)).total_seconds() > os.path.getctime(filedirpath+filename): print(indent + "\t\t\tFile exists, but is out of date:", time.ctime(os.path.getctime(filedirpath+filename))) if savefiles: if finfo['size'] < maxfilesize: print(indent + "\t\t\tGetting updated file") DCC.file_download(s, doc, filedirpath, finfo['filename']) else: print(indent + "\t\t\tFile size exceeds MaxFileSize of ", maxfilesize, "bytes") else: print(indent + "\t\t\tSaveFiles is False, so file will not be downloaded") else: print(indent + "\t\t\tFile exists, created:", time.ctime(os.path.getctime(filedirpath+filename))) for c in collist: if (not c == collkey) and (not c in exclude): traverse(s, tr, c, dirpath, indent + '\t', **kwargs)
def gen_ss_cid(s, dl): # Spreadsheet dataset will be a list of lists ss = [] for d in dl: ssrow = [] print("trying", d) if 'Document-' in d: # CID link is to a document Handle doc = DCC.prop_get(s, d, InfoSet='DocBasic') doc['Versions'] = DCC.prop_get(s, d, InfoSet='Versions') # Now read preferred version prefver = DCC.prop_get(s, doc['Versions']['prefver'], InfoSet='VerAll') # Check how many places the document is located doc['locations'] = DCC.prop_get(s, d, InfoSet='Parents') # Subject Document ssrow.append(doc['handle']) ssrow.append(doc['title']) ssrow.append(doc['tmtnum']) ssrow.append(doc['owner-username']) # Evaluation of current reference ssrow.append('Doc Ref') # Current reference ssrow.append(doc['handle']) ssrow.append(doc['title']) ssrow.append(doc['owner-username']) ssrow.append(doc['date']) # Suggested reference ssrow.append(prefver['dccver']) ssrow.append(prefver['vercomment']) ssrow.append(prefver['owner-username']) ssrow.append(prefver['date']) DCC.print_doc_basic(doc) DCC.print_ver(prefver) DCC.print_locations(doc) print(doc['handle'], doc['title'], doc['tmtnum'], doc['owner-username']) print("Doc Ref") print(prefver['dccver'], prefver['vercomment'], prefver['owner-username'], prefver['date']) print('Document has %d locations' % len(doc['locations'])) elif 'Version-' in d: # CID link is to a version handle ver = DCC.prop_get(s, d, InfoSet='VerAll') doc = DCC.prop_get(s, ver['dccdoc'], InfoSet='DocBasic') # Subject Document ssrow.append(doc['handle']) ssrow.append(doc['title']) ssrow.append(doc['tmtnum']) ssrow.append(doc['owner-username']) # find info on the preferred version prefver = DCC.prop_get(s, doc['prefver'], InfoSet='VerAll') # Evaluation of current reference print("CID references Version") print(doc['handle'], doc['title'], doc['tmtnum']) print("Referenced Version") print(ver['dccver'], ver['vercomment'], ver['owner-username'], ver['date']) if prefver['dccver'] == ver['dccver']: print("Referenced Version IS the Preferred Version") # Evaluation of current reference ssrow.append('Pref. Ver.') DCC.print_doc_all(doc) DCC.print_ver(prefver) # Current reference ssrow.append(prefver['dccver']) ssrow.append(prefver['vercomment']) ssrow.append(prefver['owner-username']) ssrow.append(prefver['date']) else: print("Referenced Version IS NOT the Preferred Version") # Evaluation of current reference ssrow.append('Non-Pref. Ver.') print("Non-Preferred Version") print(prefver['dccver'], prefver['vercomment'], prefver['owner-username'], prefver['date']) DCC.print_doc_all(doc) DCC.print_ver(ver) DCC.print_ver(prefver) # Current reference ssrow.append(ver['dccver']) ssrow.append(ver['vercomment']) ssrow.append(ver['owner-username']) ssrow.append(ver['date']) # Suggested reference ssrow.append(prefver['dccver']) ssrow.append(prefver['vercomment']) ssrow.append(prefver['owner-username']) ssrow.append(prefver['date']) else: print("Don't know how to handle", d) sys.exit() ss.append(ssrow) return (ss)
import DCC B = DCC.Unit() local = ('127.0.0.1', 12200) datalink = ('127.0.0.1', 11200) dest = ('127.0.0.1', 11200) B.debug4(local, dest, datalink) print('B.start to recv') print(B.recv()) res = input('end...')