def get_pdf(html):
""" xxx"""
reg = r'href="/paper/(.+?)"'
pdfre = re.compile(reg)
pdflist = re.findall(pdfre, html)
dir_name = 'NIPS2012'
maxrows = len(pdflist)
pbar = prgbar.ProgressBar(total=maxrows)
if os.path.exists(dir_name) is False:
os.mkdir(dir_name)
for idx, pdfurl in enumerate(pdflist):
filename = dir_name + '/' + pdfurl + '.pdf'
pbar.log('http://papers.nips.cc/paper/' + pdfurl + '.pdf')
if os.path.exists(filename) is True:
pbar.log('Exist')
else:
urllib.urlretrieve(
'http://papers.nips.cc/paper/' + pdfurl + '.pdf', filename)
pbar.update(index=(idx + 1))
pbar.finish()
python类mkdir()的实例源码
def get_pdf(html):
""" xxx"""
reg = r'href="/paper/(.+?)"'
pdfre = re.compile(reg)
pdflist = re.findall(pdfre, html)
dir_name = 'NIPS2016'
maxrows = len(pdflist)
pbar = prgbar.ProgressBar(total=maxrows)
if os.path.exists(dir_name) is False:
os.mkdir(dir_name)
for idx, pdfurl in enumerate(pdflist):
filename = dir_name + '/' + pdfurl + '.pdf'
pbar.log('http://papers.nips.cc/paper/' + pdfurl + '.pdf')
if os.path.exists(filename) is True:
pbar.log('Exist')
else:
urllib.urlretrieve(
'http://papers.nips.cc/paper/' + pdfurl + '.pdf', filename)
pbar.update(index=(idx + 1))
pbar.finish()
def get_pdf(html):
""" xxx"""
reg = r'href="/paper/(.+?)"'
pdfre = re.compile(reg)
pdflist = re.findall(pdfre, html)
dir_name = 'NIPS2013'
maxrows = len(pdflist)
pbar = prgbar.ProgressBar(total=maxrows)
if os.path.exists(dir_name) is False:
os.mkdir(dir_name)
for idx, pdfurl in enumerate(pdflist):
filename = dir_name + '/' + pdfurl + '.pdf'
pbar.log('http://papers.nips.cc/paper/' + pdfurl + '.pdf')
if os.path.exists(filename) is True:
pbar.log('Exist')
else:
urllib.urlretrieve(
'http://papers.nips.cc/paper/' + pdfurl + '.pdf', filename)
pbar.update(index=(idx + 1))
pbar.finish()
def get_pdf(html):
""" xxx"""
reg = r'href="/paper/(.+?)"'
pdfre = re.compile(reg)
pdflist = re.findall(pdfre, html)
dir_name = 'NIPS2014'
maxrows = len(pdflist)
pbar = prgbar.ProgressBar(total=maxrows)
if os.path.exists(dir_name) is False:
os.mkdir(dir_name)
for idx, pdfurl in enumerate(pdflist):
filename = dir_name + '/' + pdfurl + '.pdf'
pbar.log('http://papers.nips.cc/paper/' + pdfurl + '.pdf')
if os.path.exists(filename) is True:
pbar.log('Exist')
else:
urllib.urlretrieve(
'http://papers.nips.cc/paper/' + pdfurl + '.pdf', filename)
pbar.update(index=(idx + 1))
pbar.finish()
def get_pdf(html):
""" xxx"""
reg = r'href="(.+?\.pdf)">pdf'
pdfre = re.compile(reg)
pdflist = re.findall(pdfre, html)
dir_name = 'CVPR2014'
maxrows = len(pdflist)
pbar = prgbar.ProgressBar(total=maxrows)
if os.path.exists(dir_name) is False:
os.mkdir(dir_name)
for idx, pdfurl in enumerate(pdflist):
reg2 = r'papers/(.+?\.pdf)'
pdfre2 = re.compile(reg2)
filename = dir_name + '/' + re.findall(pdfre2, pdfurl)[0]
pbar.log('http://www.cv-foundation.org/openaccess/' + pdfurl)
if os.path.exists(filename) is True:
pbar.log('Exist')
else:
urllib.urlretrieve(
'http://www.cv-foundation.org/openaccess/' + pdfurl, filename)
pbar.update(index=(idx + 1))
pbar.finish()
def get_pdf(html):
""" xxx"""
reg = r'href="(.+?\.pdf)">pdf'
pdfre = re.compile(reg)
pdflist = re.findall(pdfre, html)
dir_name = 'CVPR2016'
maxrows = len(pdflist)
pbar = prgbar.ProgressBar(total=maxrows)
if os.path.exists(dir_name) is False:
os.mkdir(dir_name)
for idx, pdfurl in enumerate(pdflist):
reg2 = r'papers/(.+?\.pdf)'
pdfre2 = re.compile(reg2)
filename = dir_name + '/' + re.findall(pdfre2, pdfurl)[0]
pbar.log('http://www.cv-foundation.org/openaccess/' + pdfurl)
if os.path.exists(filename) is True:
pbar.log('Exist')
else:
urllib.urlretrieve(
'http://www.cv-foundation.org/openaccess/' + pdfurl, filename)
pbar.update(index=(idx + 1))
pbar.finish()
def get_pdf(html):
""" xxx"""
reg = r'href="(.+?\.pdf)">pdf'
pdfre = re.compile(reg)
pdflist = re.findall(pdfre, html)
dir_name = 'CVPR2015'
maxrows = len(pdflist)
pbar = prgbar.ProgressBar(total=maxrows)
if os.path.exists(dir_name) is False:
os.mkdir(dir_name)
for idx, pdfurl in enumerate(pdflist):
reg2 = r'papers/(.+?\.pdf)'
pdfre2 = re.compile(reg2)
filename = dir_name + '/' + re.findall(pdfre2, pdfurl)[0]
pbar.log('http://www.cv-foundation.org/openaccess/' + pdfurl)
if os.path.exists(filename) is True:
pbar.log('Exist')
else:
urllib.urlretrieve(
'http://www.cv-foundation.org/openaccess/' + pdfurl, filename)
pbar.update(index=(idx + 1))
pbar.finish()
def get_pdf(html):
""" xxx"""
reg = r'href="(.+?\.pdf)">pdf'
pdfre = re.compile(reg)
pdflist = re.findall(pdfre, html)
dir_name = 'CVPR2013'
maxrows = len(pdflist)
pbar = prgbar.ProgressBar(total=maxrows)
if os.path.exists(dir_name) is False:
os.mkdir(dir_name)
for idx, pdfurl in enumerate(pdflist):
reg2 = r'papers/(.+?\.pdf)'
pdfre2 = re.compile(reg2)
filename = dir_name + '/' + re.findall(pdfre2, pdfurl)[0]
pbar.log('http://www.cv-foundation.org/openaccess/' + pdfurl)
if os.path.exists(filename) is True:
pbar.log('Exist')
else:
urllib.urlretrieve(
'http://www.cv-foundation.org/openaccess/' + pdfurl, filename)
pbar.update(index=(idx + 1))
pbar.finish()
def save_testcase(self, ip, testcases):
try:
count = 0
dir_name = "testcase_{0}".format(ip)
print("[\033[92mINFO\033[0m] Client {0} seems to not respond anymore, saving testcases".format(ip))
try:
os.mkdir(dir_name)
except OSError:
pass
for test in testcases:
with open("{0}/testcase_{1}.json".format(dir_name, count), "wb") as t:
t.write(test)
t.close()
count += 1
except Exception as e:
raise PJFBaseException(e.message if hasattr(e, "message") else str(e))
def save_testcase(self, testcase):
"""
Save all testcases collected during monitoring
"""
try:
if self.config.debug:
print("[\033[92mINFO\033[0m] Saving testcase...")
dir_name = "testcase_{0}".format(os.path.basename(shlex.split(self.config.process_to_monitor)[0]))
try:
os.mkdir(dir_name)
except OSError:
pass
for test in testcase:
with open("{0}/testcase_{1}.json".format(dir_name, self.testcase_count), "wb") as t:
t.write(test)
t.close()
self.testcase_count += 1
except Exception as e:
raise PJFBaseException(e.message if hasattr(e, "message") else str(e))
def mkdir_file(self):
"""
:return:?????????
"""
ini = U.ConfigIni()
result_file = str(ini.get_ini('test_case', 'log_file'))
result_file_every = result_file + '/' + \
time.strftime("%Y-%m-%d_%H_%M_%S{}".format(random.randint(10, 99)),
time.localtime(time.time()))
file_list = [
result_file,
result_file_every,
result_file_every + '/log',
result_file_every + '/per',
result_file_every + '/img',
result_file_every + '/status']
if not os.path.exists(result_file):
os.mkdir(result_file)
for file_path in file_list:
if not os.path.exists(file_path):
os.mkdir(file_path)
return result_file_every
def ignore(dest):
try:
with open(Git.ignore_file) as f:
exists = dest in f.read().splitlines()
except IOError:
exists = False
if not exists:
try:
ignore_file_parent_directory = os.path.dirname(Git.ignore_file)
if not os.path.exists(ignore_file_parent_directory):
os.mkdir(ignore_file_parent_directory)
with open(Git.ignore_file, 'a') as f:
f.write(dest.replace("\\", "/") + '\n')
except IOError:
error("Unable to write ignore file in \"%s\"" % os.path.join(getcwd(), Git.ignore_file), 1)
def unignore(dest):
try:
with open(Git.ignore_file) as f:
lines = f.read().splitlines()
except IOError:
lines = []
if dest in lines:
lines.remove(dest)
try:
ignore_file_parent_directory = os.path.dirname(Git.ignore_file)
if not os.path.exists(ignore_file_parent_directory):
os.mkdir(ignore_file_parent_directory)
with open(Git.ignore_file, 'w') as f:
f.write('\n'.join(lines) + '\n')
except IOError:
error("Unable to write ignore file in \"%s\"" % os.path.join(getcwd(), Git.ignore_file), 1)
# Repository object
def get_filename(self):
view = self.view
filename = view.file_name()
# create dir in current path with the name of current filename
dirname, _ = os.path.splitext(filename)
# create new image file under currentdir/filename_without_ext/filename_without_ext%d.png
fn_without_ext = os.path.basename(dirname)
if not os.path.lexists(dirname):
os.mkdir(dirname)
i = 0
while True:
# relative file path
rel_filename = os.path.join("%s/%s%d.png" % (fn_without_ext, fn_without_ext, i))
# absolute file path
abs_filename = os.path.join(dirname, "%s%d.png" % ( fn_without_ext, i))
if not os.path.exists(abs_filename):
break
i += 1
print("save file: " + abs_filename + "\nrel " + rel_filename)
return abs_filename, rel_filename
def get_filename(self):
view = self.view
filename = view.file_name()
# create dir in current path with the name of current filename
dirname, _ = os.path.splitext(filename)
# create new image file under currentdir/filename_without_ext/filename_without_ext%d.png
fn_without_ext = os.path.basename(dirname)
if not os.path.lexists(dirname):
os.mkdir(dirname)
i = 0
while True:
# relative file path
rel_filename = os.path.join("%s/%s%d.png" % (fn_without_ext, fn_without_ext, i))
# absolute file path
abs_filename = os.path.join(dirname, "%s%d.png" % ( fn_without_ext, i))
if not os.path.exists(abs_filename):
break
i += 1
print("save file: " + abs_filename + "\nrel " + rel_filename)
return abs_filename, rel_filename
def run_devpi_command(project, logger, params) :
reports_dir = project.expand_path("$dir_reports/devpi")
if not os.path.exists(reports_dir) :
os.mkdir(reports_dir)
logger.debug("Executing devpi command %s", params)
output_file_path = os.path.join(reports_dir, params[0].replace("/", ""))
with open(output_file_path, "w") as output_file :
commandexec = ["devpi"]
commandexec.extend(params)
working_dir = project.expand_path("$dir_dist")
process = subprocess.Popen(commandexec, cwd=working_dir, stdout=output_file, stderr=output_file, shell=False)
return_code = process.wait()
if return_code != 0 :
raise BuildFailedException("Error while executing devpi command %s, see %s for details" % (params, output_file_path))
def run_setup_commands(project, logger, commands) :
reports_dir = project.expand_path("$dir_reports/distutils")
if not os.path.exists(reports_dir) :
os.mkdir(reports_dir)
setup_script = project.expand_path("$dir_dist/setup.py")
for command in commands :
logger.debug("Executing distutils command %s", command)
output_file_path = os.path.join(reports_dir, command.replace("/", ""))
with open(output_file_path, "w") as output_file :
commandexec = [sys.executable, setup_script]
commandexec.extend(command.split())
working_dir = project.expand_path("$dir_dist")
process = subprocess.Popen(commandexec, cwd=working_dir, stdout=output_file, stderr=output_file, shell=False)
return_code = process.wait()
if return_code != 0 :
raise BuildFailedException("Error while executing setup command %s, see %s for details" % (command, output_file_path))
def plotGeneratedImages(epoch,example=100,dim=(10,10),figsize=(10,10)):
noise = np.random.normal(0,1,size=(example,randomDim))
generatedImage = generator.predict(noise)
generatedImage = generatedImage.reshape(example,28,28)
plt.figure(figsize=figsize)
for i in range(example):
plt.subplot(dim[0],dim[1],i+1)
plt.imshow(generatedImage[i],interpolation='nearest',cmap='gray')
'''drop the x and y axis'''
plt.axis('off')
plt.tight_layout()
if not os.path.exists('generated_image'):
os.mkdir('generated_image')
plt.savefig('generated_image/wgan_generated_img_epoch_%d.png' % epoch)
def setup_compiler_paths(self, clang_path):
if "ccache" in self.mode.value:
cache_dir = os.path.join(self.tmp_directory.path, "ccache")
os.mkdir(cache_dir)
os.environ["CCACHE_DIR"] = cache_dir
if "clang-hash" in self.mode.value:
cache_dir = os.path.join(self.tmp_directory.path, "clang-hash-cache")
os.mkdir(cache_dir)
os.environ["CLANG_HASH_CACHE"] = cache_dir
if self.mode.value == "normal":
CC = os.path.join(clang_path, "build/wrappers/clang-normal")
elif self.mode.value == "clang-hash":
# CC = os.path.join(clang_path, "build/wrappers/clang-hash-stop")
#elif self.mode.value == "clang-hash-collect":
CC = os.path.join(clang_path, "build/wrappers/clang-hash-collect")
elif self.mode.value == "ccache-clang-hash":
CC = os.path.join(clang_path, "build/wrappers/clang-ccache-hash-stop")
elif self.mode.value == "ccache":
CC = os.path.join(clang_path, "build/wrappers/clang-ccache")
else:
raise RuntimeError("Not a valid mode")
os.environ['CC'] = CC
self.CC = CC
def __init__(self):
self.clients = {
# "HaobtcCNY": haobtccny.PrivateHaobtcCNY(config.HAOBTC_API_KEY, config.HAOBTC_SECRET_TOKEN),
"BrokerCNY": brokercny.PrivateBrokerCNY(),
}
self.cny_balance = 0
self.btc_balance = 0
self.cny_frozen = 0
self.btc_frozen = 0
self.cny_total = 0
self.btc_total = 0
try:
os.mkdir(self.out_dir)
except:
pass