本文整理汇总了Python中unipath.Path.exists方法的典型用法代码示例。如果您正苦于以下问题:Python Path.exists方法的具体用法?Python Path.exists怎么用?Python Path.exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unipath.Path
的用法示例。
在下文中一共展示了Path.exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: double_dump_test
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import exists [as 别名]
def double_dump_test():
"""
Perform a "double dump test" on every demo database.
TODO: convert this to a Lino management command.
"""
raise Exception("Not yet converted after 20150129")
if len(env.demo_databases) == 0:
return
a = Path(env.temp_dir, 'a')
b = Path(env.temp_dir, 'b')
rmtree_after_confirm(a)
rmtree_after_confirm(b)
#~ if not confirm("This will possibly break the demo databases. Are you sure?"):
#~ return
#~ a.mkdir()
with lcd(env.temp_dir):
for db in env.demo_databases:
if a.exists():
a.rmtree()
if b.exists():
b.rmtree()
local("django-admin.py dump2py --settings=%s --traceback a" % db)
local(
"django-admin.py run --settings=%s --traceback a/restore.py" %
db)
local("django-admin.py dump2py --settings=%s --traceback b" % db)
local("diff a b")
示例2: check_avatar
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import exists [as 别名]
def check_avatar(self):
avatar_path = Path("/var/www/loka3/static/media/" + str(self.avatar))
avatar_sm_path = Path("/var/www/loka3/static/media/" + str(self.avatar_sm))
print "{} exists: {}".format(avatar_path, avatar_path.exists())
if not avatar_path.exists() or not avatar_sm_path.exists():
print "Wiping avatars for", self.name
self.avatar = None
self.avatar_sm = None
self.save()
示例3: handle
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import exists [as 别名]
def handle(self, *args, **options):
directionals_path = Path(self.BASE_DIR, 'directionals.txt')
if directionals_path.exists():
Directional.load_directionals(directionals_path)
states_path = Path(self.BASE_DIR, 'states.txt')
if states_path.exists():
State.load_states(states_path)
street_types_path = Path(self.BASE_DIR, 'street_types.txt')
if street_types_path.exists():
StreetType.load_street_types(street_types_path)
示例4: boostrap_nltk_data
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import exists [as 别名]
def boostrap_nltk_data():
nltk.data.path.append('./data/')
nltkdata_exists = Path('./data/tokenizers/punkt/english.pickle')
if not nltkdata_exists.exists():
logging.info("Downloading NLTK Data")
nltk.download('punkt', './data')
示例5: create_file
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import exists [as 别名]
def create_file(self, name, contents):
"""
Creates a gzip file
:param name: (str) name of the file to be created
:param contents: (str) contents to be written in the file
:return: (str or False) path of the created file
"""
# write a tmp file
tmp = mkstemp()[1]
with gzip.open(tmp, 'wb') as handler:
handler.write(contents)
# send it to the FTP server
if self.ftp:
self.ftp.storbinary('STOR {}'.format(name), open(tmp, 'rb'))
return '{}{}'.format(self.path, name)
# or save it locally
else:
new_path = Path(self.path).child(name)
tmp_path = Path(tmp)
tmp_path.copy(new_path)
if new_path.exists():
return new_path.absolute()
return False
示例6: PickleStorage
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import exists [as 别名]
class PickleStorage(QueueStorage):
"""docstring for PickleStorage"""
def __init__(self):
super(PickleStorage, self).__init__()
self._prepareStorage()
def _prepareStorage(self):
default = Path(ingo.active_project.base_path, '/queue')
self._storage_path = Path(self.config.get('path', default))
self._storage_name = 'items.pckl'
if not self._storage_path.exists():
raise Exception("PickleStorage storage path (%s) doesn't exist!" % self._storage_path)
def load(self):
storage_file = open(Path(self._storage_path, self._storage_name), 'rb')
results = pickle.load(storage_file)
storage_file.close()
return results
def store(self, items):
storage_file = open(Path(self._storage_path, self._storage_name), 'wb')
results = pickle.dump(items, storage_file)
storage_file.close()
return results
def clear(self):
self.store([])
示例7: superuser
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import exists [as 别名]
def superuser(pubkey=None, username=None):
"""
fab env superuser
"""
env.user = 'root'
keyfile = Path(pubkey or Path('~', '.ssh', 'id_rsa.pub')).expand()
if not keyfile.exists():
abort('Public key file does not exist: %s' % keyfile)
username = username or prompt('Username: ')
password = getpass('Password: ')
password = local('perl -e \'print crypt(\"%s\", \"password\")\'' % (password),
capture=True)
with open(keyfile, 'r') as f:
pubkey = f.read(65535)
commands = (
'useradd -m -s /bin/bash -p {password} {username}',
'mkdir ~{username}/.ssh -m 700',
'echo "{pubkey}" >> ~{username}/.ssh/authorized_keys',
'chmod 644 ~{username}/.ssh/authorized_keys',
'chown -R {username}:{username} ~{username}/.ssh',
'usermod -a -G sudo {username}',
)
for command in commands:
run(command.format(**locals()))
示例8: handle
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import exists [as 别名]
def handle(self, *args, **options):
from ....media.models import MediaFile
from ...models import Transcript
if len(args) != 1:
raise CommandError('Provide media URL.')
(url,) = args
local_path = Path(url)
if local_path.exists():
url = 'file://{}'.format(local_path.absolute())
media_file = MediaFile.objects.create(
data_url=url,
)
if options['verbosity']:
self.stdout.write('Created media file: {}'.format(media_file))
transcript = Transcript.objects.create(
name=url,
)
if options['verbosity']:
self.stdout.write('Created transcript: {}'.format(transcript))
示例9: setup_babel_userdocs
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import exists [as 别名]
def setup_babel_userdocs(babelcmd):
"""Create userdocs .po files if necessary."""
userdocs = env.root_dir.child('userdocs')
if not userdocs.isdir():
return
locale_dir = userdocs.child('translations')
for domain in locale_dir.listdir('*.pot', names_only=True):
domain = domain[:-4]
for loc in env.languages:
if loc != env.languages[0]:
po_file = Path(locale_dir, loc, 'LC_MESSAGES', '%s.po' %
domain)
mo_file = Path(locale_dir, loc, 'LC_MESSAGES', '%s.mo' %
domain)
pot_file = Path(locale_dir, '%s.pot' % domain)
if babelcmd == 'init_catalog' and po_file.exists():
print("Skip %s because file exists." % po_file)
#~ elif babelcmd == 'compile_catalog' and not mo_file.needs_update(po_file):
#~ print "Skip %s because newer than .po" % mo_file
else:
args = ["python", "setup.py"]
args += [babelcmd]
args += ["-l", loc]
args += ["--domain", domain]
args += ["-d", locale_dir]
#~ args += [ "-o" , po_file ]
#~ if babelcmd == 'init_catalog':
if babelcmd == 'compile_catalog':
args += ["-i", po_file]
else:
args += ["-i", pot_file]
cmd = ' '.join(args)
#~ must_confirm(cmd)
local(cmd)
示例10: enviar_email_con_cupon
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import exists [as 别名]
def enviar_email_con_cupon(modeladmin, request, queryset):
leads_incorrectos = 0
leads_correctos = 0
for lead in queryset:
if lead.enviado_en_csv is True and lead.enviado_cupon is False and lead.colectivo_validado is True:
for fichero in os.listdir(settings.COUPONS_ROOT):
if fnmatch.fnmatch(fichero, str(lead.id)+'_*.pdf'):
cupon_fichero = Path(settings.COUPONS_ROOT, fichero)
if cupon_fichero.exists():
codigo = fichero.split("_")[1].split(".")[0]
url_cupon = settings.BASE_URL+'/static/coupons/'+fichero
mail = EmailMultiAlternatives(
subject="Mi cupón de 10€ de Juguetes Blancos",
body='Descarga tu cupon aqui: '+url_cupon+' </p>',
from_email="Rocio, JueguetesBlancos <[email protected]>",
to=[lead.email]
)
mail.attach_alternative(render_to_string('leads/email_cupon.html', {'lead': lead, 'url_cupon': url_cupon}), "text/html")
mail.send()
lead.enviado_cupon = True
lead.codigo_cupon = codigo
lead.save()
leads_correctos = leads_correctos+1
else:
leads_incorrectos = leads_incorrectos+1
messages.success(request, str(leads_correctos)+' Email/s enviado Correctamente')
messages.error(request, str(leads_incorrectos)+' Leads no cumplian las condiciones.')
示例11: test_pdf_to_png
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import exists [as 别名]
def test_pdf_to_png(self):
testdir = Path(r"C:\tmp\pdfprocessing\test")
testdir.chdir()
input_file = "testpdf.pdf"
output_file = Path(r"C:\tmp\pdfprocessing\test\test_gs_pdf_to_png.png")
gs = GhostScript()
gs.pdf_to_png(input_file,output_file)
self.assertTrue(output_file.exists(),"File")
示例12: delete
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import exists [as 别名]
def delete(self, lookup_repo_name):
repo = Repository(lookup_repo_name, self.path, self.git)
dest = Path(self.path, 'conf/repos/%s.conf' % lookup_repo_name)
if not dest.exists():
raise ValueError('Repository %s not existing.' % lookup_repo_name)
dest.remove()
self.git.commit([str(dest)], 'Deleted repo %s.' % lookup_repo_name)
return repo
示例13: boostrap_crawled_files
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import exists [as 别名]
def boostrap_crawled_files():
# If we don't have the right files, grab them.
crawled_page = Path('./data/1.html')
if not crawled_page.exists():
logging.info("Crawling Exeter Book from en.wikisource.org")
run_spider()
else:
logging.info("Crawled files in place")
示例14: test_resolve
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import exists [as 别名]
def test_resolve(self):
p1 = Path(self.link_to_images_dir, "image3.png")
p2 = p1.resolve()
assert p1.components()[-2:] == ["link_to_images_dir", "image3.png"]
assert p2.components()[-2:] == ["images", "image3.png"]
assert p1.exists()
assert p2.exists()
assert p1.same_file(p2)
assert p2.same_file(p1)
示例15: delete
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import exists [as 别名]
def delete(self, name):
user = User(self.path, self.git, name)
dest = Path(self.path, 'keydir/%s' % name)
if not dest.exists():
raise ValueError('Repository %s not existing.' % name)
dest.rmtree()
self.git.commit([str(dest)], 'Deleted user %s.' % name)
return user