def check(next,yourpath): if next == 'cd': return os.chdir(os.path.abspath(os.path.join(yourpath, os.pardir))) if next[:2] == 'cd' and len(next) > 2: if os.path.exists(next[3:]): return os.chdir(next[3:]) if next == 'ls': ls = os.listdir() ls = list(set(ls)) rls = [] for el in ls: rls += ls rls = list(set(rls)) for el in rls: if rls.index(el) != len(rls)-1: print(el,end = ' ; ') else: print(el) if next[:5] == 'touch' and len(next) > 5: try: touch.touch(next[6:]) except: print("This File Could Not Be Made") if next[:3] == 'rmv' and len(next) > 3: if os.path.exists(next[4:]): os.remove(next[4:]) return None
def main(arguments): args = parse_args(arguments) if args.wordnet: assert_lang_supported_by_wordnet(args.lang) touch(args.out_file) main_graph = build_lexicon( args.words, args.lang, args.depth, nlp_model_paths=args.nlp_model_paths, wolf_path=args.wolf_path, wordnet=args.wordnet, web=args.web, strict=args.strict, ) if args.format == "txt": main_graph.to_text_file(args.out_file) elif args.format == "xlsx": main_graph.to_xlsx_file(args.out_file) elif args.format == "ttl": with open(args.out_file, "w") as f: print(main_graph, file=f) logging.info(f"{args.out_file}") logging.info(f"done. {len(main_graph)} related words found")
def test_holdouts_tempered(): clear_all_cache(results_directory="results", cache_dir="holdouts") np.random.seed(10) generator = cached_holdouts_generator(np.random.randint(100, size=(100, 100)), holdouts=random_holdouts([0.1], [10]), cache_dir="holdouts") list(generator(results_directory="results")) paths = glob("holdouts/holdouts/*.pickle.gz") path = paths[0] os.remove(path) touch(path) with pytest.raises(ValueError): list(generator()) clear_invalid_cache(cache_dir="holdouts") assert set(glob("holdouts/holdouts/*.pickle.gz")) == set(paths[1:]) list(generator(results_directory="results")) paths = glob("holdouts/holdouts/*.pickle.gz") path = paths[0] os.remove(path) with pytest.raises(ValueError): list(generator()) clear_invalid_cache(cache_dir="holdouts") assert set(glob("holdouts/holdouts/*.pickle.gz")) == set(paths[1:]) list(generator(results_directory="results")) clear_all_cache(results_directory="results", cache_dir="holdouts")
def to_text_file(self, out_file=None): """write the graph to the path provided. Args: out_file (str, optional): The outfile path. If None, returns the string Example of file: .. code:: python book # the root word Bible # a 1st rank synonym, linked to 'book' Holy_Writ # a 2nd rank synonym, linked to 'Bible' Scripture # a 2nd rank synonym, linked to 'Bible' Word # a 2nd rank synonym, linked to 'Bible' Epistle # a 1st rank synonym, linked to 'book' letter # a 2nd rank synonym, linked to 'Epistle' missive # a 2nd rank synonym, linked to 'Epistle' """ touch(out_file) # None can be touch ! ?? def rec_search(uri, str_=None, dep=None, uri_used=[]): q_words = ("""SELECT ?uri ?pref ?dep WHERE { ?uri <http://www.w3.org/2004/02/skos/core#prefLabel> ?pref ; <urn:default:baseUri:#depth> ?dep . ?uri ?relation <""" + uri + "> } ORDER BY ASC (?pref) ") if not str_: str_ = "" res = [r for r in self.query(q_words)] for new_uri, word, dep in res: new_uri = str(new_uri) word = str(word) dep = int(dep) assert type(dep) == int assert type(word) == type(new_uri) == str if new_uri in uri_used: continue uri_used.append(new_uri) str_ += "\t" * dep + word + "\n" str_ = rec_search(new_uri, str_, dep, uri_used=uri_used) return str_ if not hasattr(self, "root_words") or not getattr(self, "root_words"): self._set_root_word_attribute() text = rec_search(self.root_word_uri, "\n".join(self.root_words) + "\n") if out_file: with open(out_file, "w") as f: print(text, file=f) else: return text logging.info(f"out file is: '{out_file}'")
def test_gifsicle_exceptions(): with pytest.raises(ValueError): gifsicle("non_existent_gif.gif") png = "existent_png.png" gif = "existent_gif.gif" touch(png) touch(gif) with pytest.raises(ValueError): gifsicle(png) with pytest.raises(ValueError): gifsicle(gif, png) os.remove(png) os.remove(gif)
def add_work_in_progress(results_directory: str, holdout_key: str, hyper_parameters: Dict = None): """Sign given holdout holdout_key as under processing for given results directory. results_directory: str, directory where results are stored. holdout_key: str, holdout_key identifier of holdout. hyper_parameters: Dict, hyper parameters to check for. """ if skip(holdout_key, hyper_parameters, results_directory): raise ValueError( "Given holdout_key {holdout_key} for given directory {results_directory} is already work in progress or completed!" .format(holdout_key=holdout_key, results_directory=results_directory)) touch( work_in_progress_path(results_directory, holdout_key, hyper_parameters))
def __init__(self): """ Name: __init__ Input: None Output: None Description: Sets initial variables in use by the many other functions. Builds the initial history index based off existing ~/.history.txt file if it exists, if it doesn't, it creates it. """ self.currentIndex = 0 self.fullHistory = [] self.shellStorePath = os.path.expanduser("~") + '.shellhistory.txt' try: historyFile = open(self.shellStorePath) for line in historyFile: self.currentIndex += 1 self.fullHistory.append(line) except: touch(path=[os.path.expanduser("~")], params=['.shellhistory.txt'])
def parse_depth_image(context, snapshot): ''' Parses the depth image from the snapshot. (deletes the raw data file and and writes to disk a new jpg file representing the depth image. Uses matplotlib. Returns the image's path.) :param context: the context object representing the folders :type context: utils.Context :param snapshot: the snapshot data to be parsed (in json format) :type snapshot: str :return: the result of the parser (in json format) :rtype: str ''' path = context.path('depth_image.jpg') snap_dict = json.loads(snapshot) w, h = snap_dict['depth_image']['width'], snap_dict['depth_image'][ 'height'] raw_file = snap_dict['depth_image']['data'] float_vals = np.load(raw_file) float_matrix = [] for i in range(h): float_matrix.append(float_vals[w * i:w * (i + 1)]) float_np = np.array(float_matrix) im = plt.imshow(float_np) touch.touch(path) plt.savefig(path) os.remove(raw_file) result = {} result['depth_image'] = path.as_posix() result['user_id'] = snap_dict['user_id'] result['parser'] = 'depth_image' result['datetime'] = snap_dict['datetime'] return json.dumps(result)
def setUp(self): # self.res = get_synonyms_from_scrappers( # "test", self.lang, self.depth, merge_graph=False # ) self.merged_graph = Graph() for g in self.res: self.merged_graph += g with open(self.out_ttl_file, "w") as f: print(self.merged_graph, file=f) self.words = [] for g in self.res: self.words += g.to_list() self.words = set(self.words) touch(self.out_text_file) touch(self.out_ttl_file) touch(self.out_ttl_file_2)
self.anb = anb_small.replace('a', 'A') except ValueError: self.anb = None self.path = mkpath(self.filename, wd=source_dir) # ### Do the job ### ''' # emptying directories, for debug purpose - TODO add option rm(to_keep_dir) rm(to_trash_dir) ''' # recreate .gitkeep touch([mkpath(".gitkeep", wd=to_keep_dir)]) images = [Picture(i) for i in ls_source_dir] # NOTE debug logs = mkpath("logs") debug = open(logs, 'w') ''' for item in images: debug.write("%s\n" % item.filename) ''' for pic in images: if pic.anb in articles_list or not pic.anb: try: dest_path = mkpath(pic.filename, wd=to_keep_dir)
def genrate(): try: if path.get() != "": a = path.get() lab_filecreated.config(text="File Created Successfully") if filextention.get() != "Select E-mail File Extention": if filename.get() != "": if filextention.get( ) == "Outlook Express e-mail message file" and filename.get( ) != "": touch.touch(a + "/{}.email".format(filename.get())) if filextention.get( ) == "E-mail message file" and filename.get( ) != "": touch.touch(a + "/{}.eml".format(filename.get())) if filextention.get( ) == "Apple Mail e-mail file" and filename.get( ) != "": touch.touch(a + "/{}.emlx".format(filename.get())) if filextention.get( ) == "Microsoft Outlook e-mail message file" and filename.get( ) != "": touch.touch(a + "/{}.msg".format(filename.get())) if filextention.get( ) == "Microsoft Outlook e-mail template file" and filename.get( ) != "": touch.touch(a + "/{}.oft".format(filename.get())) if filextention.get( ) == "Microsoft Outlook offline e-mail storage file" and filename.get( ) != "": touch.touch(a + "/{}.ost".format(filename.get())) if filextention.get( ) == "Microsoft Outlook e-mail storage file" and filename.get( ) != "": touch.touch(a + "/{}.pst".format(filename.get())) if filextention.get( ) == "E-mail contact file" and filename.get( ) != "": touch.touch(a + "/{}.vcf".format(filename.get())) else: tkinter.messagebox.showerror( "Error", "Please write a proper filename") else: tkinter.messagebox.showerror( "Error", "Please choose an extension ") else: tkinter.messagebox.showerror("Error", "Please choose path first") except Exception as e: print(e)
def mtouch(): for i in range(1, 99): t.touch("dir_patht%s" % i)
## enhancement: filter out short mapped backbones # Create a dict with lists of SimpleRead using referenceName as key. Only good quality backbone matches are recorded. myDict = collections.defaultdict(list) for read in samFile: # Remove matches that suck try: alnErr = sum(x[1] for x in read.cigartuples if x[0] in [1,2]) if alnErr/float(read.reference_end) < 0.2: if (read.reference_end - read.reference_start) > 150: #read.reference_start + read.infer_query_length(always=True) myDict[read.reference_name].append((read.reference_start,read.reference_end,read.flag&(1<<4)>0,read.query_name)) except TypeError as e: # if there is no matching reads in sam file touch.touch(ins_outFile) touch.touch(bb_outFile) touch.touch(stats_outFile) exit() # Combine matches per read sortedKeys =list( myDict.keys()) sortedKeys.sort() for key in sortedKeys: myDict[key].sort() # print(key,myDict[key]) # exit() # Work through the fastq file with open(in_fasta_path,'r') as fasta_file, open(ins_outFile,'w') as dumpFile, \ open(bb_outFile,'w') as dump_bb_File, open(stats_outFile,'w') as statFile:
def genrate(): try: if path.get() != "": a = path.get() lab_filecreated.config(text="File Created Successfully") if filextention.get() != "Select Video File Extention": if filename.get() != "": if filextention.get( ) == "3GPP2 multimedia file" and filename.get( ) != "": touch.touch(a + "/{}.3g2".format(filename.get())) if filextention.get( ) == "3GPP multimedia file" and filename.get( ) != "": touch.touch(a + "/{}.3gp".format(filename.get())) if filextention.get( ) == "AVI file" and filename.get() != "": touch.touch(a + "/{}.avi".format(filename.get())) if filextention.get( ) == "Adobe Flash file" and filename.get() != "": touch.touch(a + "/{}.flv".format(filename.get())) if filextention.get( ) == "H.264 video file" and filename.get() != "": touch.touch(a + "/{}.h264".format(filename.get())) if filextention.get( ) == "Apple MP4 video file" and filename.get( ) != "": touch.touch(a + "/{}.m4v".format(filename.get())) if filextention.get( ) == "Matroska Multimedia Container" and filename.get( ) != "": touch.touch(a + "/{}.mkv".format(filename.get())) if filextention.get( ) == "Apple QuickTime movie file" and filename.get( ) != "": touch.touch(a + "/{}.mov".format(filename.get())) if filextention.get( ) == "MPEG4 video file" and filename.get() != "": touch.touch(a + "/{}.mp4".format(filename.get())) if filextention.get( ) == "MPEG video file" and filename.get() != "": touch.touch(a + "/{}.mpg".format(filename.get())) if filextention.get( ) == "RealMedia file" and filename.get() != "": touch.touch(a + "/{}.rm".format(filename.get())) if filextention.get( ) == "Shockwave flash file" and filename.get( ) != "": touch.touch(a + "/{}.swf".format(filename.get())) if filextention.get( ) == "DVD Video Object" and filename.get() != "": touch.touch(a + "/{}.vob".format(filename.get())) if filextention.get( ) == "Windows Media Video file" and filename.get( ) != "": touch.touch(a + "/{}.wmv".format(filename.get())) else: tkinter.messagebox.showerror( "Error", "Please write a proper filename") else: tkinter.messagebox.showerror( "Error", "Please choose an extension ") else: tkinter.messagebox.showerror("Error", "Please choose path first") except Exception as e: print(e)
def genrate(): try: if path.get() != "": a = path.get() lab_filecreated.config(text="File Created Successfully") if filextention.get() != "Select Image File Extention": if filename.get() != "": if filextention.get( ) == "Adobe Illustrator file" and filename.get( ) != "": touch.touch(a + "/{}.ai".format(filename.get())) if filextention.get( ) == "Bitmap image" and filename.get() != "": touch.touch(a + "/{}.bmp".format(filename.get())) if filextention.get( ) == "GIF image" and filename.get() != "": touch.touch(a + "/{}.gif".format(filename.get())) if filextention.get( ) == "Icon file" and filename.get() != "": touch.touch(a + "/{}.ico".format(filename.get())) if filextention.get( ) == "JPEG image" and filename.get() != "": touch.touch(a + "/{}.jpg".format(filename.get())) if filextention.get( ) == "PNG image" and filename.get() != "": touch.touch(a + "/{}.png".format(filename.get())) if filextention.get( ) == "PostScript file" and filename.get() != "": touch.touch(a + "/{}.ps".format(filename.get())) if filextention.get( ) == "PSD image" and filename.get() != "": touch.touch(a + "/{}.psd".format(filename.get())) if filextention.get( ) == "Scalable Vector Graphics file" and filename.get( ) != "": touch.touch(a + "/{}.svg".format(filename.get())) if filextention.get( ) == "TIFF image" and filename.get() != "": touch.touch(a + "/{}.tiff".format(filename.get())) else: tkinter.messagebox.showerror( "Error", "Please write a proper filename") else: tkinter.messagebox.showerror( "Error", "Please choose an extension ") else: tkinter.messagebox.showerror("Error", "Please choose path first") except Exception as e: print(e)
#importing touch import touch #calling touch class from touch touch.touch("Hello.py") touch.touch("Hello.js") touch.touch("Hello.html") touch.touch("Hello.txt")
def create_all_files(destdir, methods, apifile="app.py"): if os.path.isdir(destdir) == False: os.mkdir(destdir) destdir = re.sub(r'/$', r'', destdir) apifileout = "{destdir}/imports.{apifile}".format(destdir=destdir, apifile=apifile) savefiles = {} for method in methods: # only create files when method has no error if method['error'] != False: print(method['error']) continue if DEBUG == True: pprint.pprint(method) tree = get_tree(method['operationId']) fileout = '' if len(tree) > 0: destdir_module = [] destdir_n = 0 if DEBUG == True: pprint.pprint(tree) tree_dirs = tree[:-1] if len(tree_dirs) > 0: tree_dirs_path = destdir tree_dirs_n = 0 for d in tree_dirs: tree_dirs_path = tree_dirs_path + "/" + d if tree_dirs_n + 1 < len(tree_dirs): if os.path.exists(tree_dirs_path) == False: print("creating dir {tree_dirs_path}".format( tree_dirs_path=tree_dirs_path)) os.mkdir(tree_dirs_path) if os.path.exists(tree_dirs_path + "/__init__.py") == False: print("creating file {tree_dirs_path}/__init__.py". format(tree_dirs_path=tree_dirs_path)) touch.touch(tree_dirs_path + "/__init__.py") tree_dirs_n += 1 if len(tree) > 1: fileout = destdir + "/" + "/".join(tree_dirs) + ".py" else: fileout = apifileout tree_verb = tree[-1] if DEBUG: print("verb: ", tree_verb) verb_text = create_verb(verb=tree_verb, params=method['parameters']) add_savefiles(savefiles, fileout, "verb", verb_text) if len(tree_dirs) > 0: import_text = "import " + ".".join(tree_dirs) add_savefiles(savefiles, apifileout, "import", import_text) write_savefiles(savefiles)
if os.name != 'nt': print("You are not using Windows.Termulator is for Windows systems only") exit(1) user = os.getlogin() while 1: try: q = input(user + '$') q = q.split() print(q) except KeyboardInterrupt: exit(1) try: if q[0] == 'pwd': pwd.pwd() elif q[0] == "ls": ls.ls() elif q[0] == "clear": clear.clear() elif q[0] == "cd": cd.cd(q) elif q[0] == "cp": cp.cp(q) elif q[0] == "mv": mv.mv(q) elif q[0] == "touch": touch.touch(q) else: print(q[0] + " is not a recognizable command") # default except IndexError: continue
def genrate(): try: if path.get() != "": a = path.get() lab_filecreated.config(text="File Created Successfully") if filextention.get( ) != "Select Executable File Extention": if filename.get() != "": if filextention.get( ) == "Android package file" and filename.get( ) != "": touch.touch(a + "/{}.apk".format(filename.get())) if filextention.get( ) == "Batch file" and filename.get() != "": touch.touch(a + "/{}.bat".format(filename.get())) if filextention.get( ) == "Binary file" and filename.get() != "": touch.touch(a + "/{}.bin".format(filename.get())) if filextention.get( ) == "Perl script file" and filename.get() != "": touch.touch(a + "/{}.pl".format(filename.get())) if filextention.get( ) == "MS-DOS command file" and filename.get( ) != "": touch.touch(a + "/{}.com".format(filename.get())) if filextention.get( ) == "Executable file" and filename.get() != "": touch.touch(a + "/{}.exe".format(filename.get())) if filextention.get( ) == "Windows gadget" and filename.get() != "": touch.touch( a + "/{}.gadget".format(filename.get())) if filextention.get( ) == "Java Archive file" and filename.get() != "": touch.touch(a + "/{}.jar".format(filename.get())) if filextention.get( ) == "Windows installer package" and filename.get( ) != "": touch.touch(a + "/{}.msi".format(filename.get())) if filextention.get( ) == "Python file" and filename.get() != "": touch.touch(a + "/{}.py".format(filename.get())) if filextention.get( ) == "Windows Script File" and filename.get( ) != "": touch.touch(a + "/{}.wsf".format(filename.get())) else: tkinter.messagebox.showerror( "Error", "Please write a proper filename") else: tkinter.messagebox.showerror( "Error", "Please choose an extension ") else: tkinter.messagebox.showerror("Error", "Please choose path first") except Exception as e: print(e)
# touch module using Python import touch touch.touch("file1.java") touch.touch("file2.py") touch.touch("file3.js") touch.touch("file4.html") touch.touch("file5.css") touch.touch("file6.cpp")
csvfile = file name = csvfile.replace(".csv", "") fullpath = (root + '\\Archive' + '\\' + csvfile) dt = datetime.fromtimestamp(os.stat(fullpath).st_ctime) today = datetime.now() date_diff = today - dt print(csvfile) print(name) print(fullpath) print(date_diff) if date_diff.days > 9: print("File greater than 9 Days") connection = psycopg2.connect(user=User, password=Password, host=Host, port=Port, database=Database) cursor = connection.cursor() cursor.execute('Drop table ' + name) connection.commit() print("Table dropped PostgreSQL ") cursor.close() connection.close() os.remove(fullpath) else: print("File less than 9 days") touch.touch(root + '\\landing\\' + 'Database_Governance.trig')
def setUp(self): self.g = Graph() touch(self.txt_out_file) touch(self.xlsx_out_file)
def genrate(): try: if path.get() != "": a = path.get() lab_filecreated.config(text="File Created Successfully") if filextention.get() != "Select Data File Extention": if filename.get() != "": if filextention.get( ) == "Comma separated value file" and filename.get( ) != "": touch.touch(a + "/{}.csv".format(filename.get())) if filextention.get( ) == "Data file" and filename.get() != "": touch.touch(a + "/{}.dat".format(filename.get())) if filextention.get( ) == "Database file" and filename.get() != "": touch.touch(a + "/{}.db".format(filename.get())) if filextention.get( ) == "Microsoft Access database file" and filename.get( ) != "": touch.touch(a + "/{}.mdb".format(filename.get())) if filextention.get( ) == "Save file (e.g., game save file)" and filename.get( ) != "": touch.touch(a + "/{}.sav".format(filename.get())) if filextention.get( ) == "SQL database file" and filename.get() != "": touch.touch(a + "/{}.sql".format(filename.get())) if filextention.get( ) == "Linux / Unix tarball file archive" and filename.get( ) != "": touch.touch(a + "/{}.tar".format(filename.get())) if filextention.get( ) == "XML file" and filename.get() != "": touch.touch(a + "/{}.xml".format(filename.get())) else: tkinter.messagebox.showerror( "Error", "Please write a proper filename") else: tkinter.messagebox.showerror( "Error", "Please choose an extension ") else: tkinter.messagebox.showerror("Error", "Please choose path first") except Exception as e: print(e)
def setUp(self): touch(self.out_file) touch(self.out_file_xlsx)
def genrate(): try: if path.get() != "": a = path.get() lab_filecreated.config(text="File Created Successfully") if filextention.get() != "Select System File Extention": if filename.get() != "": if filextention.get( ) == "Backup file" and filename.get() != "": touch.touch(a + "/{}.bak".format(filename.get())) if filextention.get( ) == "Windows Cabinet file" and filename.get( ) != "": touch.touch(a + "/{}.cab".format(filename.get())) if filextention.get( ) == "Configuration file" and filename.get() != "": touch.touch(a + "/{}.cfg".format(filename.get())) if filextention.get( ) == "Windows Control panel file" and filename.get( ) != "": touch.touch(a + "/{}.cpl".format(filename.get())) if filextention.get( ) == "Windows cursor file" and filename.get( ) != "": touch.touch(a + "/{}.cur".format(filename.get())) if filextention.get( ) == "DLL file" and filename.get() != "": touch.touch(a + "/{}.dll".format(filename.get())) if filextention.get( ) == "Dump file" and filename.get() != "": touch.touch(a + "/{}.dmp".format(filename.get())) if filextention.get( ) == "Device driver file" and filename.get() != "": touch.touch(a + "/{}.drv".format(filename.get())) if filextention.get( ) == "macOS X icon resource file" and filename.get( ) != "": touch.touch(a + "/{}.icns".format(filename.get())) if filextention.get( ) == "Icon file" and filename.get() != "": touch.touch(a + "/{}.ico".format(filename.get())) if filextention.get( ) == "Initialization file" and filename.get( ) != "": touch.touch(a + "/{}.ini".format(filename.get())) if filextention.get( ) == "Windows shortcut file" and filename.get( ) != "": touch.touch(a + "/{}.lnk".format(filename.get())) if filextention.get( ) == "Windows shortcut file" and filename.get( ) != "": touch.touch(a + "/{}.lnk".format(filename.get())) if filextention.get( ) == "Windows installer package" and filename.get( ) != "": touch.touch(a + "/{}.msi".format(filename.get())) if filextention.get( ) == "Windows system file" and filename.get( ) != "": touch.touch(a + "/{}.sys".format(filename.get())) if filextention.get( ) == "Temporary file" and filename.get() != "": touch.touch(a + "/{}.tmp".format(filename.get())) else: tkinter.messagebox.showerror( "Error", "Please write a proper filename") else: tkinter.messagebox.showerror( "Error", "Please choose an extension ") else: tkinter.messagebox.showerror("Error", "Please choose path first") except Exception as e: print(e)
def func3(): touch.touch()