Hylafax Mailing List Archives

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

[hylafax-users] pythonutils.hylafaxutil



Hello,
I am using the object pythonutils.hylafaxutil generated in python language.

I have found a little bug in it:
jobid's are generated in two digit basis; so we  can only have jobids
between 1 and 99.

I have fixed the source code: hfaxlib.py   specially I have modify how the
job id is generated in the job_new method:

Regards

Victor M. Moreno


The new code follow:

#!/usr/bin/env python

# Author: Harald Holzer
# 5.4.2000: Initial release

# 6.5.2000: Harald Holzer
# added logging support

# 12.6.2000: Victor M. Moreno   vmoreno@germinus.com
#         support jobid longer than 2 digits.
#         job_new method modified

import string,sys
from socket import *


class hfax:
    s=None
    sf=None
    d=None
    df=None
    user=""
    pw=""
    host=""
    port=4559
    debuglevel=0
    logfile="c:\w2hfax.log"

    def readline(self):
 data=self.sf.readline()
 self.loginfo("read: " + data)
 return data

    def writeline(self,line):
 self.loginfo("write: " + line)
 self.s.send(line)

    def connect(self,host,user,pw):
 self.host=host
 self.user=user
 self.pw=pw
 self.s=socket(AF_INET,SOCK_STREAM)
 try:
     self.s.connect(host,self.port)
     self.sf=self.s.makefile("rw")
     line=self.readline()
     self.writeline("USER " + user + "\n")
     line=self.readline()
     if line[:3]=="230":
  rc=0
     else:
  rc=1
 except error,detail:
     self.loginfo("error: " + str(detail))
     rc=2
 return rc

    def job_new(self):
 self.writeline("JOB default\n")
 self.readline()
 self.writeline("JNEW\n")
 data=self.readline()
 #Victor: 200 New job created: jobid: 2 groupid: 2.
 jobid=string.atoi(
                           data[
                                 string.find(data,"jobid:")+6 :
string.find(data,"groupid:")
                               ]
                         )
 return jobid

    def job_select(self,jobid):
 self.writeline("JOB " + str(jobid) + "\n")
 self.readline()

    def job_kill(self):
 self.writeline("JKILL\n")
 self.readline()

    def job_delete(self):
 self.writeline("JDELE\n")
 self.readline()

    def job_param_getall(self):
 self.writeline("JPARM\n")
 self.readline()
 data=""
 while 1:
     line=self.readline()
     if line[:4]=="217 ": break
     data=data + line
 return data

    def job_param_get(self,pname):
 self.writeline("JPARM " + pname + "\n")
 data=""
 while 1:
     line = self.readline()
     data = data + line[4:]
     if line[3]==" ": break
 return string.strip(data)

    def job_param_set(self,pname,pvalue):
 self.writeline("JPARM " + pname + " " + pvalue +"\n")
 self.readline()

    def getfolder(self,folder):
 self.writeline("PASV\n")
 data=self.readline()
 #print data
 data=data[string.find(data,"(")+1:string.find(data,")")]
 a1,a2,a3,a4,p1,p2=string.split(data,",")
 addr=a1 + "." + a2 + "." + a3 + "." + a4
 port=string.atoi(p1)*256 + string.atoi(p2)
 self.d=socket(AF_INET,SOCK_STREAM)
 self.d.connect(addr,port)
 self.df=self.d.makefile()
 self.writeline("list "+folder+"\n")
 fdata=""
 while 1:
     line=self.df.readline()
     if not line: break
     fdata=fdata + line
 self.df.close()
 self.d.close()
 self.readline()
 self.readline()
 return fdata

    def storefile(self,filename):
 self.writeline("PASV\n")
 data=self.readline()
 #print data
 data=data[string.find(data,"(")+1:string.find(data,")")]
 a1,a2,a3,a4,p1,p2=string.split(data,",")
 addr=a1 + "." + a2 + "." + a3 + "." + a4
 port=string.atoi(p1)*256 + string.atoi(p2)
 self.d=socket(AF_INET,SOCK_STREAM)
 self.d.connect(addr,port)
 self.df=self.d.makefile("w")

 self.writeline("STOT\n")
 reply=self.readline()
 sfile=open(filename,"r")
 while 1:
     line=sfile.readline()
     if not line: break
     self.df.write(line)
 sfile.close()
 self.df.close()
 self.d.close()
 self.readline()
 filename=string.split(reply," ")[2]
 return filename

    def retrfile(self,filename,tmpfilename):
 self.writeline("PASV\n")
 data=self.readline()
 #print data
 data=data[string.find(data,"(")+1:string.find(data,")")]
 a1,a2,a3,a4,p1,p2=string.split(data,",")
 addr=a1 + "." + a2 + "." + a3 + "." + a4
 port=string.atoi(p1)*256 + string.atoi(p2)
 self.d=socket(AF_INET,SOCK_STREAM)
 self.d.connect(addr,port)
 self.df=self.d.makefile("rb")

 self.writeline("RETR " + filename + "\n")
 reply=self.readline()
 sfile=open(tmpfilename,"wb")
 line=self.df.read()
 #while 1:
 #    line=self.df.readline()
 #    if not line: break
 #    sfile.write(line)
 sfile.write(line)
 sfile.close()
 self.df.close()
 self.d.close()
 self.readline()
 return reply

    def deletefile(self,name):
 self.writeline("DELE " + name + "\n")
 self.readline()

    def jobparam(self,param):
 self.writeline("JPARM " + param+"\n")
 self.readline()

    def submitjob(self):
 self.writeline("JSUBM\n")
 self.readline()

    def docmd(self,cmd):
 self.writeline(cmd+"\n")
 self.readline()

    def close(self):
 self.sf.close()
 self.s.close()

    def setdebuginfo(self,dbglevel,logfile):
 self.debuglevel=dbglevel
 self.logfile=logfile

    def loginfo(self,info):
 if self.debuglevel>0:
     f=open(self.logfile,"a")
     f.write(info+"\r\n")
     f.close

if __name__=="__main__":
    host="127.0.0.1"
    if len(sys.argv)>1:
 listdir=sys.argv[1]
    else:
 listdir="/"
    test=hfax()
    test.connect(host,"root")
    print test.getfolder(listdir)
    test.close()






____________________ HylaFAX(tm) Users Mailing List _______________________
 To unsub: mail -s unsubscribe hylafax-users-request@hylafax.org < /dev/null



Home
Report any problems to webmaster@hylafax.org

HylaFAX is a trademark of Silicon Graphics Corporation.
Internet connectivity for hylafax.org is provided by:
VirtuALL Private Host Services