示例#1
0
class Installer:
	def __init__(self, root_login, root_password):
	
		self.root_password = root_password
		from webnotes.model.db_schema import DbManager
		
		self.conn = webnotes.db.Database(user=root_login, password=root_password)			
		
		self.dbman = DbManager(self.conn)
		self.mysql_path = hasattr(defs, 'mysql_path') and webnotes.defs.mysql_path or ''

	#
	# run framework related cleanups
	#
	def framework_cleanups(self, target):
		self.conn.use(target)
		self.dbman.drop_table('__DocTypeCache')
		self.conn.sql("create table `__DocTypeCache` (name VARCHAR(120), modified DATETIME, content TEXT, server_code_compiled TEXT)")

		# set the basic passwords
		self.conn.sql("update tabProfile set password = password('admin') where name='Administrator'")
		self.conn.sql("update tabDocType set server_code_compiled = NULL")

		# temp
		self.conn.sql("alter table tabSessions change sessiondata sessiondata longtext")
		try: 	
			self.conn.sql("alter table tabSessions add index sid(sid)")
		except Exception, e:
			if e.args[0]==1061:
				pass
			else:
				raise e	
示例#2
0
    def __init__(self, root_login, root_password=None):
        if root_login:
            if not root_password:
                root_password = getattr(conf, "root_password", None)
            if not root_password:
                root_password = getpass.getpass("MySQL root password: ")

        self.root_password = root_password

        self.conn = webnotes.db.Database(user=root_login,
                                         password=root_password)
        webnotes.conn = self.conn
        webnotes.session = webnotes._dict({'user': '******'})
        self.dbman = DbManager(self.conn)
示例#3
0
    def __init__(self,
                 root_login,
                 root_password=None,
                 db_name=None,
                 site=None,
                 site_config=None):
        make_conf(db_name, site=site, site_config=site_config)
        self.site = site

        self.make_connection(root_login, root_password)

        webnotes.local.conn = self.conn
        webnotes.local.session = webnotes._dict({'user': '******'})

        self.dbman = DbManager(self.conn)
示例#4
0
    def __init__(self, root_login, root_password):

        import webnotes
        import webnotes.db
        import webnotes.defs

        self.root_password = root_password
        from webnotes.model.db_schema import DbManager

        self.conn = webnotes.db.Database(user=root_login,
                                         password=root_password)
        webnotes.conn = self.conn
        webnotes.session = {'user': '******'}
        self.dbman = DbManager(self.conn)
        self.mysql_path = hasattr(
            webnotes.defs, 'mysql_path') and webnotes.defs.mysql_path or ''
示例#5
0
    def __init__(self, root_login, root_password=None):

        import webnotes
        import webnotes.db

        if root_login and not root_password:
            import getpass
            root_password = getpass.getpass("MySQL root password: ")

        self.root_password = root_password
        from webnotes.model.db_schema import DbManager

        self.conn = webnotes.db.Database(user=root_login,
                                         password=root_password)
        webnotes.conn = self.conn
        webnotes.session = {'user': '******'}
        self.dbman = DbManager(self.conn)
示例#6
0
	def __init__(self, root_login, root_password):
	
		self.root_password = root_password
		from webnotes.model.db_schema import DbManager
		
		self.conn = webnotes.db.Database(user=root_login, password=root_password)			
		
		self.dbman = DbManager(self.conn)
		self.mysql_path = hasattr(defs, 'mysql_path') and webnotes.defs.mysql_path or ''
示例#7
0
	def setUp(self):
		self.test_doc = doc.Document('')
		self.f1 = doc.Document('')
		self.f2 = doc.Document('')
		self.f3 = doc.Document('')
		self.f4 = doc.Document('')
		self.p = doc.Document('')
		webnotes.session = testlib.test_webnotes_session
		webnotes.conn = testlib.test_conn
		self.dbman = DbManager(webnotes.conn)
示例#8
0
	def __init__(self, root_login, root_password=None, db_name=None, site=None, site_config=None):
		make_conf(db_name, site=site, site_config=site_config)
		self.site = site
		
		self.make_connection(root_login, root_password)

		webnotes.local.conn = self.conn
		webnotes.local.session = webnotes._dict({'user':'******'})
	
		self.dbman = DbManager(self.conn)
示例#9
0
    def __init__(self, root_login, root_password):

        self.root_password = root_password
        from webnotes.model.db_schema import DbManager

        self.conn = webnotes.db.Database(user=root_login, password=root_password)
        webnotes.conn = self.conn
        webnotes.session = {"user": "******"}
        self.dbman = DbManager(self.conn)
        self.mysql_path = hasattr(defs, "mysql_path") and webnotes.defs.mysql_path or ""
示例#10
0
	def __init__(self, root_login, root_password):

		import webnotes
		import webnotes.db
	
		self.root_password = root_password
		from webnotes.model.db_schema import DbManager
		
		self.conn = webnotes.db.Database(user=root_login, password=root_password)			
		webnotes.conn=self.conn
		webnotes.session= {'user':'******'}
		self.dbman = DbManager(self.conn)
示例#11
0
	def __init__(self, root_login, root_password=None):
		if root_login:
			if not root_password:
				root_password = getattr(conf, "root_password", None)
			if not root_password:
				root_password = getpass.getpass("MySQL root password: ")
			
		self.root_password = root_password
				
		self.conn = webnotes.db.Database(user=root_login, password=root_password)
		webnotes.conn=self.conn
		webnotes.session= webnotes._dict({'user':'******'})
		self.dbman = DbManager(self.conn)
