示例#1
0
def runabt():
	"""
	+ As we have imported all the nested XMLRPC resource,so that create one handler ``abt`` 
	  calls another if a method with a given prefix is called.
	+ and publish that handelr instance ``abt`` to server .
	+ this is ``def runabt()`` which is outside ``class abt():``.	"""
	import rpc_main
	# create the instance of class abt
	abt = rpc_main.abt()
	groups=rpc_groups.groups()
	abt.putSubHandler('groups',groups)

	account=rpc_account.account()
	abt.putSubHandler('account',account)

	organisation = rpc_organisation.organisation()
	abt.putSubHandler('organisation',organisation)

	transaction=rpc_transaction.transaction()
	abt.putSubHandler('transaction',transaction)

	data=rpc_data.data()
	abt.putSubHandler('data',data)

	reports=rpc_reports.reports()
	abt.putSubHandler('reports',reports)

	user = rpc_user.user()
	abt.putSubHandler('user',user)

	getaccountsbyrule=rpc_getaccountsbyrule.getaccountsbyrule()
	abt.putSubHandler('getaccountsbyrule',getaccountsbyrule)

	print "initialising application"
	
	#publish the object and make it to listen on the given port through reactor
	print "starting server"
	reactor.listenTCP(7081, server.Site(abt))
	#start the service by running the reactor.
	reactor.run()
	def xmlrpc_setAccount(self, queryParams, client_id):
		"""
		* Purpose:
			- it call ``getGroupCodeByGroupName()`` from ``rpc_groups`` 
			  pass param groupname will return groupcode
			- adds an account in the account table, under a selected group and optionally a subgroup.
			- depending on the preference choosen by the user.
			- this function insert a row in the account table.
			- connection made with engine of sessions using client_id.
			- add query will be execute.

		* Input:
			- queryParams[groupname,subgroupname,newsubgroupname,accountname,
				 accountcodetype,openingbalance,currentBalance,suggestedcode]
		
		* Output: 
			- returns String "success"
		"""
		group = rpc_groups.groups()
		queryParams = blankspace.remove_whitespaces(queryParams)
		sp_params = [queryParams[0], queryParams[3]] # create sp_params list contain  groupname , accountname 
		if queryParams[2] == "": # check for the new-subgroupname if blank then 

			if queryParams[1] == "No Sub-Group": # check for the subgroupname if "No Sub-Group" 
				
				sp_params.append("null")  # append null to sp_params list as 3rd parameter else 
			else:
				sp_params.append(queryParams[1]) # else append subgroupname sp_params list as 3rd parameter
				
		if queryParams[1] == "Create New Sub-Group" : # subgroupname is "Create New Sub-Group" then
			
			sp_params.append(queryParams[2]) # append new-subgroupname to sp_params list as 4rd parameter
		if queryParams[0] == "Direct Income" or queryParams[0] == "Direct Expense"\
		   or queryParams[0] == "Indirect Income" or queryParams[0] == "Indirect Expense": # check for groupname
		   
			sp_params.append(0) # if above groupname then append 0 as opening balance 
		else:
			sp_params.append(queryParams[5]) 
			
		now = datetime.today() # sqlite take datetime or date object for TIMESTAMP
		sp_params.append(now) # append the current date of system while setting account
		sp_params.append(sp_params[3]) # append accountname
		
		if queryParams[6] == "": # chech for suggested account code
		
			sp_params.append("null") # if blank then append "null"
		else:
			sp_params.append(queryParams[6]) # else append suggestedcode
		
		# execute here
		connection = dbconnect.engines[client_id].connect()
		Session = dbconnect.session(bind=connection)
		# call getGroupCodeByGroupName() pass param groupname will return groupcode
		group_code = group.xmlrpc_getGroupCodeByGroupName([sp_params[0]], client_id); 
		# check for accountcode if null
		
 		if sp_params[6] == 'null': # then
 			
 			result = Session.query(dbconnect.Account.accountcode).\
		      	 		order_by(dbconnect.Account.accountcode).\
		      			all()
		      	accountcode = []
			if result == []:
				maxcode = []
			else:
				for row in result:
					accountcode.append(int(row.accountcode))
					maxcode = accountcode
 			
 			if maxcode == []:
				maxcode = 0
				sp_params[6] = int(maxcode) + 1;
			else:
				maxcode = max(maxcode)
				sp_params[6] = int(maxcode) + 1;
				
		# check for new-subgropname if null	
		print "account params"
		print sp_params
		if sp_params[2] == 'null': # then 
			# add all values in the account table
			Session.add(dbconnect.Account(\
						sp_params[6],group_code[0],None,sp_params[1],sp_params[3],sp_params[4]))
			Session.commit()
		else:
			# if new-subgroupname is present then call getSubGroupCodeBySubGroupName pass params new-subgroupname
			# it will return subgroupcode or False
			
			subgroup_code =  group.xmlrpc_getSubGroupCodeBySubGroupName([sp_params[2]], client_id)
			# check for subgroupcode if False 
			
			if subgroup_code == [] : # then 
			        # call setSubGroup pass params groupname , new-subgroupname , client-id
   				group.xmlrpc_setSubGroup([sp_params[0],sp_params[2]],client_id); 
   				# call getSubGroupCodeBySubGroupName pass params new-subgroupname return subgroupcode
   				subgroup_code =  group.xmlrpc_getSubGroupCodeBySubGroupName([sp_params[2]], client_id); 
   			# add all the values in the account table
   			Session.add(dbconnect.Account(\
   						sp_params[6],group_code[0],subgroup_code[0],sp_params[1],\
   						sp_params[3],sp_params[4]))
   				
   			Session.commit()
                	Session.close()
                	connection.connection.close()
                	
		return "success"
