本文整理汇总了Python中tempfile._RandomNameSequence函数的典型用法代码示例。如果您正苦于以下问题:Python _RandomNameSequence函数的具体用法?Python _RandomNameSequence怎么用?Python _RandomNameSequence使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_RandomNameSequence函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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]
示例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'
示例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)
示例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
示例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
示例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()
示例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
示例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
示例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
示例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()
示例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')
示例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))
示例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 == []
示例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()
示例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'