示例#12
0
	def __init__(self, root_login, root_password):

		import webnotes
		import webnotes.db
		import webnotes.defs
	
		self.root_password = root_password
		from webnotes.model.db_schema import DbManager
		
		self.conn = webnotes.db.Database(user=root_login, password=root_password)			
		webnotes.conn=self.conn
		webnotes.session= {'user':'******'}
		self.dbman = DbManager(self.conn)
		self.mysql_path = hasattr(webnotes.defs, 'mysql_path') and webnotes.defs.mysql_path or ''
示例#13
0
	def __init__(self, root_login, root_password=None):

		import webnotes
		import webnotes.db
	
		if not root_password:
			import getpass
			root_password = getpass.getpass("MySQL root password: ")
			
		self.root_password = root_password
		from webnotes.model.db_schema import DbManager
		
		self.conn = webnotes.db.Database(user=root_login, password=root_password)			
		webnotes.conn=self.conn
		webnotes.session= {'user':'******'}
		self.dbman = DbManager(self.conn)
示例#14
0
class Installer:
    def __init__(self, root_login, root_password):

        import webnotes
        import webnotes.db
        import webnotes.defs

        self.root_password = root_password
        from webnotes.model.db_schema import DbManager

        self.conn = webnotes.db.Database(user=root_login,
                                         password=root_password)
        webnotes.conn = self.conn
        webnotes.session = {'user': '******'}
        self.dbman = DbManager(self.conn)
        self.mysql_path = hasattr(
            webnotes.defs, 'mysql_path') and webnotes.defs.mysql_path or ''

    #
    # run framework related cleanups
    #
    def framework_cleanups(self, target):

        import webnotes
        self.dbman.drop_table('__DocTypeCache')
        webnotes.conn.sql(
            "create table `__DocTypeCache` (name VARCHAR(120), modified DATETIME, content TEXT, server_code_compiled TEXT)"
        )

        # set the basic passwords
        webnotes.conn.begin()
        webnotes.conn.sql(
            "update tabProfile set password = password('admin') where name='Administrator'"
        )
        webnotes.conn.commit()

    def import_core_module(self):
        """
			Imports the "Core" module from .txt file and creates
			Creates profile Administrator
		"""
        import webnotes
        from webnotes.modules import Module
        core = Module('core')

        core.reload('doctype', 'doctype')
        core.reload('doctype', 'docfield')
        core.reload('doctype', 'docperm')
        core.sync_all(verbose=1)

    def create_users(self):
        """
			Create Administrator / Guest
		"""
        webnotes.conn.begin()

        from webnotes.model.doc import Document
        p = Document('Profile')
        p.name = p.first_name = 'Administrator'
        p.email = 'admin@localhost'
        p.save(new=1)

        ur = Document('UserRole')
        ur.parent = 'Administrator'
        ur.role = 'Administrator'
        ur.parenttype = 'Profile'
        ur.parentfield = 'userroles'
        p.enabled = 1
        ur.save(1)

        p = Document('Profile')
        p.name = p.first_name = 'Guest'
        p.email = 'guest@localhost'
        p.enabled = 1
        p.save(new=1)

        ur = Document('UserRole')
        ur.parent = 'Guest'
        ur.role = 'Guest'
        ur.parenttype = 'Profile'
        ur.parentfield = 'userroles'
        ur.save(1)

        webnotes.conn.commit()

    def get_db_password(self, db_name):
        """
			Get the db_password by method
		"""
        import webnotes.defs
        if hasattr(webnotes.defs, 'get_db_password'):
            return webnotes.defs.get_db_password(db_name)
        if hasattr(webnotes.defs, 'db_password'):
            return webnotes.defs.db_password
        return ''

    def import_from_db(self,
                       target,
                       source_path='',
                       password='******',
                       verbose=0):
        """
		a very simplified version, just for the time being..will eventually be deprecated once the framework stabilizes.
		"""
        import webnotes.defs

        # delete user (if exists)
        self.dbman.delete_user(target)

        # create user and db
        self.dbman.create_user(target, self.get_db_password(target))
        if verbose: print "Created user %s" % target

        # create a database
        self.dbman.create_database(target)
        if verbose: print "Created database %s" % target

        # grant privileges to user
        self.dbman.grant_all_privileges(target, target)
        if verbose:
            print "Granted privileges to user %s and database %s" % (target,
                                                                     target)

        # flush user privileges
        self.dbman.flush_privileges()

        self.conn.use(target)

        # import in target
        if verbose: print "Starting database import..."

        # get the path of the sql file to import
        source_given = True
        if not source_path:
            source_given = False
            source_path = os.path.join(
                os.path.sep.join(
                    os.path.abspath(webnotes.__file__).split(
                        os.path.sep)[:-3]), 'data', 'Framework.sql')

        self.dbman.restore_database(target, source_path, self.root_password)
        if verbose: print "Imported from database %s" % source_path

        if not source_given:
            if verbose: print "Importing core module..."
            self.import_core_module()
            self.create_users()

        # framework cleanups
        self.framework_cleanups(target)
        if verbose: print "Ran framework startups on %s" % target

        return target