示例#3
0
def runabt():
	"""
	+ As we have imported all the nested XMLRPC resource,so that create one handler ``abt`` 
	  calls another if a method with a given prefix is called.
	+ and publish that handelr instance ``abt`` to server .
	+ this is ``def runabt()`` which is outside ``class abt():``.
	"""
	import rpc_main
	# create the instance of class abt
	abt = rpc_main.abt()
	groups=rpc_groups.groups()
	abt.putSubHandler('groups',groups)

	account=rpc_account.account()
	abt.putSubHandler('account',account)

	organisation = rpc_organisation.organisation()
	abt.putSubHandler('organisation',organisation)

	transaction=rpc_transaction.transaction()
	abt.putSubHandler('transaction',transaction)

	data=rpc_data.data()
	abt.putSubHandler('data',data)

	reports=rpc_reports.reports()
	abt.putSubHandler('reports',reports)

	user = rpc_user.user()
	abt.putSubHandler('user',user)

	getaccountsbyrule=rpc_getaccountsbyrule.getaccountsbyrule()
	abt.putSubHandler('getaccountsbyrule',getaccountsbyrule)

	print "initialising application"
	#the code to daemonise published instance.
	
 	# Daemonizing abt
	# Accept commandline arguments
	# A workaround for debugging
	def usage():
		print "Usage: %s [d|debug] [h|help]\n" % (sys.argv[0])
		print "\td (debug)\tStart server in debug mode. Do not fork a daemon."
		print "\td (help)\tShow this help"

	try:
		opts, args = getopt.getopt(sys.argv[1:], "hd", ["help","debug"])
	except getopt.GetoptError:
		usage()
		os._exit(2)

	debug = 0
	for opt, arg in opts:
		if opt in ("h", "help"):
			usage()
			os.exit(0)
		elif opt in ("d", "debug"):
			debug = 1

	# Do not fork if we are debug mode
	if debug == 0:
		try:
			pid = os.fork()
		except OSError, e:
			raise Exception, "Could not fork a daemon: %s" % (e.strerror)

		if pid != 0:
			os._exit(0)

		# Prevent it from being orphaned
		os.setsid()
	
		# Change working directory to root
		os.chdir("/")

		# Change umask
		os.umask(0)

		# All prints should be replaced with logging, preferrably into syslog
		# The standard I/O file descriptors are redirected to /dev/null by default.
		if (hasattr(os, "devnull")):
			REDIRECT_TO = os.devnull
		else:
			REDIRECT_TO = "/dev/null"

		# Redirect the standard I/O file descriptors to the specified file.  Since
		# the daemon has no controlling terminal, most daemons redirect stdin,
		# stdout, and stderr to /dev/null.  This is done to prevent sideeffects
		# from reads and writes to the standard I/O file descriptors.

		# This call to open is guaranteed to return the lowest file descriptor,
		# which will be 0 (stdin), since it was closed above.
		os.open(REDIRECT_TO, os.O_RDWR)	# standard input (0)

		# Duplicate standard input to standard output and standard error.
		os.dup2(0, 1)			# standard output (1)
		os.dup2(0, 2)			# standard error (2)
