def xmlrpc_editProject(self, queryParams, client_id): """ * Purpose: - function for edit projectname - it will alter projectname ans update it. * Input: - [projectcode,projectname] * Output: - return string ``updated successfully`` """ queryParams = blankspace.remove_whitespaces(queryParams) transaction = rpc_transaction.transaction() connection = dbconnect.engines[client_id].connect() Session = dbconnect.session(bind=connection) result = Session.query(dbconnect.Projects).\ filter(dbconnect.Projects.projectcode == queryParams[0]).\ update({'projectname': queryParams[1]}) Session.commit() Session.close() connection.connection.close() return "upadted successfully"
def xmlrpc_getAccountNamesByProjectName(self,queryParams,client_id): """ * Purpose: - call ``getProjectcoeByProjectName`` to get projectcode - using projectcode we will get accountnames used in transaction for given projectname. - function will return list of accountnames for particular projectname * Input: - [projectname] * Output: - list of accountnames """ transaction = rpc_transaction.transaction() projectcode = transaction.xmlrpc_getProjectcodeByProjectName(queryParams,client_id) statement = 'select distinct(account_name)\ from view_voucherbook\ where projectcode = "'+str(projectcode)+'"\ and flag = 1\ order by account_name' result = dbconnect.engines[client_id].execute(statement).fetchall() accountname = [] for Row in result: accountname.append(Row[0]) return accountname
def xmlrpc_hasProjectTransactions(self, queryParams, client_id): """ Purpose: Function to find out whether the given projectname has any transactions or not It will take projectname as a first parameter and then getprojetcode to delete project Input: queryParams[projectname(datatype:String)] Output: It returns strig "1" when transaction with projectname is present else return "0" """ transaction = rpc_transaction.transaction() connection = dbconnect.engines[client_id].connect() Session = dbconnect.session(bind=connection) projectcode = transaction.xmlrpc_getProjectcodeByProjectName( [queryParams[0]], client_id) statement = "select count(vouchercode) as vouchercodeCount\ from view_voucherbook\ where projectcode ='" + str(projectcode) + "'" result = dbconnect.engines[client_id].execute(statement).fetchone() Session.close() connection.connection.close() if result[0] == 0: return 0 if result[0] > 0: return 1
def xmlrpc_hasProjectTransactions(self, queryParams, client_id): """ * Purpose: - function to find out whether the given projectname has any transactions or not - it will take projectname as a first parameter and then getprojetcode to delete project * Input: - queryParams[projectname(datatype:String)] * Output: - It returns strig "1" when transaction with projectname is present else return "0" """ transaction = rpc_transaction.transaction() connection = dbconnect.engines[client_id].connect() Session = dbconnect.session(bind=connection) projectcode = transaction.xmlrpc_getProjectcodeByProjectName([queryParams[0]],client_id) statement = "select count(vouchercode) as vouchercodeCount\ from view_voucherbook\ where projectcode ='"+str(projectcode)+"'" result = dbconnect.engines[client_id].execute(statement).fetchone() Session.close() connection.connection.close() if result[0] == 0: return 0 if result[0] > 0: return 1
def xmlrpc_getAccountNamesByProjectName(self,queryParams,client_id): ''' Purpose : This function will return list of accountnames for particular projectname Input parameters: projectname output : list of accountnames ''' transaction = rpc_transaction.transaction() projectcode = transaction.xmlrpc_getProjectcodeByProjectName(queryParams,client_id) statement = "select distinct(account_name)\ from view_voucherbook\ where projectcode = '"+str(projectcode)+"'\ and flag = 1\ order by account_name" result = dbconnect.engines[client_id].execute(statement).fetchall() accountname = [] for Row in result: accountname.append(Row[0]) return accountname
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_getAccountNamesByProjectName(self, queryParams, client_id): ''' Purpose : This function will return list of accountnames for particular projectname Input parameters: projectname output : list of accountnames ''' transaction = rpc_transaction.transaction() projectcode = transaction.xmlrpc_getProjectcodeByProjectName( queryParams, client_id) statement = "select distinct(account_name)\ from view_voucherbook\ where projectcode = '" + str(projectcode) + "'\ and flag = 1\ order by account_name" result = dbconnect.engines[client_id].execute(statement).fetchall() accountname = [] for Row in result: accountname.append(Row[0]) return accountname
def xmlrpc_editProject(self, queryParams, client_id): """ Purpose: function for edit projectname Input: queryParams[projectcode,projectname] Output: Return string when it updated successfully """ queryParams = blankspace.remove_whitespaces(queryParams) transaction = rpc_transaction.transaction() connection = dbconnect.engines[client_id].connect() Session = dbconnect.session(bind=connection) result = Session.query(dbconnect.Projects).\ filter(dbconnect.Projects.projectcode == queryParams[0]).\ update({'projectname': queryParams[1]}) Session.commit() Session.close() connection.connection.close() return "upadted successfully"
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)
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() abt.putSubHandler('reports',reports) user=rpc_user.user() abt.putSubHandler('user',user) getaccountsbyrule=rpc_getaccountsbyrule.getaccountsbyrule() abt.putSubHandler('getaccountsbyrule',getaccountsbyrule) def runabt():
# 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() abt.putSubHandler("reports", reports) user = rpc_user.user() abt.putSubHandler("user", user) getaccountsbyrule = rpc_getaccountsbyrule.getaccountsbyrule() abt.putSubHandler("getaccountsbyrule", getaccountsbyrule)