示例#15
0
class Installer:
    def __init__(self,
                 root_login,
                 root_password=None,
                 db_name=None,
                 site=None,
                 site_config=None):
        make_conf(db_name, site=site, site_config=site_config)
        self.site = site

        self.make_connection(root_login, root_password)

        webnotes.local.conn = self.conn
        webnotes.local.session = webnotes._dict({'user': '******'})

        self.dbman = DbManager(self.conn)

    def make_connection(self, root_login, root_password):
        if root_login:
            if not root_password:
                root_password = webnotes.conf.get("root_password") or None

            if not root_password:
                root_password = getpass.getpass("MySQL root password: "******"Database %s already exists" % (db_name, ))

        # create user and db
        self.dbman.create_user(db_name, webnotes.conf.db_password)

        if verbose: print "Created user %s" % db_name

        # create a database
        self.dbman.create_database(db_name)
        if verbose: print "Created database %s" % db_name

        # grant privileges to user
        self.dbman.grant_all_privileges(db_name, db_name)
        if verbose:
            print "Granted privileges to user %s and database %s" % (db_name,
                                                                     db_name)

        # flush user privileges
        self.dbman.flush_privileges()

        # close root connection
        self.conn.close()

        webnotes.connect(db_name=db_name, site=self.site)
        self.dbman = DbManager(webnotes.conn)

        # import in db_name
        if verbose: print "Starting database import..."

        # get the path of the sql file to import
        if not source_sql:
            source_sql = os.path.join(os.path.dirname(webnotes.__file__), "..",
                                      'conf', 'Framework.sql')

        self.dbman.restore_database(db_name, source_sql, db_name,
                                    webnotes.conf.db_password)
        if verbose: print "Imported from database %s" % source_sql

        self.create_auth_table()

        # fresh app
        if 'Framework.sql' in source_sql:
            if verbose: print "Installing app..."
            self.install_app(verbose=verbose)

        # update admin password
        self.update_admin_password(admin_password)

        # create public folder
        from webnotes.install_lib import setup_public_folder
        setup_public_folder.make(site=self.site)

        if not self.site:
            from webnotes.build import bundle
            bundle(False)

        return db_name

    def install_app(self, verbose=False):
        sync_for("lib", force=True, sync_everything=True, verbose=verbose)
        self.import_core_docs()

        try:
            from startup import install
        except ImportError, e:
            install = None

        if os.path.exists("app"):
            sync_for("app", force=True, sync_everything=True, verbose=verbose)

        if os.path.exists(os.path.join("app", "startup", "install_fixtures")):
            install_fixtures()

        if verbose: print "Completing App Import..."
        install and install.post_import()
        if verbose: print "Updating patches..."
        self.set_all_patches_as_completed()
        self.assign_all_role_to_administrator()
示例#16
0
class Installer:
	def __init__(self, root_login, root_password):

		import webnotes
		import webnotes.db
		import webnotes.defs
	
		self.root_password = root_password
		from webnotes.model.db_schema import DbManager
		
		self.conn = webnotes.db.Database(user=root_login, password=root_password)			
		webnotes.conn=self.conn
		webnotes.session= {'user':'******'}
		self.dbman = DbManager(self.conn)
		self.mysql_path = hasattr(webnotes.defs, 'mysql_path') and webnotes.defs.mysql_path or ''

	#
	# run framework related cleanups
	#
	def framework_cleanups(self, target):

		import webnotes
		self.dbman.drop_table('__DocTypeCache')
		webnotes.conn.sql("create table `__DocTypeCache` (name VARCHAR(120), modified DATETIME, content TEXT, server_code_compiled TEXT)")

		# set the basic passwords
		webnotes.conn.begin()
		webnotes.conn.sql("update tabProfile set password = password('admin') where name='Administrator'")
		webnotes.conn.commit()

	def import_core_module(self):
		"""
			Imports the "Core" module from .txt file and creates
			Creates profile Administrator
		"""
		import webnotes
		from webnotes.modules import Module
		core = Module('core')

		core.reload('doctype','doctype')
		core.reload('doctype','docfield')
		core.reload('doctype','docperm')
		core.sync_all(verbose=1)
		
	def create_users(self):
		"""
			Create Administrator / Guest
		"""
		webnotes.conn.begin()
		
		from webnotes.model.doc import Document
		p = Document('Profile')
		p.name = p.first_name = 'Administrator'
		p.email = 'admin@localhost'
		p.save(new = 1)
		
		ur = Document('UserRole')
		ur.parent = 'Administrator'
		ur.role = 'Administrator'
		ur.parenttype = 'Profile'
		ur.parentfield = 'userroles'
		p.enabled = 1
		ur.save(1)

		p = Document('Profile')
		p.name = p.first_name = 'Guest'
		p.email = 'guest@localhost'
		p.enabled = 1
		p.save(new = 1)
		
		ur = Document('UserRole')
		ur.parent = 'Guest'
		ur.role = 'Guest'
		ur.parenttype = 'Profile'
		ur.parentfield = 'userroles'
		ur.save(1)

		webnotes.conn.commit()

	def get_db_password(self, db_name):
		"""
			Get the db_password by method
		"""
		import webnotes.defs
		if hasattr(webnotes.defs, 'get_db_password'):
			return webnotes.defs.get_db_password(db_name)
		if hasattr(webnotes.defs, 'db_password'):
			return webnotes.defs.db_password
		return ''

	def import_from_db(self, target, source_path='', password = '******', verbose=0):
		"""
		a very simplified version, just for the time being..will eventually be deprecated once the framework stabilizes.
		"""
		import webnotes.defs		
		
		# delete user (if exists)
		self.dbman.delete_user(target)

		# create user and db
		self.dbman.create_user(target,self.get_db_password(target))
		if verbose: print "Created user %s" % target
	
		# create a database
		self.dbman.create_database(target)
		if verbose: print "Created database %s" % target
		
		# grant privileges to user
		self.dbman.grant_all_privileges(target,target)
		if verbose: print "Granted privileges to user %s and database %s" % (target, target)

		# flush user privileges
		self.dbman.flush_privileges()

		self.conn.use(target)
		
		# import in target
		if verbose: print "Starting database import..."

		# get the path of the sql file to import
		source_given = True
		if not source_path:
			source_given = False
			source_path = os.path.join(os.path.sep.join(os.path.abspath(webnotes.__file__).split(os.path.sep)[:-3]), 'data', 'Framework.sql')

		self.dbman.restore_database(target, source_path, self.root_password)
		if verbose: print "Imported from database %s" % source_path

		if not source_given:
			if verbose: print "Importing core module..."
			self.import_core_module()
			self.create_users()

		# framework cleanups
		self.framework_cleanups(target)
		if verbose: print "Ran framework startups on %s" % target
		
		return target		