示例#4
0
    def xmlrpc_setAccount(self, queryParams, client_id):
        """
		Purpose: Adds an account in the account table, under a selected 
			group and optionally a subgroup.  
			depending on the preference choosen by the user.
			This function insert a row in the account table.
		        it takes one parameter named queryParams which is a list containing,
		
		Input: queryParams[groupname,subgroupname,newsubgroupname,accountname,
		accountcodetype,openingbalance,currentBalance,suggestedcode]
		
		Output: Returns String "success"
		"""
        group = rpc_groups.groups()

        queryParams = blankspace.remove_whitespaces(queryParams)
        sp_params = [
            queryParams[0], queryParams[3]
        ]  # create sp_params list contain  groupname , accountname
        if queryParams[
                2] == "":  # check for the new-subgroupname if blank then

            if queryParams[
                    1] == "No Sub-Group":  # check for the subgroupname if "No Sub-Group"

                sp_params.append(
                    "null"
                )  # append null to sp_params list as 3rd parameter else
            else:
                sp_params.append(
                    queryParams[1]
                )  # else append subgroupname sp_params list as 3rd parameter

        if queryParams[
                1] == "Create New Sub-Group":  # subgroupname is "Create New Sub-Group" then

            sp_params.append(
                queryParams[2]
            )  # append new-subgroupname to sp_params list as 4rd parameter
        if queryParams[0] == "Direct Income" or queryParams[0] == "Direct Expense"\
           or queryParams[0] == "Indirect Income" or queryParams[0] == "Indirect Expense": # check for groupname

            sp_params.append(
                0)  # if above groupname then append 0 as opening balance
        else:
            sp_params.append(queryParams[5])

        now = datetime.today(
        )  # sqlite take datetime or date object for TIMESTAMP
        #date = now.strftime("%Y-%m-%d %H:%M:%S")
        sp_params.append(
            now)  # append the current date of system while setting account
        sp_params.append(sp_params[3])  # append accountname

        if queryParams[7] == "":  # chech for suggested account code

            sp_params.append("null")  # if blank then append "null"
        else:
            sp_params.append(queryParams[7])  # else append suggestedcode

        # execute here
        connection = dbconnect.engines[client_id].connect()
        Session = dbconnect.session(bind=connection)
        # call getGroupCodeByGroupName() pass param groupname will return groupcode
        group_code = group.xmlrpc_getGroupCodeByGroupName([sp_params[0]],
                                                          client_id)
        # check for accountcode if null

        if sp_params[6] == 'null':  # then

            result = Session.query(dbconnect.Account.accountcode).\
                    order_by(dbconnect.Account.accountcode).\
                   all()
            accountcode = []
            if result == []:
                maxcode = []
            else:
                for row in result:
                    accountcode.append(int(row.accountcode))
                    maxcode = accountcode

            if maxcode == []:
                maxcode = 0
                sp_params[6] = int(maxcode) + 1
            else:
                maxcode = max(maxcode)
                sp_params[6] = int(maxcode) + 1

        # check for new-subgropname if null
        if sp_params[2] == 'null':  # then
            # add all values in the account table
            Session.add(dbconnect.Account(\
               sp_params[6],group_code[0],"",sp_params[1],sp_params[3],sp_params[4],sp_params[5]))
            Session.commit()
        else:
            # if new-subgroupname is present then call getSubGroupCodeBySubGroupName pass params new-subgroupname
            # it will return subgroupcode or False

            subgroup_code = group.xmlrpc_getSubGroupCodeBySubGroupName(
                [sp_params[2]], client_id)
            # check for subgroupcode if False

            if subgroup_code == []:  # then
                # call setSubGroup pass params groupname , new-subgroupname , client-id
                group.xmlrpc_setSubGroup([sp_params[0], sp_params[2]],
                                         client_id)
                # call getSubGroupCodeBySubGroupName pass params new-subgroupname return subgroupcode
                subgroup_code = group.xmlrpc_getSubGroupCodeBySubGroupName(
                    [sp_params[2]], client_id)
# add all the values in the account table
            Session.add(dbconnect.Account(\
               sp_params[6],group_code[0],subgroup_code[0],sp_params[1],\
               sp_params[3],sp_params[4],sp_params[5]))

            Session.commit()
            Session.close()
            connection.connection.close()

        return "success"
示例#5
0
		Session.commit()

		Session.add_all([\
			dbconnect.Flags(None,'mandatory'),\
			dbconnect.Flags(None,'automatic')\
		])
		Session.commit()

		Session.close()
		connection.close()
		return True,self.client_id
# create the instance of class abt

abt = abt()

groups=rpc_groups.groups()
abt.putSubHandler('groups',groups)

account=rpc_account.account()
abt.putSubHandler('account',account)

organisation = rpc_organisation.organisation()
abt.putSubHandler('organisation',organisation)

transaction=rpc_transaction.transaction()
abt.putSubHandler('transaction',transaction)

data=rpc_data.data()
abt.putSubHandler('data',data)

reports=rpc_reports.reports()
示例#6
0
        Session.commit()

        Session.add_all([dbconnect.Flags(None, "mandatory"), dbconnect.Flags(None, "automatic")])
        Session.commit()

        Session.close()
        connection.close()
        return True, self.client_id


# create the instance of class abt

abt = abt()

groups = rpc_groups.groups()
abt.putSubHandler("groups", groups)

account = rpc_account.account()
abt.putSubHandler("account", account)

organisation = rpc_organisation.organisation()
abt.putSubHandler("organisation", organisation)

transaction = rpc_transaction.transaction()
abt.putSubHandler("transaction", transaction)

data = rpc_data.data()
abt.putSubHandler("data", data)

reports = rpc_reports.reports()