本文整理汇总了Python中attrdict.AttrDict.package_name方法的典型用法代码示例。如果您正苦于以下问题:Python AttrDict.package_name方法的具体用法?Python AttrDict.package_name怎么用?Python AttrDict.package_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类attrdict.AttrDict
的用法示例。
在下文中一共展示了AttrDict.package_name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_project
# 需要导入模块: from attrdict import AttrDict [as 别名]
# 或者: from attrdict.AttrDict import package_name [as 别名]
def create_project(provider_name):
r = AttrDict()
r.provider_name = provider_name
r.repository_name = "cb-%s-connector" % provider_name
r.rpm_name = "python-%s" % r.repository_name
r.package_name = "cbopensource.connectors.%s" % r.provider_name
# by default there is one script
r.scripts = [r.repository_name]
# create a random port number for the listener
r.port_number = random.randint(2000, 8000)
template_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "templates")
# create an empty git repository
output = None
if os.path.exists(r.repository_name):
raise ProjectCreationError(message="Directory %s already exists" % r.repository_name)
try:
os.mkdir(r.repository_name, 0755)
except OSError as e:
raise ProjectCreationError(message="Could not create directory %s" % r.repository_name, extended_output=e)
os.chdir(r.repository_name)
try:
output = subprocess.check_output("git init", shell=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
raise ProjectCreationError(message="Could not run git init on new repository", extended_output=output)
# now cycle through the templates
for root, _, files in os.walk(template_directory):
reldir = os.path.relpath(root, template_directory)
reldir = Template(reldir).render(**r)
if not os.path.isdir(reldir):
os.makedirs(reldir, 0755)
for fn in files:
destination_filename = fn.replace(".template", "")
destination_filename = Template(destination_filename).render(**r)
destination_file = os.path.join(reldir, destination_filename)
source_template = os.path.join(root, fn)
print "creating %s" % destination_file
if fn.endswith(".template"):
try:
t = Template(open(source_template, "rb").read())
open(destination_file, "wb").write(t.render(**r))
shutil.copymode(source_template, destination_file)
except IOError as e:
raise ProjectCreationError(
message="Could not create file %s from template %s" % (destination_file, source_template),
extended_output=e.message,
)
else:
try:
shutil.copyfile(source_template, destination_file)
except IOError as e:
raise ProjectCreationError(
message="Could not copy file %s from %s" % (destination_file, source_template),
extended_output=e.message,
)
try:
output = subprocess.check_output("git add .", shell=True, stderr=subprocess.STDOUT)
output = subprocess.check_output("git commit -m 'Initial commit'", shell=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
raise ProjectCreationError(message="Could not run git commit on repository", extended_output=output)
print "\nNew connector scaffolding created in %s." % r.repository_name
print "Create a new repository on github.com and add the repository:"
print " git add remote origin [email protected]:carbonblack/%s.git" % r.repository_name
print " git push origin"