示例#17
0
def make_scheduler(root_login, root_password, verbose):
	"""
		Make the database where all scheduler events will be stored from multiple datbases
		See webnotes.utils.scheduler for more information
	"""
	conn = webnotes.db.Database(user=root_login, password=root_password)			

	from webnotes.model.db_schema import DbManager

	dbman = DbManager(conn)
	
	# delete user (if exists)
	dbman.delete_user('master_scheduler')

	# create user and db
	dbman.create_user('master_scheduler', getattr(webnotes.defs,'scheduler_password',None))
	if verbose: print "Created user master_scheduler"

	# create a database
	dbman.create_database('master_scheduler')
	if verbose: print "Created database master_scheduler" 

	# grant privileges to user
	dbman.grant_all_privileges('master_scheduler','master_scheduler')

	# flush user privileges
	dbman.flush_privileges()
	
	conn.use('master_scheduler')
	
	# create events table
	conn.sql("""create table Event(
		`db_name` varchar(60),
		`event` varchar(180),
		`interval` int(20),
		`next_execution` timestamp,
		`recurring` int(1),
		primary key (`db_name`, `event`),
		index next_execution(next_execution)
		)""")
	
	conn.sql("""create table EventLog(
		`db_name` varchar(180), 
		`event` varchar(180),
		`executed_on` timestamp,
		`log` text,
		index executed_on(executed_on))
	""")
示例#18
0
	def install(self, db_name, source_sql=None, admin_password = '******', verbose=0,
		force=0):
		
		if force or (db_name not in self.dbman.get_database_list()):
			# delete user (if exists)
			self.dbman.delete_user(db_name)
		else:
			raise Exception("Database %s already exists" % (db_name,))

		# create user and db
		self.dbman.create_user(db_name, webnotes.conf.db_password)
			
		if verbose: print "Created user %s" % db_name
	
		# create a database
		self.dbman.create_database(db_name)
		if verbose: print "Created database %s" % db_name
		
		# grant privileges to user
		self.dbman.grant_all_privileges(db_name, db_name)
		if verbose: print "Granted privileges to user %s and database %s" % (db_name, db_name)

		# flush user privileges
		self.dbman.flush_privileges()
		
		# close root connection
		self.conn.close()

		webnotes.connect(db_name=db_name, site=self.site)
		self.dbman = DbManager(webnotes.conn)
		
		# import in db_name
		if verbose: print "Starting database import..."

		# get the path of the sql file to import
		if not source_sql:
			source_sql = os.path.join(os.path.dirname(webnotes.__file__), "..", 
				'conf', 'Framework.sql')

		self.dbman.restore_database(db_name, source_sql, db_name, webnotes.conf.db_password)
		if verbose: print "Imported from database %s" % source_sql
		
		self.create_auth_table()

		# fresh app
		if 'Framework.sql' in source_sql:
			if verbose: print "Installing app..."
			self.install_app(verbose=verbose)

		# update admin password
		self.update_admin_password(admin_password)
		
		# create public folder
		from webnotes.install_lib import setup_public_folder
		setup_public_folder.make(site=self.site)
		
		if not self.site:
			from webnotes.build import bundle
			bundle(False)
		
		return db_name
