本文整理汇总了Python中pyasm.biz.Project.get_by_code方法的典型用法代码示例。如果您正苦于以下问题:Python Project.get_by_code方法的具体用法?Python Project.get_by_code怎么用?Python Project.get_by_code使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyasm.biz.Project
的用法示例。
在下文中一共展示了Project.get_by_code方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from pyasm.biz import Project [as 别名]
# 或者: from pyasm.biz.Project import get_by_code [as 别名]
def execute(my):
database = "sthpw"
sql = DbContainer.get(database)
value_array = sql.do_query("select code, cc from (select code, count(code) as cc from file group by code order by cc desc) as X where cc > 1;")
#value_array = sql.do_query("select code, cc from (select code, count(code) as cc from file group by code order by cc desc) as X;")
print "found [%s] pairs" % len(value_array)
for count, value_list in enumerate(value_array):
if count >= BATCH:
break
# get the file object
file_code = value_list[0]
search = Search("sthpw/file")
search.add_filter("code", file_code)
files = search.get_sobjects()
#if len(files) == 1:
# continue
for file in files:
project_code = file.get_value("project_code")
if not project_code:
print "WARNING: file [%s] has no project_code" % file_code
continue
project = Project.get_by_code(project_code)
initials = project.get_initials()
id = file.get_id()
new_file_code = "%s%s" % (id, initials)
if file_code == new_file_code:
continue
print "-"*20
print "switching: ", file_code, "to", new_file_code
snapshot_code = file.get_value("snapshot_code")
snapshot = Snapshot.get_by_code(snapshot_code)
assert snapshot
snapshot_xml = snapshot.get_xml_value("snapshot")
print snapshot_xml.to_string()
node = snapshot_xml.get_node("snapshot/file[@file_code='%s']" % file_code)
Xml.set_attribute(node, "file_code", new_file_code)
print snapshot_xml.to_string()
assert node
# set the file_code
file.set_value("code", new_file_code)
file.commit()
# set the snapshot
snapshot.set_value("snapshot", snapshot_xml.to_string() )
snapshot.commit()
示例2: execute
# 需要导入模块: from pyasm.biz import Project [as 别名]
# 或者: from pyasm.biz.Project import get_by_code [as 别名]
def execute(my):
my.base_dir = my.kwargs.get("base_dir")
if not my.base_dir:
my.base_dir = Environment.get_template_dir()
my.project_code = my.kwargs.get("project_code")
if not my.project_code:
my.project_code = Project.get_project_code()
assert my.project_code
# project code can be called anything, and we want to have a _template suffix for the template code
#my.plugin_code = "%s_template" % my.project_code
#my.template_project_code = re.sub( '_template$', '', my.plugin_code)
my.template_project_code = my.project_code
my.project = Project.get_by_code(my.project_code)
if not my.project:
raise TacticException('This project [%s] does not exist'%my.project_code)
my.project_type = my.project.get_value("type")
if not my.project_type:
my.project_type = my.project_code
Project.set_project(my.project_code)
my.export_template()
示例3: execute
# 需要导入模块: from pyasm.biz import Project [as 别名]
# 或者: from pyasm.biz.Project import get_by_code [as 别名]
def execute(self):
self.base_dir = self.kwargs.get("base_dir")
if not self.base_dir:
self.base_dir = Environment.get_template_dir()
self.project_code = self.kwargs.get("project_code")
if not self.project_code:
self.project_code = Project.get_project_code()
assert self.project_code
# project code can be called anything, and we want to have a _template suffix for the template code
#self.plugin_code = "%s_template" % self.project_code
#self.template_project_code = re.sub( '_template$', '', self.plugin_code)
self.template_project_code = self.project_code
self.project = Project.get_by_code(self.project_code)
if not self.project:
raise TacticException('This project [%s] does not exist'%self.project_code)
self.project_type = self.project.get_value("type")
if not self.project_type:
self.project_type = self.project_code
Project.set_project(self.project_code)
self.export_template()
示例4: get_parent_schema
# 需要导入模块: from pyasm.biz import Project [as 别名]
# 或者: from pyasm.biz.Project import get_by_code [as 别名]
def get_parent_schema(self):
parent_schema_code = self.xml.get_value("schema/@parent")
if parent_schema_code:
if parent_schema_code == "__NONE__":
return None
parent_schema = Schema.get_by_code(parent_schema_code)
return parent_schema
else:
# Note: assume schema code == project_code
schema_code = self.get_value("code")
from pyasm.biz import Project
project = Project.get_by_code(schema_code)
if not project:
return None
project_code = project.get_code()
project_type = project.get_base_type()
if not project_type:
return None
parent_schema = Schema.get_predefined_schema(project_type)
return parent_schema
示例5: _test_project
# 需要导入模块: from pyasm.biz import Project [as 别名]
# 或者: from pyasm.biz.Project import get_by_code [as 别名]
def _test_project(self):
# create a fake project
#project = SearchType.create("sthpw/project")
#project.set_value("code", "db_test")
#project.set_value("db_resource", "sqlite")
#project.commit()
from pyasm.biz import Project
project = Project.get_by_code("db_test")
db_resource = project.get_db_resource()
# so if we have search type, this will use the database resource
# that is designated by
search_type = "config/widget_config?project=db_test"
search = Search(search_type)
sobjects = search.get_sobject()
# this is really tricky to do because a *lot* of functions assume
# a local database by passing just a database string through.
# things like table_exists() or any of these. Ultimately, they
# have to do a DbContainer.get(database) to do any operations.
# But on the way, db_resource turns into database_name. To really
# fix, we have to enforce db_resource at DbContainer
DbContainer.get(database)
示例6: create
# 需要导入模块: from pyasm.biz import Project [as 别名]
# 或者: from pyasm.biz.Project import get_by_code [as 别名]
def create(self):
project = Project.get_by_code(self.project_code)
if project:
self.delete()
print "Setting up a basic Sample3d project"
# create the project
create_cmd = CreateProjectCmd(project_code=self.project_code, project_title="Sample 3D") #, project_type="unittest")
create_cmd.execute()
# install the unittest plugin
installer = PluginInstaller(relative_dir="TACTIC/internal/sample3d", verbose=False)
installer.execute()
# add 30 shots
for x in xrange(30):
shot = SearchType.create("prod/shot")
shot.set_value('name','shot%s'%x)
shot.set_value('sequence_code','SEQ_01')
shot.commit(triggers=False)
if not Search.eval("@SOBJECT(prod/sequence['code','SEQ_01'])"):
seq = SearchType.create("prod/sequence")
seq.set_value('code','SEQ_01')
seq.commit(triggers=False)
示例7: _test_add_drop_column
# 需要导入模块: from pyasm.biz import Project [as 别名]
# 或者: from pyasm.biz.Project import get_by_code [as 别名]
def _test_add_drop_column(my):
#Project.set_project('unittest')
from pyasm.command import ColumnAddCmd, ColumnDropCmd, Command
cmd = ColumnAddCmd('unittest/country','special_place','varchar(256)')
Command.execute_cmd(cmd)
search_type = 'unittest/country'
# clear cache
SearchType.clear_column_cache(search_type)
DatabaseImpl.clear_table_cache()
exists = SearchType.column_exists(search_type, 'special_place')
my.assertEquals(exists, True)
# now drop the column
cmd = ColumnDropCmd(search_type,'special_place')
Command.execute_cmd(cmd)
# clear cache
SearchType.clear_column_cache(search_type)
cache_dict = Container.get("DatabaseImpl:column_info")
# assume database is the same as sthpw
database_type = Project.get_by_code("unittest").get_database_type()
db_resource = DbResource.get_default('unittest')
table_info = cache_dict.get("%s:%s" % (db_resource, "country"))
my.assertEquals(table_info == None, True)
key = "%s:%s" % (db_resource, "country")
cache_dict[key] = None
exists = SearchType.column_exists(search_type, 'special_place')
my.assertEquals(exists, False)
示例8: _test_get_connect
# 需要导入模块: from pyasm.biz import Project [as 别名]
# 或者: from pyasm.biz.Project import get_by_code [as 别名]
def _test_get_connect(my):
database= 'unittest'
project = Project.get_by_code(database)
db_resource= project.get_project_db_resource()
sql1 = DbContainer.get(db_resource)
sql2 = DbContainer.get(db_resource)
my.assertEquals(sql1, sql2)
示例9: _test_set_value
# 需要导入模块: from pyasm.biz import Project [as 别名]
# 或者: from pyasm.biz.Project import get_by_code [as 别名]
def _test_set_value(my):
''' test with different Database Impl'''
update = Update()
update.set_database('sthpw')
update.set_table('task')
update.set_value('timestamp','2012-12-12')
my.assertEquals( update.get_statement(), """UPDATE {0}"task" SET "timestamp" = '2012-12-12'""".format(my.sthpw_prefix))
update = Update()
update.set_database('sthpw')
update.set_table('task')
# Changing database to SQLServer
sql_impl = DatabaseImpl.get('SQLServer')
update.impl = sql_impl
update.set_value('timestamp','2012-12-12')
my.assertEquals( update.get_statement(), """UPDATE {0}"task" SET "timestamp" = convert(datetime2, \'2012-12-12\', 0)""".format(my.sthpw_prefix))
update.set_value('timestamp','NOW')
my.assertEquals( update.get_statement(), """UPDATE {0}"task" SET "timestamp" = getdate()""".format(my.sthpw_prefix))
from pyasm.biz import Project
database_type = Project.get_by_code("unittest").get_database_type()
if database_type == "MySQL":
print
print "WARNING: !!!!!!!"
print "test for NOW is disabled"
print "WARNING: !!!!!!!"
print
return
time_dict = {'SQLServer': "convert(datetime2, '2012-12-25', 0)",
'Sqlite':"'2012-12-25'",
'PostgreSQL':"'2012-12-25'",
'MySQL': "'2012-12-25'"}
#'Oracle':"TO_DATE('2012-12-25','YYYY-MM-DD'"}
#TODO: test with cx_Oracle installed
for db_type in ['Sqlite','SQLServer','MySQL','PostgreSQL']:
sql_impl = DatabaseImpl.get(db_type)
update = Update()
update.set_database('sthpw')
update.set_table('task')
update.impl = sql_impl
update.set_value('timestamp','2012-12-25')
update.set_value('description','')
if db_type == 'SQLServer':
my.assertEquals( update.get_statement(), """UPDATE %s"task" SET "timestamp" = %s, "description" = N\'\'"""% (my.sthpw_prefix, time_dict.get(db_type)))
else:
my.assertEquals( update.get_statement(), """UPDATE %s"task" SET "timestamp" = %s, "description" = \'\'"""% (my.sthpw_prefix, time_dict.get(db_type)))
update.set_value('description',None)
my.assertEquals( update.get_statement(), """UPDATE %s"task" SET "timestamp" = %s, "description" = NULL"""% (my.sthpw_prefix, time_dict.get(db_type)))
示例10: _create_table
# 需要导入模块: from pyasm.biz import Project [as 别名]
# 或者: from pyasm.biz.Project import get_by_code [as 别名]
def _create_table(my):
from pyasm.search import CreateTable
project = Project.get_by_code("mongodb")
#sql = project.get_sql()
db_resource = project.get_project_db_resource()
sql = db_resource.get_sql()
create = CreateTable()
create.set_table("whatever")
create.commit(sql)
示例11: handle_not_logged_in
# 需要导入模块: from pyasm.biz import Project [as 别名]
# 或者: from pyasm.biz.Project import get_by_code [as 别名]
def handle_not_logged_in(my, allow_change_admin=True):
site_obj = Site.get()
site_obj.set_site("default")
DbResource.clear_cache()
from pyasm.widget import WebLoginWdg, BottomWdg
from tactic.ui.app import TitleTopWdg
from pyasm.biz import Project
from tactic.ui.panel import HashPanelWdg
web = WebContainer.get_web()
widget = Widget()
top = TitleTopWdg()
widget.add(top)
body = top.get_body()
body.add_gradient("background", "background", 5, -20)
body.add_color("color", "color")
reset_request = web.get_form_value('reset_request') =='true'
if reset_request:
from tactic.ui.widget import ResetPasswordWdg
top.add(ResetPasswordWdg())
else:
reset_msg = web.get_form_value('reset_msg')
if reset_msg:
web.set_form_value(WebLoginWdg.LOGIN_MSG, reset_msg)
sudo = Sudo()
try:
# get the project from the url because we are still
# in the admin project at this stage
current_project = web.get_context_name()
try:
if current_project != "default":
project = Project.get_by_code(current_project)
assert project
except Exception, e:
web_wdg = None
else:
示例12: _test_transaction
# 需要导入模块: from pyasm.biz import Project [as 别名]
# 或者: from pyasm.biz.Project import get_by_code [as 别名]
def _test_transaction(my):
# initiate a global transaction
database = "unittest"
count_sql = 'select count(*) from "person"'
transaction = Transaction.get(create=True)
# adding these 2 lines
project = Project.get_by_code(database)
db_resource= project.get_project_db_resource()
db = DbContainer.get(db_resource)
count0 = db.get_value(count_sql)
person = Person.create("Mr", "Dumpling", "Dumpling Land", "Burnt")
# check to see that one was added
count1 = db.get_value(count_sql)
my.assertEquals( count1, count0+1)
# FIXME: cant' delete for some reason
#person.delete()
# commit the first time
transaction.commit()
# check to see that one was added
count1 = db.get_value(count_sql)
my.assertEquals( count1, count0+1)
#transaction.rollback()
#person.delete()
last = TransactionLog.get_last()
last.undo()
# create another login
transaction = Transaction.get(create=True)
count0 = db.get_value(count_sql)
person = Person.create("Mr", "Dumpling", "Dumpling Land", "Burnt")
db = DbContainer.get(db_resource)
count2 = db.get_value(count_sql)
my.assertEquals( count2, count0+1)
transaction.rollback()
# check to see that one was removed/rolled back
count3 = db.get_value(count_sql)
my.assertEquals( count3, count0)
示例13: create
# 需要导入模块: from pyasm.biz import Project [as 别名]
# 或者: from pyasm.biz.Project import get_by_code [as 别名]
def create(my):
project = Project.get_by_code(my.project_code)
if project:
my.delete()
print "Setting up a basic Sample3d project"
# create the project
create_cmd = CreateProjectCmd(project_code=my.project_code, project_title="Sample 3D") #, project_type="unittest")
create_cmd.execute()
# install the unittest plugin
installer = PluginInstaller(relative_dir="TACTIC/internal/sample3d", verbose=False)
installer.execute()
示例14: get_display
# 需要导入模块: from pyasm.biz import Project [as 别名]
# 或者: from pyasm.biz.Project import get_by_code [as 别名]
def get_display(my):
web = WebContainer.get_web()
widget = Widget()
html = HtmlElement("html")
html.add_attr("xmlns:v", 'urn:schemas-microsoft-com:vml')
is_xhtml = False
if is_xhtml:
web.set_content_type("application/xhtml+xml")
widget.add('''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
''')
html.add_attr("xmlns", "http://www.w3.org/1999/xhtml")
#html.add_attr("xmlns:svg", "http://www.w3.org/2000/svg")
# add the copyright
widget.add( my.get_copyright_wdg() )
widget.add(html)
# create the header
head = HtmlElement("head")
html.add(head)
head.add('<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>\n')
head.add('<meta http-equiv="X-UA-Compatible" content="IE=edge"/>\n')
# Add the tactic favicon
head.add('<link rel="shortcut icon" href="/context/favicon.ico" type="image/x-icon"/>')
# add the css styling
head.add(my.get_css_wdg())
# add the title in the header
try:
project = Project.get()
except Exception, e:
print "ERROR: ", e
# if the project doesn't exist, then use the admin project
project = Project.get_by_code("admin")
示例15: get_display
# 需要导入模块: from pyasm.biz import Project [as 别名]
# 或者: from pyasm.biz.Project import get_by_code [as 别名]
def get_display(self):
widget = DivWdg()
widget.add_style("text-align: center")
search_type = self.get_current_sobject()
project_code = search_type.get_value("database")
if project_code == "{project}":
# HACK: assumes database == project_code. Can't seem to get
# around the {project} variable ... need to look at this
# sometime
project = Project.get()
else:
project = Project.get_by_code(project_code)
if not project:
widget.add( IconWdg("Exists", IconWdg.ERROR) )
widget.add( "Project does not exist")
return widget
table = search_type.get_table()
if not table:
return ""
try:
db_resource = project.get_project_db_resource()
sql = DbContainer.get(db_resource)
tables = sql.get_tables()
has_table = table in tables
except DatabaseException:
has_table = False
if has_table:
widget.add( IconWdg("Exists", IconWdg.DOT_GREEN) )
else:
widget.add( IconWdg("Does not Exist", IconWdg.DOT_RED) )
return widget