本文整理汇总了Python中tempfile._RandomNameSequence函数的典型用法代码示例。如果您正苦于以下问题:Python _RandomNameSequence函数的具体用法?Python _RandomNameSequence怎么用?Python _RandomNameSequence使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_RandomNameSequence函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_push_unlocks_repository_git
def test_push_unlocks_repository_git(self, webserver):
# enable locking
fork_name = '%s_fork%s' % (GIT_REPO, _RandomNameSequence().next())
fixture.create_fork(GIT_REPO, fork_name)
r = Repository.get_by_repo_name(fork_name)
r.enable_locking = True
Session().commit()
#clone some temp
DEST = _get_tmp_dir()
clone_url = webserver.repo_url(fork_name)
stdout, stderr = Command(TESTS_TMP_PATH).execute('git clone', clone_url, DEST)
#check for lock repo after clone
r = Repository.get_by_repo_name(fork_name)
assert r.locked[0] == User.get_by_username(TEST_USER_ADMIN_LOGIN).user_id
#push is ok and repo is now unlocked
stdout, stderr = _add_files_and_push(webserver, 'git', DEST, clone_url=clone_url)
_check_proper_git_push(stdout, stderr)
assert ('remote: Released lock on repo `%s`' % fork_name) in stderr
#we need to cleanup the Session Here !
Session.remove()
r = Repository.get_by_repo_name(fork_name)
assert r.locked == [None, None]
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:25,代码来源:test_vcs_operations.py
示例2: test_clone_with_credentials
def test_clone_with_credentials(no_errors=False, repo=HG_REPO, method=METHOD,
seq=None, backend='hg'):
cwd = path = jn(TESTS_TMP_PATH, repo)
if seq is None:
seq = _RandomNameSequence().next()
try:
shutil.rmtree(path, ignore_errors=True)
os.makedirs(path)
#print 'made dirs %s' % jn(path)
except OSError:
raise
clone_url = 'http://%(user)s:%(pass)[email protected]%(host)s/%(cloned_repo)s' % \
{'user': USER,
'pass': PASS,
'host': HOST,
'cloned_repo': repo, }
dest = path + seq
if method == 'pull':
stdout, stderr = Command(cwd).execute(backend, method, '--cwd', dest, clone_url)
else:
stdout, stderr = Command(cwd).execute(backend, method, clone_url, dest)
print stdout,'sdasdsadsa'
if not no_errors:
if backend == 'hg':
assert """adding file changes""" in stdout, 'no messages about cloning'
assert """abort""" not in stderr , 'got error from clone'
elif backend == 'git':
assert """Cloning into""" in stdout, 'no messages about cloning'
开发者ID:adamscieszko,项目名称:rhodecode,代码行数:32,代码来源:test_concurency.py
示例3: test_push_new_file
def test_push_new_file(commits=15, with_clone=True):
if with_clone:
test_clone_with_credentials(no_errors=True)
cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
added_file = jn(path, '%ssetupążźć.py' % _RandomNameSequence().next())
Command(cwd).execute('touch %s' % added_file)
Command(cwd).execute('hg add %s' % added_file)
for i in xrange(commits):
cmd = """echo 'added_line%s' >> %s""" % (i, added_file)
Command(cwd).execute(cmd)
cmd = """hg ci -m 'commited new %s' -u '%s' %s """ % (i,
'Marcin Kuźminski <[email protected]>',
added_file)
Command(cwd).execute(cmd)
push_url = 'http://%(user)s:%(pass)[email protected]%(host)s/%(cloned_repo)s' % \
{'user':USER,
'pass':PASS,
'host':HOST,
'cloned_repo':HG_REPO,
'dest':jn(TESTS_TMP_PATH, HG_REPO)}
Command(cwd).execute('hg push --verbose --debug %s' % push_url)
开发者ID:q210,项目名称:rhodecode,代码行数:29,代码来源:test_hg_operations.py
示例4: CreateCustomVRT
def CreateCustomVRT(vrtxml, vrtcols, vrtrows):
try:
vrt = []
vrt.append('<VRTDataset rasterXSize="%s" rasterYSize="%s">' % (vrtcols, vrtrows))
vrt.append("%s" % vrtxml)
vrt.append("</VRTDataset>")
vrtfn = "/vsimem/%s.vrt" % tempfile._RandomNameSequence().next()
write_vsimem(vrtfn, "\n".join(vrt))
return vrtfn
except:
return None
开发者ID:simonaoliver,项目名称:metageta,代码行数:11,代码来源:geometry.py
示例5: test_push_new_file_git
def test_push_new_file_git(self, webserver):
DEST = _get_tmp_dir()
clone_url = webserver.repo_url(GIT_REPO)
stdout, stderr = Command(TESTS_TMP_PATH).execute('git clone', clone_url, DEST)
# commit some stuff into this repo
fork_name = '%s_fork%s' % (GIT_REPO, _RandomNameSequence().next())
fixture.create_fork(GIT_REPO, fork_name)
clone_url = webserver.repo_url(fork_name)
stdout, stderr = _add_files_and_push(webserver, 'git', DEST, clone_url=clone_url)
print [(x.repo_full_path,x.repo_path) for x in Repository.query()] # TODO: what is this for
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:11,代码来源:test_vcs_operations.py
示例6: generate_api_key
def generate_api_key(str_, salt=None):
"""
Generates API KEY from given string
:param str_:
:param salt:
"""
if salt is None:
salt = _RandomNameSequence().next()
return hashlib.sha1(str_ + salt).hexdigest()
开发者ID:adamscieszko,项目名称:rhodecode,代码行数:12,代码来源:auth.py
示例7: _add_files_and_push
def _add_files_and_push(webserver, vcs, DEST, ignoreReturnCode=False, files_no=3,
clone_url=None, username=TEST_USER_ADMIN_LOGIN, password=TEST_USER_ADMIN_PASS):
"""
Generate some files, add it to DEST repo and push back
vcs is git or hg and defines what VCS we want to make those files for
:param vcs:
:param DEST:
"""
# commit some stuff into this repo
cwd = os.path.join(DEST)
#added_file = '%ssetupążźć.py' % _RandomNameSequence().next()
added_file = '%ssetup.py' % _RandomNameSequence().next()
Command(cwd).execute('touch %s' % added_file)
Command(cwd).execute('%s add %s' % (vcs, added_file))
email = '[email protected]'
if os.name == 'nt':
author_str = 'User <%s>' % email
else:
author_str = 'User ǝɯɐᴎ <%s>' % email
for i in xrange(files_no):
cmd = """echo "added_line%s" >> %s""" % (i, added_file)
Command(cwd).execute(cmd)
if vcs == 'hg':
cmd = """hg commit -m "committed new %s" -u "%s" "%s" """ % (
i, author_str, added_file
)
elif vcs == 'git':
cmd = """git commit -m "committed new %s" --author "%s" "%s" """ % (
i, author_str, added_file
)
# git commit needs EMAIL on some machines
Command(cwd).execute(cmd, EMAIL=email)
# PUSH it back
_REPO = None
if vcs == 'hg':
_REPO = HG_REPO
elif vcs == 'git':
_REPO = GIT_REPO
if clone_url is None:
clone_url = webserver.repo_url(_REPO, username=username, password=password)
stdout = stderr = None
if vcs == 'hg':
stdout, stderr = Command(cwd).execute('hg push --verbose', clone_url, ignoreReturnCode=ignoreReturnCode)
elif vcs == 'git':
stdout, stderr = Command(cwd).execute('git push --verbose', clone_url, "master", ignoreReturnCode=ignoreReturnCode)
return stdout, stderr
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:52,代码来源:test_vcs_operations.py
示例8: test_push_new_file_hg
def test_push_new_file_hg(self, webserver):
DEST = _get_tmp_dir()
clone_url = webserver.repo_url(HG_REPO)
stdout, stderr = Command(TESTS_TMP_PATH).execute('hg clone', clone_url, DEST)
fork_name = '%s_fork%s' % (HG_REPO, _RandomNameSequence().next())
fixture.create_fork(HG_REPO, fork_name)
clone_url = webserver.repo_url(fork_name)
stdout, stderr = _add_files_and_push(webserver, 'hg', DEST, clone_url=clone_url)
assert 'pushing to' in stdout
assert 'Repository size' in stdout
assert 'Last revision is now' in stdout
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:13,代码来源:test_vcs_operations.py
示例9: _add_files_and_push
def _add_files_and_push(vcs, DEST, **kwargs):
"""
Generate some files, add it to DEST repo and push back
vcs is git or hg and defines what VCS we want to make those files for
:param vcs:
:param DEST:
"""
# commit some stuff into this repo
cwd = path = jn(DEST)
#added_file = jn(path, '%ssetupążźć.py' % _RandomNameSequence().next())
added_file = jn(path, '%ssetup.py' % _RandomNameSequence().next())
Command(cwd).execute('touch %s' % added_file)
Command(cwd).execute('%s add %s' % (vcs, added_file))
for i in xrange(kwargs.get('files_no', 3)):
cmd = """echo 'added_line%s' >> %s""" % (i, added_file)
Command(cwd).execute(cmd)
author_str = 'Marcin Kuźminski <[email protected]>'
if vcs == 'hg':
cmd = """hg commit -m 'commited new %s' -u '%s' %s """ % (
i, author_str, added_file
)
elif vcs == 'git':
cmd = """EMAIL="[email protected]" git commit -m 'commited new %s' --author '%s' %s """ % (
i, author_str, added_file
)
Command(cwd).execute(cmd)
# PUSH it back
_REPO = None
if vcs == 'hg':
_REPO = HG_REPO
elif vcs == 'git':
_REPO = GIT_REPO
kwargs['dest'] = ''
clone_url = _construct_url(_REPO, **kwargs)
if 'clone_url' in kwargs:
clone_url = kwargs['clone_url']
stdout = stderr = None
if vcs == 'hg':
stdout, stderr = Command(cwd).execute('hg push --verbose', clone_url)
elif vcs == 'git':
stdout, stderr = Command(cwd).execute('git push --verbose', clone_url + " master")
return stdout, stderr
开发者ID:zhumengyuan,项目名称:kallithea,代码行数:47,代码来源:manual_test_vcs_operations.py
示例10: generate_api_key
def generate_api_key(username, salt=None):
"""
Generates unique API key for given username, if salt is not given
it'll be generated from some random string
:param username: username as string
:param salt: salt to hash generate KEY
:rtype: str
:returns: sha1 hash from username+salt
"""
from tempfile import _RandomNameSequence
import hashlib
if salt is None:
salt = _RandomNameSequence().next()
return hashlib.sha1(username + salt).hexdigest()
开发者ID:lmamsen,项目名称:rhodecode,代码行数:17,代码来源:__init__.py
示例11: random_track
def random_track(number_of_features=15000000, size=1000, jump=1000, orig_start=0, chrs=20):
import random, tempfile
yield 'track type=bed name="Features" description="Intervals" source="Random generator"\n'
name_gen = tempfile._RandomNameSequence()
chr = 0
for i in range(number_of_features):
if i % (number_of_features / chrs) == 0:
chr += 1
start = orig_start
start = start + (random.randint(0,jump))
end = start + (random.randint(1,size))
thick_start = start + (random.randint(-size*0.25,size*0.25))
thick_end = end + (random.randint(-size*0.25,size*0.25))
name = name_gen.next() + name_gen.next()
strand = random.random() < 0.5 and '+' or '-'
score = random.random()
line = ['chr' + str(chr), str(start), str(end), name, score, strand, str(thick_start), str(thick_end)]
yield ('\t'.join(line) + '\n')
开发者ID:bow,项目名称:track,代码行数:18,代码来源:random_bed_generator.py
示例12: parse
def parse(self):
# Initialize #
chromosomes = [chrsuffix + str(x) for x in range(10)]
name_generator = tempfile._RandomNameSequence()
name_generator.rng.seed(0)
# New track #
self.handler.newTrack("Random track generator")
self.handler.defineFields(["start", "end", "name", "score", "strand"])
self.handler.defineChrmeta(dict([(ch, dict([("length", sys.maxint)])) for ch in chromosomes]))
# Lots of features #
for chrom in chromosomes:
start = 0
for feat in range(int(feature_factor + 4 * feature_factor * random.random())):
start = start + (random.randint(0, 100))
end = start + (random.randint(1, 100))
name = name_generator.next()
score = random.gammavariate(1, 0.1) * 1000
strand = map(lambda x: x == 1 and 1 or -1, [random.randint(0, 1)])[0]
self.handler.newFeature(chrom, (start, end, name, score, strand))
开发者ID:xapple,项目名称:track,代码行数:19,代码来源:random_sql_generator.py
示例13: test_push_invalidates_cache_hg
def test_push_invalidates_cache_hg(self, webserver):
key = CacheInvalidation.query().filter(CacheInvalidation.cache_key
==HG_REPO).scalar()
if not key:
key = CacheInvalidation(HG_REPO, HG_REPO)
Session().add(key)
key.cache_active = True
Session().commit()
DEST = _get_tmp_dir()
clone_url = webserver.repo_url(HG_REPO)
stdout, stderr = Command(TESTS_TMP_PATH).execute('hg clone', clone_url, DEST)
fork_name = '%s_fork%s' % (HG_REPO, _RandomNameSequence().next())
fixture.create_fork(HG_REPO, fork_name)
clone_url = webserver.repo_url(fork_name)
stdout, stderr = _add_files_and_push(webserver, 'hg', DEST, files_no=1, clone_url=clone_url)
key = CacheInvalidation.query().filter(CacheInvalidation.cache_key
==fork_name).all()
assert key == []
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:22,代码来源:test_vcs_operations.py
示例14: setUp
def setUp(self):
"""Initialize arithmetic coding unit test.
This method is called when an EncodeDirTest object is run. It
gets the contents of the current directory, creates the names
used for temporary files containing encoded and decoded data,
and it creates an instance of an ArithmeticCode object.
Arguments:
None.
Return Value(s):
None.
Side Effects:
Instance variables are initialized.
Exceptions Raised:
None.
"""
self.dir = os.listdir('.')
# generate unique tmp file names by cheating
makesuffix = tempfile._RandomNameSequence()
self.encoded = tempfile.gettempprefix() + makesuffix.next()
self.decoded = tempfile.gettempprefix() + makesuffix.next()
while self.encoded in self.dir:
self.encoded = tempfile.gettempprefix() + makesuffix.next()
while self.decoded in self.dir:
self.decoded = tempfile.gettempprefix() + makesuffix.next()
self.ar = ArithmeticCode()
开发者ID:ResilientScience,项目名称:rsi-arcode,代码行数:36,代码来源:arcode.py
示例15: test_clone_with_credentials
def test_clone_with_credentials(no_errors=False, repo=HG_REPO):
cwd = path = jn(TESTS_TMP_PATH, repo)
try:
shutil.rmtree(path, ignore_errors=True)
os.makedirs(path)
#print 'made dirs %s' % jn(path)
except OSError:
raise
clone_url = 'http://%(user)s:%(pass)[email protected]%(host)s/%(cloned_repo)s %(dest)s' % \
{'user':USER,
'pass':PASS,
'host':HOST,
'cloned_repo':repo,
'dest':path + _RandomNameSequence().next()}
stdout, stderr = Command(cwd).execute('hg clone', clone_url)
if no_errors is False:
assert """adding file changes""" in stdout, 'no messages about cloning'
assert """abort""" not in stderr , 'got error from clone'
开发者ID:q210,项目名称:rhodecode,代码行数:24,代码来源:test_concurency.py
示例16: test_push_invalidates_cache_git
def test_push_invalidates_cache_git(self, webserver):
key = CacheInvalidation.query().filter(CacheInvalidation.cache_key
==GIT_REPO).scalar()
if not key:
key = CacheInvalidation(GIT_REPO, GIT_REPO)
Session().add(key)
key.cache_active = True
Session().commit()
DEST = _get_tmp_dir()
clone_url = webserver.repo_url(GIT_REPO)
stdout, stderr = Command(TESTS_TMP_PATH).execute('git clone', clone_url, DEST)
# commit some stuff into this repo
fork_name = '%s_fork%s' % (GIT_REPO, _RandomNameSequence().next())
fixture.create_fork(GIT_REPO, fork_name)
clone_url = webserver.repo_url(fork_name)
stdout, stderr = _add_files_and_push(webserver, 'git', DEST, files_no=1, clone_url=clone_url)
_check_proper_git_push(stdout, stderr)
key = CacheInvalidation.query().filter(CacheInvalidation.cache_key
==fork_name).all()
assert key == []
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:24,代码来源:test_vcs_operations.py
示例17: import
# -*- coding: utf-8 -*-
"""Helper methods for libtmux and downstream libtmux libraries."""
from __future__ import (absolute_import, division, print_function,
unicode_literals, with_statement)
import contextlib
import logging
import os
import tempfile
logger = logging.getLogger(__name__)
TEST_SESSION_PREFIX = 'libtmux_'
namer = tempfile._RandomNameSequence()
current_dir = os.path.abspath(os.path.dirname(__file__))
example_dir = os.path.abspath(os.path.join(current_dir, '..', 'examples'))
fixtures_dir = os.path.realpath(os.path.join(current_dir, 'fixtures'))
def get_test_session_name(server, prefix=TEST_SESSION_PREFIX):
while True:
session_name = prefix + next(namer)
if not server.has_session(session_name):
break
return session_name
def get_test_window_name(session, prefix=TEST_SESSION_PREFIX):
while True:
开发者ID:dankrause,项目名称:libtmux,代码行数:31,代码来源:test.py
示例18: generate_api_key
def generate_api_key(username, salt=None):
if salt is None:
salt = _RandomNameSequence().next()
return hashlib.sha1(username + salt).hexdigest()
开发者ID:lmamsen,项目名称:rhodecode,代码行数:5,代码来源:auth.py
示例19: make_track_name_random
def make_track_name_random(path):
name_gen = tempfile._RandomNameSequence()
return ' '.join([name_gen.next() for x in range(10)]) + ' ' + path.split('/')[-1]
开发者ID:hjanime,项目名称:gMiner,代码行数:3,代码来源:graphs.py
示例20: create_test_user
assert """Cloning into""" in stdout, 'no messages about cloning'
if __name__ == '__main__':
try:
create_test_user(force=False)
seq = None
import time
try:
METHOD = sys.argv[3]
except Exception:
pass
try:
backend = sys.argv[4]
except Exception:
backend = 'hg'
if METHOD == 'pull':
seq = _RandomNameSequence().next()
test_clone_with_credentials(repo=sys.argv[1], method='clone',
seq=seq, backend=backend)
s = time.time()
for i in range(1, int(sys.argv[2]) + 1):
print 'take', i
test_clone_with_credentials(repo=sys.argv[1], method=METHOD,
seq=seq, backend=backend)
print 'time taken %.3f' % (time.time() - s)
except Exception, e:
sys.exit('stop on %s' % e)
开发者ID:adamscieszko,项目名称:rhodecode,代码行数:30,代码来源:test_concurency.py
注:本文中的tempfile._RandomNameSequence函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论