本文整理汇总了Python中unipath.Path.mkdir方法的典型用法代码示例。如果您正苦于以下问题:Python Path.mkdir方法的具体用法?Python Path.mkdir怎么用?Python Path.mkdir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unipath.Path
的用法示例。
在下文中一共展示了Path.mkdir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import mkdir [as 别名]
def run(self, context):
if not self.directory_name.isabsolute():
directory = Path(Path(context['package_project_dir']), self.directory_name)
else:
directory = Path(context['package_root'], Path(strip_root(self.directory_name)))
directory.mkdir(parents=True, mode=self.mode)
示例2: sort_episode
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import mkdir [as 别名]
def sort_episode(series_name, episode, torrent_path):
# Ensure the series directory exists
series_dir = Path(SERIES_DIR, series_name)
series_dir.mkdir(True)
if torrent_path.isdir():
files = [torrent_path.listdir('*.' + ext) for ext in VIDEO_FILES]
files = [f for sublist in files for f in sublist]
files = remove_samples(files)
logging.debug('List of files: {}'.format(files))
if len(files) == 0:
logging.critical('No video file found in series directory!')
sys.exit(1)
src_file = files[0]
dst_file = Path(series_dir,
series_name + ' - ' + episode + files[0].ext)
else:
if torrent_path.ext.replace('.', '') not in VIDEO_FILES:
logging.warning('Unknown video file extention: {}'.format(
torrent_path.ext))
src_file = torrent_path
dst_file = Path(series_dir, series_name + ' - ' + episode + \
torrent_path.ext)
logging.info('Copying single file to destination: {}'.format(
dst_file))
copy_file(src_file, dst_file)
示例3: create
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import mkdir [as 别名]
def create(dataset, work_dir):
# Find all the pages in the dataset
img_dir = Path(Path.cwd().ancestor(1), 'data/hwr_data/pages', dataset)
ann_dir = Path(Path.cwd().ancestor(1), 'data/charannotations')
images = img_dir.listdir('*.jpg')
annotations = ann_dir.listdir(dataset + '*.words')
files = merge(images, annotations)
# Create character segmentations
stats = {}
for f in files:
# Preprocess
logging.info("Preprocessing %s", str(f[0]))
pagesPathFolder = Path(work_dir, 'pages')
pagesPathFolder.mkdir()
pagePath = Path(pagesPathFolder, f[0].stem + '.ppm')
img = cv2.imread(f[0], cv2.IMREAD_GRAYSCALE)
img = preprocess(img)
cv2.imwrite(pagePath, img)
# Segment
segmentPathFolder = Path(work_dir, 'segments')
segmentPathFolder.mkdir()
e = ET.parse(f[1]).getroot()
logging.info("Segmenting %s", str(f[0]))
segment(img, e, segmentPathFolder, stats)
print_statistics(stats, dataset)
示例4: savejson
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import mkdir [as 别名]
def savejson(d):
status = d['status']
if status.startswith('Pendent'):
status = 'Pendent'
carpeta = Path(exportpath, status, d['year'], d['month'])
carpeta.mkdir(parents=True)
fpath = carpeta.child('{}.json'.format(d['id']))
with open(fpath, 'w') as f:
json.dump(d, f, sort_keys=True, indent=4, separators=(',', ': '))
示例5: copy_files
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import mkdir [as 别名]
def copy_files(context):
# copy files from deployments
if context["deployment_files_dir"].exists() and context["deployment_files_dir"].isdir():
for i in context["deployment_files_dir"].walk():
rel_path = get_relative_path(i, context["deployment_files_dir"])
target = Path(context["package_project_dir"], rel_path)
if i.isdir():
target.mkdir(parents=True, mode=self.mode)
elif i.isfile():
local("cp -R %(i)s %(target)s" % locals())
示例6: get
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import mkdir [as 别名]
def get(project=None):
"""Get the data from different experiments.
Warning! Experiment directories are expected in a particular location
outside of this (words-in-transition) directory.
Options are:
telephone-app
acoustic-similarity
learning-sound-names
"""
if project is None or project == 'telephone-app':
app_dir = Path('../telephone-app')
snapshot_dir = Path(app_dir, 'words-in-transition')
if src_dir.exists():
src_dir.rmtree()
copytree(snapshot_dir, src_dir)
if project is None or project == 'acoustic-similarity':
# src
proj_dir = Path('../acoustic-similarity/data')
judgments = Path(proj_dir, 'judgments')
# dst
acoustic_similarity_dir = Path(data_raw, 'acoustic-similarity')
if not acoustic_similarity_dir.isdir():
acoustic_similarity_dir.mkdir()
# copy the csvs in the root proj data dir
for csv in proj_dir.listdir('*.csv'):
csv.copy(Path(acoustic_similarity_dir, csv.name))
# concat and save judgments files
judgments_csv = Path(acoustic_similarity_dir, 'judgments.csv')
judgments = [pd.read_csv(x) for x in judgments.listdir('*.csv')]
if judgments:
(pd.concat(judgments, ignore_index=True)
.to_csv(judgments_csv, index=False))
if project is None or project == 'learning-sound-names':
src = Path('../learning-sound-names/data')
dst = Path(data_raw, 'learning_sound_names.csv')
data = pd.concat([pd.read_csv(x) for x in src.listdir('LSN*.csv')])
data['is_correct'] = data.is_correct.astype(int)
data.to_csv(dst, index=False)
# also get subject info and questionnaire data
to_get = ['questionnaire_v1', 'subject_info']
for x in to_get:
src_file = Path(src, '{}.csv'.format(x))
dst_file = Path(data_raw, 'learning_sound_names_{}.csv'.format(x))
run('cp {} {}'.format(src_file, dst_file))
示例7: dict2dir
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import mkdir [as 别名]
def dict2dir(dir, dic, mode="w"):
dir = Path(dir)
if not dir.exists():
dir.mkdir()
for filename, content in dic.items():
p = Path(dir, filename)
if isinstance(content, dict):
dict2dir(p, content)
continue
f = open(p, mode)
f.write(content)
f.close()
示例8: process
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import mkdir [as 别名]
def process(appname):
appdir = Path(appname)
if not appdir.isdir():
print("Error: there is no app called {0}.".format(appdir))
sys.exit(1)
# else
static = Path(appname, 'static', appname)
static.mkdir(True)
templates = Path(appname, 'templates', appname)
templates.mkdir(True)
urls = Path(appname, 'urls.py')
if not urls.isfile():
urls.write_file(urls_py)
示例9: segment
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import mkdir [as 别名]
def segment(img, annotation, work_dir, stats):
sides = ['left', 'top', 'right', 'bottom']
# Parse the given sentences
for sentence in annotation:
for word in sentence:
for char in word:
c = char.get('text')
if c in '!-,.':
continue # Skip stupid labels
cdir = Path(work_dir, c)
cdir.mkdir()
f = Path(cdir, str(uuid.uuid1()) + '.ppm')
rect = {side: int(char.get(side)) for side in sides}
# Correct for swapped coordinates
if rect['top'] > rect['bottom']:
rect['top'], rect['bottom'] = rect['bottom'], rect['top']
if rect['left'] > rect['right']:
rect['left'], rect['right'] = rect['right'], rect['left']
cropped_im = img[rect['top']:rect['bottom'], rect['left']:rect['right']]
# Remove rows from the top if they're white
while cropped_im.shape[1] > 0 and cropped_im.shape[0] > 0 \
and min(cropped_im[0,:]) == 255:
cropped_im = cropped_im[1:,:]
# Remove from the bottom
while cropped_im.shape[1] > 0 and cropped_im.shape[0] > 0 \
and min(cropped_im[-1,:]) == 255:
cropped_im = cropped_im[:-1,:]
# Remove from the left
while cropped_im.shape[1] > 0 and cropped_im.shape[0] > 0 \
and min(cropped_im[:,0]) == 255:
cropped_im = cropped_im[:,1:]
# Remove from the right
while cropped_im.shape[1] > 0 and cropped_im.shape[0] > 0 \
and min(cropped_im[:,-1]) == 255:
cropped_im = cropped_im[:,:-1]
if cropped_im.shape[0] <= 5 or cropped_im.shape[1] <= 5:
print "Discarding image"
continue
aspect_ratio = cropped_im.shape[0] / float(cropped_im.shape[1])
if not (1/3.0) <= aspect_ratio <= 5.5:
print "Image with wrong aspect ratio:", aspect_ratio, c
continue
cv2.imwrite(f, cropped_im)
# Add to statistics
if c not in stats.keys():
stats[c] = {'width': [], 'height': []}
stats[c]['width'].append(cropped_im.shape[1])
stats[c]['height'].append(cropped_im.shape[0])
示例10: download_survey_responses
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import mkdir [as 别名]
def download_survey_responses(survey_name):
"""Download the survey data.
Args:
survey_name: 'sound_similarity_6' or 'sound_similarity_4'
"""
qualtrics = Qualtrics(**get_creds())
responses = qualtrics.get_survey_responses(survey_name)
survey_dir = Path(exp_dir, survey_name)
if not survey_dir.exists():
survey_dir.mkdir()
output = Path(survey_dir, survey_name + '.csv')
responses.to_csv(output, index=False)
示例11: create
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import mkdir [as 别名]
def create():
# create a clean temporary directory
work_dir = Path("tmp")
work_dir.mkdir()
lexicon = create_lexicon()
lexicon_path = Path(work_dir, "lexicon.csv")
w = csv.writer(open(lexicon_path, "w"))
for key, val in lexicon.items():
w.writerow([key, val])
return lexicon
return lexicon
示例12: gather
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import mkdir [as 别名]
def gather(ctx):
"""Gather the experiment data and put it in the R pkg data-raw folder.
Currently set to get the fourth run experiment data.
"""
dest_dir = Path('propertyverificationdata', 'data-raw', 'question_first',
'fourth_run', 'data')
if not dest_dir.exists():
dest_dir.mkdir(parents=True)
data_files = Path('experiment/data').listdir('PV*csv')
for data_file in data_files:
dest = Path(dest_dir, data_file.name)
run('cp {src} {dest}'.format(src=data_file, dest=dest))
# move the subj info sheet
run('cp experiment/subj_info.csv {}'.format(dest_dir.parent))
示例13: main
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import mkdir [as 别名]
def main():
global conn
opts, args = parser.parse_args()
common.init_logging(opts.log_sql)
if opts.debug:
log.setLevel(logging.DEBUG)
if len(args) != 3:
parser.error("wrong number of command-line arguments")
site, dburl, output_dir = args
engine = sa.create_engine(dburl)
log.debug("Starting")
conn = engine.connect()
output_dir = Path(output_dir)
output_dir.mkdir()
output_raw_referers(site, conn, output_dir, True)
output_raw_referers(site, conn, output_dir, False)
output_search_terms(site, conn, output_dir)
示例14: main
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import mkdir [as 别名]
def main():
if len(sys.argv) != 2 or sys.argv[1] not in ['KNMP', 'Stanford', 'both']:
print("Usage: python %s <dataset>" % sys.argv[0])
print("\tDataset should be either 'KNMP' or 'Stanford' or 'both'")
sys.exit(1)
# create a clean temporary directory
if os.path.exists("tmp"):
shutil.rmtree("tmp")
os.makedirs("tmp")
work_dir = Path("tmp")
work_dir.rmtree()
work_dir.mkdir()
if sys.argv[1] in ['KNMP', 'both']:
create('KNMP', work_dir)
if sys.argv[1] in ['Stanford', 'both']:
create('Stanford', work_dir)
示例15: env_create_package_files
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import mkdir [as 别名]
def env_create_package_files(workspace, packages, files):
for p in packages:
if files:
for f in files:
f = Path(workspace, 'test', p, f)
f.mkdir(parents=True)
version = '.'.join([x for x in f.name if x.isdigit()])
i = env_create_package_pkginfo(p, version)
Path(f, '%s.egg-info' % f.name).mkdir()
Path(f, 'PKG-INFO').write_file(i)
Path(f, '%s.egg-info' % f.name, 'PKG-INFO').write_file(i)
os.chdir(f.parent)
tar = tarfile.open('%s.tar.gz' % f, 'w:gz')
tar.add('%s' % f.name)
tar.close()
f.rmtree()
else:
Path(workspace, 'test', p).mkdir(parents=True)