本文整理汇总了Python中unipath.Path方法的典型用法代码示例。如果您正苦于以下问题:Python unipath.Path方法的具体用法?Python unipath.Path怎么用?Python unipath.Path使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unipath
的用法示例。
在下文中一共展示了unipath.Path方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_by_name
# 需要导入模块: import unipath [as 别名]
# 或者: from unipath import Path [as 别名]
def get_by_name(cls, name, path, git):
# get user's keys
key_path = Path(path, 'keydir')
keys = [key for key in key_path.walk() if
key.endswith('%s.pub' % name)]
# get user's repos
repos = []
repos_path = Path(path, 'conf/')
for repo in repos_path.walk():
if repo.isdir():
continue
with open(str(repo)) as f:
if name in f.read():
repos.append(repo)
if repos or keys:
return cls(path, git, name, **{'repos': repos, 'keys': keys})
return None
示例2: remove
# 需要导入模块: import unipath [as 别名]
# 或者: from unipath import Path [as 别名]
def remove(self, key):
if not isinstance(key, bytes):
key = key.encode('utf-8')
directory = Path(self.user.path, 'keydir', self.user.name,
hashlib.md5(key.strip().split()[1]).hexdigest())
key_file = Path(directory, "%s.pub" % self.user.name)
if not key_file.exists():
raise ValueError("Invalid key")
key_file.remove()
key_file.parent.rmdir()
self.user.git.commit(['keydir'],
'Removed key for user %s' % self.user.name)
示例3: get_data_home
# 需要导入模块: import unipath [as 别名]
# 或者: from unipath import Path [as 别名]
def get_data_home(data_home=None):
"""
Return the path of the revrand data dir.
This folder is used by some large dataset loaders to avoid
downloading the data several times.
By default the data dir is set to a folder named 'revrand_data'
in the user home folder.
Alternatively, it can be set by the 'REVRAND_DATA' environment
variable or programmatically by giving an explicit folder path. The
'~' symbol is expanded to the user home folder.
If the folder does not already exist, it is automatically created.
"""
data_home_default = Path(__file__).ancestor(3).child('demos',
'_revrand_data')
if data_home is None:
data_home = os.environ.get('REVRAND_DATA', data_home_default)
if not os.path.exists(data_home):
os.makedirs(data_home)
return data_home
示例4: upgrade
# 需要导入模块: import unipath [as 别名]
# 或者: from unipath import Path [as 别名]
def upgrade():
file_name = Path('migrations', 'csv', 'whisky.csv')
lines = list(reader(open(file_name, 'r')))
headers = lines.pop(0)
headers.append('slug')
for line in lines:
whisky = Whisky(distillery=line[0])
line.append(whisky.get_slug())
data = [dict(zip(headers, line)) for line in lines]
op.bulk_insert(Whisky.__table__, data)
示例5: upgrade
# 需要导入模块: import unipath [as 别名]
# 或者: from unipath import Path [as 别名]
def upgrade():
# main vars
total_views = dict()
file_handler = Path('migrations',
'csv',
'20140101-20141218_google_analytics.csv')
# load csv data
for path, views in reader(open(file_handler, 'r')):
# get whisky id from database
if '/w/' in path:
whisky_id = int(path.replace('/w/', ''))
whisky = Whisky.query.get(whisky_id)
else:
whisky_slug = path.replace('/', '')
new_whisky = Whisky(distillery=whisky_slug)
new_slug = new_whisky.get_slug()
whisky = Whisky.query.filter(Whisky.slug == new_slug).first()
# feed temporary dictionary
if whisky is not None:
total_views[whisky.id] = total_views.get(whisky.id, 0) + int(views)
# update db
for whisky_id in total_views.keys():
new_whisky = Whisky.query.get(whisky_id)
new_whisky.views = total_views[whisky_id]
db.session.add(new_whisky)
# commit
db.session.commit()
示例6: cache_path
# 需要导入模块: import unipath [as 别名]
# 或者: from unipath import Path [as 别名]
def cache_path():
"""
Returns the directory where cached charts are saved.
:return: (unipath.Path) path of the directory where cache files are
stored
"""
path = app.config["BASEDIR"].child("whiskyton", "static", "charts")
if not path.exists():
path.mkdir()
return path.absolute()
示例7: cache_name
# 需要导入模块: import unipath [as 别名]
# 或者: from unipath import Path [as 别名]
def cache_name(self, full_path=False):
"""
Returns the name of a cache file for a given chart.
:param full_path: (boolean) return the file name only if True, or the
full path with file name if false
:return: (string or unipath.Path) the file name of the cache for the
chart comparing these both whiskies
"""
reference_string = "".join(self.reference)
comparison_string = "".join(self.comparison)
filename = "%sx%s.svg" % (reference_string, comparison_string)
if full_path:
return Path(self.cache_path(), filename).absolute()
else:
return filename
示例8: cache
# 需要导入模块: import unipath [as 别名]
# 或者: from unipath import Path [as 别名]
def cache(self):
"""
This method saves a SVG chart in the cache directory.
:return: (unipath.Path) the path of the cache file
"""
svg_compressed = self.create()
file_path = self.cache_name(True)
if file_path.exists():
file_path.remove()
file_path.write_file(svg_compressed)
return file_path
示例9: all
# 需要导入模块: import unipath [as 别名]
# 或者: from unipath import Path [as 别名]
def all(self):
users = []
key_dir = Path(self.path, 'keydir')
for obj in key_dir.walk():
if obj.isdir():
continue
files = re.compile(r'(\w+.pub)').findall(str(obj))
if files:
users += files
return [User.get_by_name(user[:-4], self.path, self.git)
for user in set(users)]
示例10: __init__
# 需要导入模块: import unipath [as 别名]
# 或者: from unipath import Path [as 别名]
def __init__(self, admin_repository):
self.path = Path(admin_repository)
self.git = Git(admin_repository)
if not self.path.isdir():
raise ValueError('Admin repository path should point to directory')
示例11: create
# 需要导入模块: import unipath [as 别名]
# 或者: from unipath import Path [as 别名]
def create(self, entity):
repo_file = Path(self.path, 'conf/repos/%s.conf' % entity)
if repo_file.exists():
raise ValueError('Repository %s already exists' % entity)
# If there are missing parent paths in the repo path, create them so we don't get IOErrors
# In the case of a repo having names with slashes (e.g. "username/reponame")
elif repo_file.parent != Path(""):
repo_file.parent.mkdir(parents=True)
repo_file.write_file("repo %s\n" % entity)
self.git.commit([str(repo_file)], 'Created repo %s' % entity)
return Repository(entity, self.path, self.git)
示例12: __init__
# 需要导入模块: import unipath [as 别名]
# 或者: from unipath import Path [as 别名]
def __init__(self, repository):
self.repository_model = repository
self.repo = Repo(Path(repository.path,
"conf/repos/%s.conf" % repository.name))
示例13: __init__
# 需要导入模块: import unipath [as 别名]
# 或者: from unipath import Path [as 别名]
def __init__(self, name, path, git):
self.name = name
self.path = path
self.git = git
self.repo = Repo(Path(path,
"conf/repos/%s.conf" % name))
self.users = ListUsers(self)
示例14: get_by_name
# 需要导入模块: import unipath [as 别名]
# 或者: from unipath import Path [as 别名]
def get_by_name(cls, lookup_repo, path, git):
for obj in Path(path, 'conf').walk():
if obj.isdir():
continue
with open(str(obj)) as f:
try:
first_line = f.read().split('\n')[0]
except IndexError:
return None
if "repo %s" % lookup_repo == first_line.strip():
return cls(lookup_repo, path, git)
return None