示例#19
0
class Installer:
    def __init__(self, root_login, root_password=None):

        import webnotes
        import webnotes.db

        if root_login and not root_password:
            import getpass
            root_password = getpass.getpass("MySQL root password: "******"""
		a very simplified version, just for the time being..will eventually be deprecated once the framework stabilizes.
		"""
        import conf

        # delete user (if exists)
        self.dbman.delete_user(target)

        # create user and db
        self.dbman.create_user(
            target,
            hasattr(conf, 'db_password') and conf.db_password or password)

        if verbose: print "Created user %s" % target

        # create a database
        self.dbman.create_database(target)
        if verbose: print "Created database %s" % target

        # grant privileges to user
        self.dbman.grant_all_privileges(target, target)
        if verbose:
            print "Granted privileges to user %s and database %s" % (target,
                                                                     target)

        # flush user privileges
        self.dbman.flush_privileges()

        self.conn.use(target)

        # import in target
        if verbose: print "Starting database import..."

        # get the path of the sql file to import
        source_given = True
        if not source_path:
            source_given = False
            source_path = os.path.join(
                os.path.sep.join(
                    os.path.abspath(webnotes.__file__).split(
                        os.path.sep)[:-3]), 'data', 'Framework.sql')

        self.dbman.restore_database(target, source_path, self.root_password)
        if verbose: print "Imported from database %s" % source_path

        # fresh app
        if 'Framework.sql' in source_path:
            from webnotes.model.sync import sync_install
            print "Building tables from all module..."
            sync_install()

        # framework cleanups
        self.framework_cleanups(target)
        if verbose: print "Ran framework startups on %s" % target

        return target

    def framework_cleanups(self, target):
        """create framework internal tables"""
        import webnotes
        self.create_sessions_table()
        self.create_scheduler_log()
        self.create_auth_table()

        # set the basic passwords
        webnotes.conn.begin()
        webnotes.conn.sql("""update __Auth set password = password('admin') 
			where user='******'""")
        webnotes.conn.commit()

    def create_sessions_table(self):
        """create sessions table"""
        import webnotes
        self.dbman.drop_table('tabSessions')
        webnotes.conn.sql("""CREATE TABLE `tabSessions` (
		  `user` varchar(40) DEFAULT NULL,
		  `sid` varchar(120) DEFAULT NULL,
		  `sessiondata` longtext,
		  `ipaddress` varchar(16) DEFAULT NULL,
		  `lastupdate` datetime DEFAULT NULL,
		  `status` varchar(20) DEFAULT NULL,
		  KEY `sid` (`sid`)
		) ENGINE=InnoDB DEFAULT CHARSET=utf8""")

    def create_scheduler_log(self):
        import webnotes
        self.dbman.drop_table('__SchedulerLog')
        webnotes.conn.sql("""create table __SchedulerLog (
			`timestamp` timestamp,
			method varchar(200),
			error text
		) engine=MyISAM""")

    def create_auth_table(self):
        import webnotes
        webnotes.conn.sql("""create table if not exists __Auth (
			`user` VARCHAR(180) NOT NULL PRIMARY KEY,
			`password` VARCHAR(180) NOT NULL
			) ENGINE=InnoDB DEFAULT CHARSET=utf8""")
示例#20
0
class Installer:
	def __init__(self, root_login, root_password=None, db_name=None, site=None, site_config=None):
		make_conf(db_name, site=site, site_config=site_config)
		self.site = site
		
		self.make_connection(root_login, root_password)

		webnotes.local.conn = self.conn
		webnotes.local.session = webnotes._dict({'user':'******'})
	
		self.dbman = DbManager(self.conn)
		
	def make_connection(self, root_login, root_password):
		if root_login:
			if not root_password:
				root_password = webnotes.conf.get("root_password") or None
			
			if not root_password:
				root_password = getpass.getpass("MySQL root password: "******"Database %s already exists" % (db_name,))

		# create user and db
		self.dbman.create_user(db_name, webnotes.conf.db_password)
			
		if verbose: print "Created user %s" % db_name
	
		# create a database
		self.dbman.create_database(db_name)
		if verbose: print "Created database %s" % db_name
		
		# grant privileges to user
		self.dbman.grant_all_privileges(db_name, db_name)
		if verbose: print "Granted privileges to user %s and database %s" % (db_name, db_name)

		# flush user privileges
		self.dbman.flush_privileges()
		
		# close root connection
		self.conn.close()

		webnotes.connect(db_name=db_name, site=self.site)
		self.dbman = DbManager(webnotes.conn)
		
		# import in db_name
		if verbose: print "Starting database import..."

		# get the path of the sql file to import
		if not source_sql:
			source_sql = os.path.join(os.path.dirname(webnotes.__file__), "..", 
				'conf', 'Framework.sql')

		self.dbman.restore_database(db_name, source_sql, db_name, webnotes.conf.db_password)
		if verbose: print "Imported from database %s" % source_sql
		
		self.create_auth_table()

		# fresh app
		if 'Framework.sql' in source_sql:
			if verbose: print "Installing app..."
			self.install_app(verbose=verbose)

		# update admin password
		self.update_admin_password(admin_password)
		
		# create public folder
		from webnotes.install_lib import setup_public_folder
		setup_public_folder.make(site=self.site)
		
		if not self.site:
			from webnotes.build import bundle
			bundle(False)
		
		return db_name
		
	def install_app(self, verbose=False):
		sync_for("lib", force=True, sync_everything=True, verbose=verbose)
		self.import_core_docs()

		try:
			from startup import install
		except ImportError, e:
			install = None

		if os.path.exists("app"):
			sync_for("app", force=True, sync_everything=True, verbose=verbose)

		if os.path.exists(os.path.join("app", "startup", "install_fixtures")):
			install_fixtures()

		if verbose: print "Completing App Import..."
		install and install.post_import()
		if verbose: print "Updating patches..."
		self.set_all_patches_as_completed()
		self.assign_all_role_to_administrator()
示例#21
0
class Installer:
	def __init__(self, root_login, root_password=None):

		import webnotes
		import webnotes.db
	
		if not root_password:
			import getpass
			root_password = getpass.getpass("MySQL root password: "******"""
		a very simplified version, just for the time being..will eventually be deprecated once the framework stabilizes.
		"""
		import conf
		
		# delete user (if exists)
		self.dbman.delete_user(target)

		# create user and db
		self.dbman.create_user(target, 
			hasattr(conf, 'db_password') and conf.db_password or password)
			
		if verbose: print "Created user %s" % target
	
		# create a database
		self.dbman.create_database(target)
		if verbose: print "Created database %s" % target
		
		# grant privileges to user
		self.dbman.grant_all_privileges(target,target)
		if verbose: print "Granted privileges to user %s and database %s" % (target, target)

		# flush user privileges
		self.dbman.flush_privileges()

		self.conn.use(target)
		
		# import in target
		if verbose: print "Starting database import..."

		# get the path of the sql file to import
		source_given = True
		if not source_path:
			source_given = False
			source_path = os.path.join(os.path.sep.join(os.path.abspath(webnotes.__file__).split(os.path.sep)[:-3]), 'data', 'Framework.sql')

		self.dbman.restore_database(target, source_path, self.root_password)
		if verbose: print "Imported from database %s" % source_path

		# fresh app
		if 'Framework.sql' in source_path:
			from webnotes.model.sync import sync_install
			print "Building tables from all module..."
			sync_install()

		# framework cleanups
		self.framework_cleanups(target)
		if verbose: print "Ran framework startups on %s" % target
		
		return target	

	def framework_cleanups(self, target):
		"""create framework internal tables"""
		import webnotes
		self.create_sessions_table()
		self.create_scheduler_log()
		self.create_session_cache()
		self.create_cache_item()

		# set the basic passwords
		webnotes.conn.begin()
		webnotes.conn.sql("""update tabProfile set password = password('admin') 
			where name='Administrator'""")
		webnotes.conn.commit()

	def create_sessions_table(self):
		"""create sessions table"""
		import webnotes
		self.dbman.drop_table('tabSessions')
		webnotes.conn.sql("""CREATE TABLE `tabSessions` (
		  `user` varchar(40) DEFAULT NULL,
		  `sid` varchar(120) DEFAULT NULL,
		  `sessiondata` longtext,
		  `ipaddress` varchar(16) DEFAULT NULL,
		  `lastupdate` datetime DEFAULT NULL,
		  `status` varchar(20) DEFAULT NULL,
		  KEY `sid` (`sid`)
		) ENGINE=InnoDB DEFAULT CHARSET=utf8""")
	
	def create_scheduler_log(self):
		import webnotes
		self.dbman.drop_table('__SchedulerLog')
		webnotes.conn.sql("""create table __SchedulerLog (
			`timestamp` timestamp,
			method varchar(200),
			error text
		) engine=MyISAM""")
	
	def create_session_cache(self):
		import webnotes
		self.dbman.drop_table('__SessionCache')
		webnotes.conn.sql("""create table `__SessionCache` ( 
			user VARCHAR(120), 
			country VARCHAR(120), 
			cache LONGTEXT)""")

	def create_cache_item(self):
		import webnotes
		self.dbman.drop_table('__CacheItem')
		webnotes.conn.sql("""create table __CacheItem(
			`key` VARCHAR(180) NOT NULL PRIMARY KEY,
			`value` LONGTEXT,
			`expires_on` DATETIME
			) ENGINE=MyISAM DEFAULT CHARSET=utf8""")
示例#22
0
def make_scheduler(root_login, root_password, verbose):
    """
		Make the database where all scheduler events will be stored from multiple datbases
		See webnotes.utils.scheduler for more information
	"""
    conn = webnotes.db.Database(user=root_login, password=root_password)

    from webnotes.model.db_schema import DbManager

    dbman = DbManager(conn)

    # delete user (if exists)
    dbman.delete_user('master_scheduler')

    # create user and db
    dbman.create_user('master_scheduler',
                      getattr(webnotes.defs, 'scheduler_password', None))
    if verbose: print "Created user master_scheduler"

    # create a database
    dbman.create_database('master_scheduler')
    if verbose: print "Created database master_scheduler"

    # grant privileges to user
    dbman.grant_all_privileges('master_scheduler', 'master_scheduler')

    # flush user privileges
    dbman.flush_privileges()

    conn.use('master_scheduler')

    # create events table
    conn.sql("""create table Event(
		`db_name` varchar(60),
		`event` varchar(180),
		`interval` int(20),
		`next_execution` timestamp,
		`recurring` int(1),
		primary key (`db_name`, `event`),
		index next_execution(next_execution)
		)""")

    conn.sql("""create table EventLog(
		`db_name` varchar(180), 
		`event` varchar(180),
		`executed_on` timestamp,
		`log` text,
		index executed_on(executed_on))
	""")
示例#23
0
class test_doc(unittest.TestCase):
	""" 
	Basic test cases for the doc object.
	the numbering 1,2,3..is just to make sure order of execution. the testrunner otherwise sorts by function name.
	
	"""
	
	def setUp(self):
		self.test_doc = doc.Document('')
		self.f1 = doc.Document('')
		self.f2 = doc.Document('')
		self.f3 = doc.Document('')
		self.f4 = doc.Document('')
		self.p = doc.Document('')
		webnotes.session = testlib.test_webnotes_session
		webnotes.conn = testlib.test_conn
		self.dbman = DbManager(webnotes.conn)
	
		
	def test_1_create_new_doctype_record(self):
				
		# create tabAccount
		self.test_doc = doc.Document('DocType')
		self.test_doc.name = testlib.test_doctype
		self.test_doc.autoname = testlib.test_doctype_autoname
		self.test_doc.save(1)
		webnotes.conn.commit()
		assert (testlib.test_conn.sql("select count(*) from tabDocType where name = '%s'"%testlib.test_doctype)[0][0])

	def test_2_create_new_doctype_table(self):
		updatedb((testlib.test_doctype))
		table_list = self.dbman.get_tables_list(testlib.test_db)
		webnotes.conn.commit()
		assert ('tab'+testlib.test_doctype in table_list)
		
		
	def test_3_create_new_docfields(self):
	
		self.f1 = self.test_doc.addchild('fields', 'DocField')
		self.f1.label = 'Test Account Name'
		self.f1.fieldname = 'test_ac_name'
		self.f1.fieldtype = 'Data'
		self.f1.save()
	
	
		self.f2 = self.test_doc.addchild('fields', 'DocField')
		self.f2.label = 'Database Name'
		self.f2.fieldname = 'test_db_name'
		self.f2.fieldtype = 'Data'
		self.f2.save()

		self.f3 = self.test_doc.addchild('fields', 'DocField')
		self.f3.label = 'Database Login'
		self.f3.fieldname = 'test_db_login'
		self.f3.fieldtype = 'Data'
		self.f3.save()

		self.f4 = self.test_doc.addchild('fields', 'DocField')
		self.f4.label = 'App Login' 
		self.f4.fieldname = 'test_app_login'
		self.f4.fieldtype = 'Data'
		self.f4.save()
		

		updatedb((testlib.test_doctype))
		webnotes.conn.commit()
		assert (testlib.test_conn.sql("select count(*) from tabDocField where name = '%s'"%self.f1.fieldname)[0][0])
		assert (testlib.test_conn.sql("select count(*) from tabDocField where name = '%s'"%self.f2.fieldname)[0][0])
		assert (testlib.test_conn.sql("select count(*) from tabDocField where name = '%s'"%self.f3.fieldname)[0][0])
		assert (testlib.test_conn.sql("select count(*) from tabDocField where name = '%s'"%self.f4.fieldname)[0][0])
		
		
	def test_4_create_docperms(self):
		
		self.p = self.test_doc.addchild(testlib.test_docperm, 'DocPerm')
		self.p.role =  'Administrator'
		self.p.read = 1
		self.p.write = 1
		self.p.create = 1
		self.p.save()
		webnotes.conn.commit()
		assert testlib.test_conn.sql("select count(*) from tabDocPerm where name = '%s'"%self.p.name)[0][0]
		

		
		
	def test_5_make_autoname(self):
		new_name = doc.make_autoname(self.test_doc.name,self.test_doc.parenttype)
		last_name = testlib.test_conn.sql("select name from `tab%s` order by name desc limit 1"%testlib.test_doctype)		
		if not last_name:
			last_name = '0'
		webnotes.conn.commit()
		assert (cint(new_name[get_num_start_pos(new_name):])) - cint(last_name[get_num_start_pos(last_name):])
		
		
	def test_6_delete_doctype_record(self):
		
		delete_doc('DocType',testlib.test_doctype)
		webnotes.conn.commit()
		assert (not testlib.test_conn.sql("select count(*) from tabDocType where name = '%s'"%testlib.test_doctype)[0][0])

		
	def test_7_delete_docfield_record(self):
		
		delete_doc('DocField',self.f1.name)
		delete_doc('DocField',self.f2.name)
		delete_doc('DocField',self.f3.name)
		delete_doc('DocField',self.f4.name)
		delete_doc('DocField',self.p.name)
		webnotes.conn.commit()
		assert (not testlib.test_conn.sql("select count(*) from tabDocType where name = '%s'"%self.f1.name)[0][0])
示例#24
0
class Installer:
    def __init__(self, root_login, root_password=None):
        if root_login:
            if not root_password:
                root_password = getattr(conf, "root_password", None)
            if not root_password:
                root_password = getpass.getpass("MySQL root password: "******"""
		a very simplified version, just for the time being..will eventually be deprecated once the framework stabilizes.
		"""
        # delete user (if exists)
        self.dbman.delete_user(target)

        # create user and db
        self.dbman.create_user(target, conf.db_password)

        if verbose: print "Created user %s" % target

        # create a database
        self.dbman.create_database(target)
        if verbose: print "Created database %s" % target

        # grant privileges to user
        self.dbman.grant_all_privileges(target, target)
        if verbose:
            print "Granted privileges to user %s and database %s" % (target,
                                                                     target)

        # flush user privileges
        self.dbman.flush_privileges()

        self.conn.use(target)

        # import in target
        if verbose: print "Starting database import..."

        # get the path of the sql file to import
        source_given = True
        if not source_path:
            source_given = False
            source_path = os.path.join(
                os.path.sep.join(
                    os.path.abspath(webnotes.__file__).split(
                        os.path.sep)[:-3]), 'data', 'Framework.sql')

        self.dbman.restore_database(target, source_path, target,
                                    conf.db_password)
        if verbose: print "Imported from database %s" % source_path

        # fresh app
        if 'Framework.sql' in source_path:
            print "Installing app..."
            self.install_app()

        # update admin password
        self.create_auth_table()
        self.update_admin_password(password)
        return target

    def install_app(self):
        try:
            from startup import install
        except ImportError, e:
            print "No app install found"

        sync_for("lib", force=True, sync_everything=True)
        self.import_core_docs()
        install.pre_import()
        sync_for("app", force=True, sync_everything=True)
        print "Completing App Import..."
        install.post_import()
        print "Updating patches..."
        self.set_all_patches_as_completed()
示例#25
0
    def install(self,
                db_name,
                source_sql=None,
                admin_password='******',
                verbose=0,
                force=0):

        if force or (db_name not in self.dbman.get_database_list()):
            # delete user (if exists)
            self.dbman.delete_user(db_name)
        else:
            raise Exception("Database %s already exists" % (db_name, ))

        # create user and db
        self.dbman.create_user(db_name, webnotes.conf.db_password)

        if verbose: print "Created user %s" % db_name

        # create a database
        self.dbman.create_database(db_name)
        if verbose: print "Created database %s" % db_name

        # grant privileges to user
        self.dbman.grant_all_privileges(db_name, db_name)
        if verbose:
            print "Granted privileges to user %s and database %s" % (db_name,
                                                                     db_name)

        # flush user privileges
        self.dbman.flush_privileges()

        # close root connection
        self.conn.close()

        webnotes.connect(db_name=db_name, site=self.site)
        self.dbman = DbManager(webnotes.conn)

        # import in db_name
        if verbose: print "Starting database import..."

        # get the path of the sql file to import
        if not source_sql:
            source_sql = os.path.join(os.path.dirname(webnotes.__file__), "..",
                                      'conf', 'Framework.sql')

        self.dbman.restore_database(db_name, source_sql, db_name,
                                    webnotes.conf.db_password)
        if verbose: print "Imported from database %s" % source_sql

        self.create_auth_table()

        # fresh app
        if 'Framework.sql' in source_sql:
            if verbose: print "Installing app..."
            self.install_app(verbose=verbose)

        # update admin password
        self.update_admin_password(admin_password)

        # create public folder
        from webnotes.install_lib import setup_public_folder
        setup_public_folder.make(site=self.site)

        if not self.site:
            from webnotes.build import bundle
            bundle(False)

        return db_name
示例#26
0
class Installer:
	def __init__(self, root_login, root_password=None):
		if root_login:
			if not root_password:
				root_password = getattr(conf, "root_password", None)
			if not root_password:
				root_password = getpass.getpass("MySQL root password: "******"""
		a very simplified version, just for the time being..will eventually be deprecated once the framework stabilizes.
		"""		
		# delete user (if exists)
		self.dbman.delete_user(target)

		# create user and db
		self.dbman.create_user(target, conf.db_password)
			
		if verbose: print "Created user %s" % target
	
		# create a database
		self.dbman.create_database(target)
		if verbose: print "Created database %s" % target
		
		# grant privileges to user
		self.dbman.grant_all_privileges(target,target)
		if verbose: print "Granted privileges to user %s and database %s" % (target, target)

		# flush user privileges
		self.dbman.flush_privileges()

		self.conn.use(target)
		
		# import in target
		if verbose: print "Starting database import..."

		# get the path of the sql file to import
		source_given = True
		if not source_path:
			source_given = False
			source_path = os.path.join(os.path.sep.join(os.path.abspath(webnotes.__file__).split(os.path.sep)[:-3]), 'data', 'Framework.sql')

		self.dbman.restore_database(target, source_path, target, conf.db_password)
		if verbose: print "Imported from database %s" % source_path

		# fresh app
		if 'Framework.sql' in source_path:
			print "Installing app..."
			self.install_app()

		# update admin password
		self.create_auth_table()
		self.update_admin_password(password)
		return target
		
	def install_app(self):
		try:
			from startup import install
		except ImportError, e:
			print "No app install found"

		sync_for("lib", force=True, sync_everything=True)
		self.import_core_docs()
		install.pre_import()
		sync_for("app", force=True, sync_everything=True)
		print "Completing App Import..."
		install.post_import()
		print "Updating patches..."
		self.set_all_patches_as_completed()
示例#27
0
class Installer:
    def __init__(self, root_login, root_password):

        self.root_password = root_password
        from webnotes.model.db_schema import DbManager

        self.conn = webnotes.db.Database(user=root_login, password=root_password)
        webnotes.conn = self.conn
        webnotes.session = {"user": "******"}
        self.dbman = DbManager(self.conn)
        self.mysql_path = hasattr(defs, "mysql_path") and webnotes.defs.mysql_path or ""

        #
        # run framework related cleanups
        #

    def framework_cleanups(self, target):
        self.dbman.drop_table("__DocTypeCache")
        webnotes.conn.sql(
            "create table `__DocTypeCache` (name VARCHAR(120), modified DATETIME, content TEXT, server_code_compiled TEXT)"
        )

        # set the basic passwords
        webnotes.conn.begin()
        webnotes.conn.sql("update tabProfile set password = password('admin') where name='Administrator'")
        webnotes.conn.commit()

    def import_core_module(self):
        """
			Imports the "Core" module from .txt file and creates
			Creates profile Administrator
		"""
        from webnotes.modules.import_module import import_module
        from webnotes.modules.module_manager import reload_doc

        reload_doc("core", "doctype", "doctype")
        reload_doc("core", "doctype", "docfield")
        reload_doc("core", "doctype", "docperm")

        import_module("core")

        webnotes.conn.begin()

        from webnotes.model.doc import Document

        p = Document("Profile")
        p.name = p.first_name = "Administrator"
        p.email = "admin@localhost"
        p.save(new=1)

        ur = Document("UserRole")
        ur.parent = "Administrator"
        ur.role = "Administrator"
        ur.parenttype = "Profile"
        ur.parentfield = "userroles"
        p.enabled = 1
        ur.save(1)

        p = Document("Profile")
        p.name = p.first_name = "Guest"
        p.email = "guest@localhost"
        p.enabled = 1
        p.save(new=1)

        ur = Document("UserRole")
        ur.parent = "Guest"
        ur.role = "Guest"
        ur.parenttype = "Profile"
        ur.parentfield = "userroles"
        ur.save(1)

        webnotes.conn.commit()

        #
        # main script to create a database from
        #

    def import_from_db(self, target, source_path="", password="******", verbose=0):
        """
		a very simplified version, just for the time being..will eventually be deprecated once the framework stabilizes.
		"""

        # get the path of the sql file to import
        if not source_path:
            source_path = os.path.join(
                os.path.sep.join(os.path.abspath(webnotes.__file__).split(os.path.sep)[:-3]), "data", "Framework.sql"
            )

            # delete user (if exists)
        self.dbman.delete_user(target)

        # create user and db
        self.dbman.create_user(target, getattr(defs, "db_password", None))
        if verbose:
            print "Created user %s" % target

        # create a database
        self.dbman.create_database(target)
        if verbose:
            print "Created database %s" % target

        # grant privileges to user
        self.dbman.grant_all_privileges(target, target)
        if verbose:
            print "Granted privileges to user %s and database %s" % (target, target)

        # flush user privileges
        self.dbman.flush_privileges()

        self.conn.use(target)

        # import in target
        if verbose:
            print "Starting database import..."
        self.dbman.restore_database(target, source_path, self.root_password)
        if verbose:
            print "Imported from database %s" % source_path

        self.import_core_module()

        # framework cleanups
        self.framework_cleanups(target)
        if verbose:
            print "Ran framework startups on %s" % target

        return target