Python os.tempnam() Examples
The following are 30
code examples of os.tempnam().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
os
, or try the search function
.
Example #1
Source File: shell.py From collection with MIT License | 6 votes |
def plist_save(filename, data, binary = False): import plistlib if not binary: plistlib.writePlist(data, filename) return 0 import warnings warnings.filterwarnings("ignore") tmpname = os.tempnam(None, 'plist.') plistlib.writePlist(data, tmpname) plutil('-convert', 'binary1', '-o', filename, tmpname) os.remove(tmpname) return 0 #---------------------------------------------------------------------- # testing case #----------------------------------------------------------------------
Example #2
Source File: singular.py From scryptoslib with MIT License | 6 votes |
def singular(cmd, isAll=False, debug=False): assert check("Singular") if isinstance(cmd, str): cmd = [cmd] s = ";\n".join(cmd) + ";" if debug: print("[+] Throughout to Singular Commands: {!r}".format(cmd)) tmpname = os.tempnam() open(tmpname, "w").write(s) p = Popen(["Singular", "-bq", tmpname], stdin=PIPE, stdout=PIPE) d, _ = p.communicate() os.remove(tmpname) if isAll: return d.split("\n")[:-1] else: return d.split("\n")[:-1][-1]
Example #3
Source File: splice_align.py From Cogent with BSD 3-Clause Clear License | 6 votes |
def get_consensus_through_pbdagcon(seq1, weight1, seq2, weight2): fname = os.tempnam("/tmp") + '.fasta' with open(fname, 'w') as f: for i in range(min(10, weight1)): # max cutoff at 10 f.write(">test1_{0}\n{1}\n".format(i, seq1)) for i in range(min(10, weight2)): # max cutoff at 10 f.write(">test2_{0}\n{1}\n".format(i, seq2)) cmd = "ice_pbdagcon.py --maxScore 10 {0} {0}.g_con g_con".format(fname) if subprocess.check_call(cmd, shell=True) == -1: raise Exception("Trouble running cmd: ").with_traceback(cmd) gcon_filename = fname + '.g_con.fasta' gref_filename = fname + '.g_con_ref.fasta' if os.path.exists(gcon_filename) and os.stat(gcon_filename).st_size > 0: return str(SeqIO.parse(open(gcon_filename), 'fasta').next().seq) elif os.path.exists(gref_filename): return str(SeqIO.parse(open(gref_filename), 'fasta').next().seq) else: raise Exception("Could not get results from running cmd:").with_traceback(cmd)
Example #4
Source File: application.py From wxGlade with MIT License | 6 votes |
def _get_preview_filename(self): import warnings warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, "application") if compat.PYTHON2: out_name = os.tempnam(None, 'wxg') + '.py' else: # create a temporary file at either the output path or the project path error = None if not self.filename: error = "Save project first; a temporary file will be created in the same directory." else: dirname, basename = os.path.split(self.filename) basename, extension = os.path.splitext(basename) if not os.path.exists(dirname): error = "Directory '%s' not found"%dirname elif not os.path.isdir(dirname): error = "'%s' is not a directory"%dirname if error: misc.error_message(error) return None while True: out_name = os.path.join(dirname, "_%s_%d.py"%(basename,random.randrange(10**8, 10**9))) if not os.path.exists(out_name): break return out_name
Example #5
Source File: test_os.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_tempnam(self): if not hasattr(os, "tempnam"): return warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, r"test_os$") self.check_tempfile(os.tempnam()) name = os.tempnam(test_support.TESTFN) self.check_tempfile(name) name = os.tempnam(test_support.TESTFN, "pfx") self.assert_(os.path.basename(name)[:3] == "pfx") self.check_tempfile(name)
Example #6
Source File: utils.py From dash-hack with MIT License | 5 votes |
def get_temp_file(keep=False, autoext=""): f = os.tempnam("","scapy") if not keep: conf.temp_files.append(f+autoext) return f
Example #7
Source File: utils.py From dash-hack with MIT License | 5 votes |
def get_temp_file(keep=False, autoext=""): f = os.tempnam("","scapy") if not keep: conf.temp_files.append(f+autoext) return f
Example #8
Source File: utils.py From dash-hack with MIT License | 5 votes |
def get_temp_file(keep=False, autoext=""): f = os.tempnam("","scapy") if not keep: conf.temp_files.append(f+autoext) return f
Example #9
Source File: utils.py From isip with MIT License | 5 votes |
def get_temp_file(keep=False, autoext=""): f = os.tempnam("","scapy") if not keep: conf.temp_files.append(f+autoext) return f
Example #10
Source File: test_os.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_tempnam(self): with warnings.catch_warnings(): warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, r"test_os$") warnings.filterwarnings("ignore", "tempnam", DeprecationWarning) self.check_tempfile(os.tempnam()) name = os.tempnam(test_support.TESTFN) self.check_tempfile(name) name = os.tempnam(test_support.TESTFN, "pfx") self.assertTrue(os.path.basename(name)[:3] == "pfx") self.check_tempfile(name)
Example #11
Source File: __init__.py From pth-toolkit with BSD 2-Clause "Simplified" License | 5 votes |
def setUp(self): super(LdbTestCase, self).setUp() self.filename = os.tempnam() self.ldb = samba.Ldb(self.filename)
Example #12
Source File: test_os.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_tempnam(self): with warnings.catch_warnings(): warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, r"test_os$") warnings.filterwarnings("ignore", "tempnam", DeprecationWarning) self.check_tempfile(os.tempnam()) name = os.tempnam(test_support.TESTFN) self.check_tempfile(name) name = os.tempnam(test_support.TESTFN, "pfx") self.assertTrue(os.path.basename(name)[:3] == "pfx") self.check_tempfile(name)
Example #13
Source File: utils.py From POC-EXP with GNU General Public License v3.0 | 5 votes |
def get_temp_file(keep=False, autoext=""): f = os.tempnam("","scapy") if not keep: conf.temp_files.append(f+autoext) return f
Example #14
Source File: test_os.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_tempnam(self): if not hasattr(os, "tempnam"): return with warnings.catch_warnings(): warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, r"test_os$") warnings.filterwarnings("ignore", "tempnam", DeprecationWarning) self.check_tempfile(os.tempnam()) name = os.tempnam(test_support.TESTFN) self.check_tempfile(name) name = os.tempnam(test_support.TESTFN, "pfx") self.assertTrue(os.path.basename(name)[:3] == "pfx") self.check_tempfile(name)
Example #15
Source File: generate_docs.py From lpts with GNU General Public License v2.0 | 5 votes |
def format_string(fp, str): str = re.sub("<<([^>]+)>>", "See also pychart.\\1", str) str2 = "" in_example = 0 for l in str.split("\n"): if re.match("@example", l): in_example = 1 if re.match("@end example", l): in_example = 0 if in_example: str2 += l else: l = re.sub("^[ \t]*", "", l) str2 += l str2 += "\n" fname = os.tempnam() out_fp = open(fname, "w") out_fp.write(str2) out_fp.close() in_fp = os.popen("makeinfo --fill-column=64 --no-headers " + fname, "r") for l in in_fp.readlines(): fp.write(" " * indent) fp.write(l) in_fp.close() os.remove(fname)
Example #16
Source File: command.py From sqlobject with GNU Lesser General Public License v2.1 | 5 votes |
def nowarning_tempnam(*args, **kw): return os.tempnam(*args, **kw)
Example #17
Source File: test_os.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_tempnam(self): if not hasattr(os, "tempnam"): return with warnings.catch_warnings(): warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, r"test_os$") warnings.filterwarnings("ignore", "tempnam", DeprecationWarning) self.check_tempfile(os.tempnam()) name = os.tempnam(test_support.TESTFN) self.check_tempfile(name) name = os.tempnam(test_support.TESTFN, "pfx") self.assertTrue(os.path.basename(name)[:3] == "pfx") self.check_tempfile(name)
Example #18
Source File: utils.py From CVE-2016-6366 with MIT License | 5 votes |
def get_temp_file(keep=False, autoext=""): f = os.tempnam("","scapy") if not keep: conf.temp_files.append(f+autoext) return f
Example #19
Source File: fixture.py From mishkal with GNU General Public License v3.0 | 5 votes |
def tempnam_no_warning(*args): """ An os.tempnam with the warning turned off, because sometimes you just need to use this and don't care about the stupid security warning. """ return os.tempnam(*args)
Example #20
Source File: test_cPickle.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_load_negative(self): if cPickle.__name__ == "cPickle": # pickle vs. cPickle report different exceptions, even on Cpy filename = os.tempnam() for temp in ['\x02', "No"]: self.write_to_file(filename, content=temp) f = open(filename) self.assertRaises(cPickle.UnpicklingError, cPickle.load, f) f.close()
Example #21
Source File: utils.py From CyberScan with GNU General Public License v3.0 | 5 votes |
def get_temp_file(keep=False, autoext=""): f = os.tempnam("","scapy") if not keep: conf.temp_files.append(f+autoext) return f
Example #22
Source File: test_os.py From BinderFilter with MIT License | 5 votes |
def test_tempnam(self): if not hasattr(os, "tempnam"): return with warnings.catch_warnings(): warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, r"test_os$") warnings.filterwarnings("ignore", "tempnam", DeprecationWarning) self.check_tempfile(os.tempnam()) name = os.tempnam(test_support.TESTFN) self.check_tempfile(name) name = os.tempnam(test_support.TESTFN, "pfx") self.assertTrue(os.path.basename(name)[:3] == "pfx") self.check_tempfile(name)
Example #23
Source File: test_os.py From oss-ftp with MIT License | 5 votes |
def test_tempnam(self): with warnings.catch_warnings(): warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, r"test_os$") warnings.filterwarnings("ignore", "tempnam", DeprecationWarning) self.check_tempfile(os.tempnam()) name = os.tempnam(test_support.TESTFN) self.check_tempfile(name) name = os.tempnam(test_support.TESTFN, "pfx") self.assertTrue(os.path.basename(name)[:3] == "pfx") self.check_tempfile(name)
Example #24
Source File: utils.py From smod-1 with GNU General Public License v2.0 | 5 votes |
def get_temp_file(keep=False, autoext=""): f = os.tempnam("","scapy") if not keep: conf.temp_files.append(f+autoext) return f
Example #25
Source File: shell.py From collection with MIT License | 5 votes |
def plist_load(filename): import plistlib fp = open(filename, 'rb') content = fp.read(8) fp.close() if content == 'bplist00': import warnings warnings.filterwarnings("ignore") tmpname = os.tempnam(None, 'plist.') plutil('-convert', 'xml1', '-o', tmpname, filename) data = plistlib.readPlist(tmpname) os.remove(tmpname) return data data = plistlib.readPlist(filename) return data
Example #26
Source File: utils.py From mptcp-abuse with GNU General Public License v2.0 | 5 votes |
def get_temp_file(keep=False, autoext=""): f = os.tempnam("","scapy") if not keep: conf.temp_files.append(f+autoext) return f
Example #27
Source File: test_functional.py From bandit with Apache License 2.0 | 5 votes |
def test_tempnam(self): '''Test for `os.tempnam` / `os.tmpnam`.''' expect = { 'SEVERITY': {'UNDEFINED': 0, 'LOW': 0, 'MEDIUM': 6, 'HIGH': 0}, 'CONFIDENCE': {'UNDEFINED': 0, 'LOW': 0, 'MEDIUM': 0, 'HIGH': 6} } self.check_example('tempnam.py', expect)
Example #28
Source File: test_cPickle.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_load_negative(self): if cPickle.__name__ == "_pickle": # pickle vs. cPickle report different exceptions, even on Cpy filename = os.tempnam() for temp in ['\x02', "No"]: self.write_to_file(filename, content=temp) f = open(filename) self.assertRaises(cPickle.UnpicklingError, cPickle.load, f) f.close()
Example #29
Source File: utils.py From CVE-2016-6366 with MIT License | 4 votes |
def do_graph(graph,prog=None,format=None,target=None,type=None,string=None,options=None): """do_graph(graph, prog=conf.prog.dot, format="svg", target="| conf.prog.display", options=None, [string=1]): string: if not None, simply return the graph string graph: GraphViz graph description format: output type (svg, ps, gif, jpg, etc.), passed to dot's "-T" option target: filename or redirect. Defaults pipe to Imagemagick's display program prog: which graphviz program to use options: options to be passed to prog""" if format is None: if WINDOWS: format = "png" # use common format to make sure a viewer is installed else: format = "svg" if string: return graph if type is not None: format=type if prog is None: prog = conf.prog.dot start_viewer=False if target is None: if WINDOWS: tempfile = os.tempnam("", "scapy") + "." + format target = "> %s" % tempfile start_viewer = True else: target = "| %s" % conf.prog.display if format is not None: format = "-T %s" % format w,r = os.popen2("%s %s %s %s" % (prog,options or "", format or "", target)) w.write(graph) w.close() if start_viewer: # Workaround for file not found error: We wait until tempfile is written. waiting_start = time.time() while not os.path.exists(tempfile): time.sleep(0.1) if time.time() - waiting_start > 3: warning("Temporary file '%s' could not be written. Graphic will not be displayed." % tempfile) break else: if conf.prog.display == conf.prog._default: os.startfile(tempfile) else: subprocess.Popen([conf.prog.display, tempfile])
Example #30
Source File: dataset-get.py From TextDetector with GNU General Public License v3.0 | 4 votes |
def atomic_replace( src_filename, dst_filename ): """ Does an "atomic" replace of a file by another. If both files reside on the fame FS device, atomic_replace does a regular move. If not, the source file is first copied to a temporary location on the same FS as the destination, then a regular move is performed. caveat: the destination FS must have enough storage left for the temporary file. :param src_filename: The file to replace from :param dst_filename: The file to be replaced :raises: whatever shutil raises """ #################################### def same_fs( filename_a, filename_b): """ Checks if both files reside on the same FS device """ stats_a = os.stat(filename_a) stats_b = os.stat(filename_b) return stats_a.st_dev == stats_b.st_dev; if os.path.exists(dst_filename) and not same_fs(src_filename,dst_filename): # deals with non-atomic move # dst_path = os.path.dirname(os.path.abspath(dst_filename)) dst_temp_filename=os.tempnam(dst_path); shutil.copy(src_filename, dst_temp_filename) # non-atomic shutil.move(dst_temp_filename,dst_filename) # atomic else: # an atomic move is performed # (both files are on the same device, # or the destination doesn't exist) # shutil.move(src_filename, dst_filename) ########################################