Python os 模块,mkdirs() 实例源码
我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用os.mkdirs()。
def execute_frama_c(self, main):
if not os.path.islink(self.shortdest):
# print self.shortdest
# print self.patchdest
os.symlink(self.patchdest, self.shortdest)
if len(self.backupdir) > 0:
if not os.path.isdir(self.backupdir):
os.mkdirs(self.backupdir)
[shutil.copyfile(f.pp_path,
os.path.join(self.backupdir,
os.path.basename(f.pp_path)))
for f in self.preprocessed_files]
cmd = "%s %s %s %s %s" % (self.frama_c, self.paths(),
self.frama_c_main_arg, main, self.frama_c_args)
if self.execute:
if self.verbose:
print cmd
self.get_cmd_results(cmd)
else:
print cmd
print "\n"
def __init__(self, cache_dir=None, expiration_in_minutes=30):
# Protects |self| but individual file objects in |store| are not
# protected once its returned from |_file_for|.
self.lock = threading.Lock()
# Dictionary mapping a URL to a tuple containing a file object and a
# timestamp. The timestamp notes the creation time.
self.store = {}
# Directory containing cache files. If |cache_dir| is None, then each
# file is created independently using tempfile.TemporaryFile().
self.cache_dir = cache_dir
# Garbage collector timer.
self.timer = threading.Timer(15 * 60, self.gc)
self.timer.start()
self.expiration = datetime.timedelta(minutes=expiration_in_minutes)
if cache_dir and not os.path.exists(cache_dir):
if not os.path.isabs(cache_dir):
raise ValueError('|cache_dir| should be an absolute path')
os.mkdirs(cache_dir)
def get_screenshot(ip, port, logdir):
log._LOG_LEVEL = log.Level.ERROR
app = QtGui.QApplication(sys.argv)
import qt4reactor
qt4reactor.install()
from twisted.internet import reactor
try: os.mkdirs(logdir + "5_Reporting/images/")
except: pass
reactor.connectTCP(ip, int(port), RDPScreenShotFactory(
reactor, app, 1200, 800, "%s/5_Reporting/images/rdp_%s_%s.jpg" % (logdir, ip, port), 7))
try: reactor.runReturn(installSignalHandlers=0)
except: pass
app.exec_()
return "%s/5_Reporting/images/rdp_%s_%s.jpg" % (logdir, ip, port)
def decompress(self, fn):
ret = {}
doc = zipfile.ZipFile(fn)
try:
os.mkdirs('./tmp')
except:
pass
doc.extractall('./tmp/')
for item in doc.infolist():
x = self.file_parse('./tmp/' + item.orig_filename)
if len(x.keys()) > 1:
del x['filename']
ret = self.addto(ret, x)
if item.orig_filename == 'meta.xml':
ret = self.addto(ret, self.ooo_meta('./tmp/' + item.orig_filename))
elif item.orig_filename in ('docProps/app.xml',
'docProps/core.xml') or item.orig_filename.split('/')[-1] \
in ('sharedStrings.xml', 'document.xml'):
ret = self.addto(ret, self.msoffice_meta('./tmp/' + item.orig_filename))
return ret
def write_to_csv(timestamp, target):
try:
x = [" "] * len(flist.split(","))
for i, v in target.items():
if type(v) == list:
v = ' | '.join(v)
if i.lower() in flist.lower().split(', '): # matching up the columns with our values
x[flist.lower().split(", ").index(i.lower())] = re.sub('[\n\r,]', '', safe_string(v).replace('"', '"'))
except Exception, ex:
output.put("\n %s[!]%s Unable to parse host record:\n\t%s\n" % (TC.YELLOW, TC.END, str(ex)))
try:
if not os.path.isfile("3_Enumeration/rawr_%s_serverinfo.csv" % timestamp):
try: os.mkdirs("3_Enumeration")
except: pass
open("3_Enumeration/rawr_%s_serverinfo.csv" % timestamp, 'w').write(flist)
open("3_Enumeration/rawr_%s_serverinfo.csv" % timestamp, 'a').write('\n"%s"' % (str('","'.join(x))))
except Exception, ex:
output.put("\n %s[!]%s Unable to write .csv:\n\t%s\n" % (TC.YELLOW, TC.END, str(ex)))
def setUp(self):
super(SelfCleaningTestCase, self).setUp()
# tempdir for brunnhilde outputs
self.dest_tmpdir = tempfile.mkdtemp()
if not os.path.isdir(self.dest_tmpdir):
os.mkdirs(self.dest_tmpdir)
def make_dirs(env) -> "(path -- )":
"Creates the directory given by path. Like make.dir, but makes all intermediate-level directories needed to contain the leaf directory"
os.mkdirs(env.stack.pop().val)