ftplib acting weird

2007-05-04 Thread Merrigan
Hi All,

I have written a little script to upload some files to an ftp folder.
The problem is as follows :

I wrote the script on my windows laptop, and I want to run it from
mylinux server. Everything worked fine so I uploaded it to my linux
machine. Every time I tun the script I get the following error:

***

[EMAIL PROTECTED] ftpsync]# python ftpsync.py
!!
The Connection to the Server Could not be established.
Please Check all neccesary settings and run the script again.
Thank you
!!
Traceback (most recent call last):
  File "ftpsync.py", line 194, in ?
ftplisting()
  File "ftpsync.py", line 83, in ftplisting
ftpconn.cwd(remotedir) #This changes to the remote directory
  File "/usr/lib64/python2.4/ftplib.py", line 494, in cwd
return self.voidcmd(cmd)
  File "/usr/lib64/python2.4/ftplib.py", line 245, in voidcmd
self.putcmd(cmd)
  File "/usr/lib64/python2.4/ftplib.py", line 175, in putcmd
self.putline(line)
  File "/usr/lib64/python2.4/ftplib.py", line 170, in putline
self.sock.sendall(line)
AttributeError: 'NoneType' object has no attribute 'sendall'
[EMAIL PROTECTED] ftpsync]#

***

When I copy the same piece of scripting and run it from the python
command shell, it works...

what am I doing wrong? I have double checked everything about a
million times, but to no avail.

Blessings!

-- 
http://mail.python.org/mailman/listinfo/python-list


progress

2007-05-05 Thread Merrigan
Hi All,

I have posted yesterday about an ftplib issue, this has been resolved.

I actually want to ask something here...

The script that that ftplib error was from...I was wondering - What do
I need to do to print the stats (speed/s, percentage done) of the
upload that is running on the monitor.

This script runs on a Fedora Machine.

Thanx for the help guys!

 -- Merrigan

-- 
http://mail.python.org/mailman/listinfo/python-list


long lists

2007-05-07 Thread Merrigan
Hi All,

Firstly - thank you Sean for the help and the guideline to get the
size comparison, I will definitely look into this.

At the moment I actually have 2 bigger issues that needs sorting...

1. I have the script popping all the files that need to be checked
into a list, and have it parsing the list for everything...Now the
problem is this : The sever needs to check (at the moment) 375 files
and eliminate those that don't need reuploading. This number will
obviously get bigger and bigger as more files gets uploaded. Now, the
problem that I'm having is that the script is taking forever to parse
the list and give the final result. How can I speed this up?

2. This issue is actually because of the first one. While the script
is parsing the lists and files, the connection to the ftp server times
out, and I honestly must say that is is quite annoying. I know I can
set the function to reconnect if it cannot find a connection, but
wouldn't it just be easier just to keep the connection alive? Any idea
how I can keep the connection alive?

Thanks for all the help folks, I really appreciate it!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: long lists

2007-05-07 Thread Merrigan
On May 7, 10:18 am, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> On Mon, 07 May 2007 00:28:14 -0700, Merrigan wrote:
> > 1. I have the script popping all the files that need to be checked into
> > a list, and have it parsing the list for everything...Now the problem is
> > this : The sever needs to check (at the moment) 375 files and eliminate
> > those that don't need reuploading. This number will obviously get bigger
> > and bigger as more files gets uploaded. Now, the problem that I'm having
> > is that the script is taking forever to parse the list and give the
> > final result. How can I speed this up?
>
> By writing faster code???
>
> It's really hard to answer this without more information. In particular:
>
> - what's the format of the list and how do you parse it?
>
> - how does the script decide what files need uploading?
>
> --
> Steven.

Hi, Thanx for the reply,

The Script it available at this url : http://www.lewendewoord.co.za/theScript.py

P.S. I know it looks like crap, but I'm a n00b, and not yet through
the OOP part of the tutorial.

Thanx in advance!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: long lists

2007-05-08 Thread Merrigan
On May 7, 10:21 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Mon, 07 May 2007 09:14:34 -0300, Merrigan <[EMAIL PROTECTED]>
> escribió:
>
> > The Script it available at this url :
> >http://www.lewendewoord.co.za/theScript.py
>
> I understand this as a learning exercise, since there are lot of utilities
> for remote syncing.
>
> Some comments:
> - use os.path.join to build file paths, instead of concatenating strings.
> - instead of reassigning sys.stdout before the call to retrlines, use the
> callback:
>
>  saveinfo = sys.stdout
>  fsock = open(tempDir + "remotelist.txt", "a")
>  sys.stdout = fsock
>  ftpconn.cwd(remotedir) #This changes to the remote directory
>  ftpconn.retrlines("LIST") #This gets a complete list of everything in
> the directory
>  sys.stdout = saveinfo
>  fsock.close()
>
> becomes:
>
>  fsock = open(os.path.join(tempDir,"remotelist.txt"), "a")
>  ftpconn.cwd(remotedir) #This changes to the remote directory
>  ftpconn.retrlines("LIST", fsock.write) #This gets a complete list of
> everything in the directory
>  fsock.close()
>  (Why mode="a"? Shouldn't it be "w"? Isn't the listing for a single
> directory?)
>
> - Saving both file lists may be useful, but why do you read them again? If
> you already have a list of local filenames and remote filenames, why read
> them from the saved copy?
> - It's very confusing having "filenames" ending with "\n" - strip that as
> you read it. You can use fname = fname.rstrip()
> - If you are interested on filenames with a certain extension, only
> process those files. That is, filter them *before* the processing begins.
>
> - The time-consuming part appears to be this:
>
> def comp_are():
>  global toup
>  temptoup = []
>  for file1 in remotefiles:
>  a = file1
>  for file2 in localfiles:
>  b = file2
>  if str(a) == str(b):
>  pass
>  if str(b) != str(a):
>  temptoup.append(str(str(b)))
>  toup = list(sets.Set(temptoup))
>  for filename in remotefiles:
>  fn2up = filename
>  for item in toup:
>  if fn2up == item:
>  toup.remove(item)
>  else:
>  pass
>  toup.sort()
>
> (It's mostly nonsense... what do you expect from str(str(b)) different
>  from str(b)? and the next line is just a waste of time, can you see why?)
> I think you want to compare two lists of filenames, and keep the elements
> that are on one "localfiles" list but not on the other. As you appear to
> know about sets: it's the set difference between "localfiles" and
> "remotefiles". Keeping the same "globalish" thing:
>
> def comp_are():
>  global toup
>  toup = list(sets.Set(localfiles) - sets.Set(remotefiles))
>  toup.sort()
>
> Since Python 2.4, set is a builtin type, and you have sorted(), so you
> could write:
>
> def comp_are():
>  global toup
>  toup = sorted(set(localfiles) - set(remotefiles))
>
> - Functions may have parameters and return useful things :)
> That is, you may write, by example:
>
>remotefiles = getRemoteFiles(host, remotedir)
>localfiles = getLocalFiles(localdir)
>newfiles = findNewFiles(localfiles, remotefiles)
>uploadFiles(host, newfiles)
>
> --
> Gabriel Genellina

Hmmm, thanks a lot. This has really been helpful. I have tried putting
it in the set, and whoops, it workes. Now, I think I need to start
learning some more.

now the script is running a lot slower...
Now to get the rest of it up and running...

Thanx for the help!

-- 
http://mail.python.org/mailman/listinfo/python-list


E-Mail Parsing

2007-12-12 Thread Merrigan
Hi There,

I am writing a script to administer my E-Mail Server. The One thing
I'm currently struggling with is kind of Parsing the E-Mail adress
that I supply to the script.

I need to get the username (The part BEFORE the @ sign) out of the
address so that I can use it elsewhere. The problem I have with this
is that both the domain, and the username are variable lenghts and
that I have no idea how to split the two parts.

Is there any way that I can do this?

Thank ye very much.

 -- Merrigan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: E-Mail Parsing

2007-12-13 Thread Merrigan
On Dec 13, 9:29 am, Matt Nordhoff <[EMAIL PROTECTED]> wrote:
> Merrigan wrote:
> > I am writing a script to administer my E-Mail Server. The One thing
> > I'm currently struggling with is kind of Parsing the E-Mail adress
> > that I supply to the script.
>
> > I need to get the username (The part BEFORE the @ sign) out of the
> > address so that I can use it elsewhere. The problem I have with this
> > is that both the domain, and the username are variable lenghts and
> > that I have no idea how to split the two parts.
>
> > Is there any way that I can do this?
>
> > Thank ye very much.
> >>> addr = "[EMAIL PROTECTED]"
> >>> addr.split("@")
>
> ['user', 'example.com']
>
> If it's formatted like a To header ("User <[EMAIL PROTECTED]>"), use
> email.Utils.parseaddr() to get the address out of it.\
>
> The email modules might help you a lot:
>
> <http://docs.python.org/lib/module-email.html>
> --

Hi Matt,

Thank you very much for the help. It was exactly what I was looking
for, and made my script much safer and easier to use.

Blessings!

 -- Merrigan
-- 
http://mail.python.org/mailman/listinfo/python-list


Data Manipulation?

2007-12-13 Thread Merrigan
Hi There,

I Posted a while ago about a challenge I had in splitting an E-Mail
adress up to use it. Anyways, the same script but different issue.
Some Background:

The script is going to be used to manage a Virtual User Based E-Mail
system. Now the part I'm struggling with is to delete the E-Mail
address from the database, and then giving the user the option to
DELETE and/or modify any E-Mail Aliases associated to the Deleted E-
Mail Address.

The delete code up to this stage only gives me a list of associated
Aliases:

def delUser():
conn_db()
use = "USE %s" % mysql_db
db_cursor.execute(use)
print "DATABASE ONLINE"
e_mail = raw_input("Please Provide a the E-Mail Address you wish to
Delete: ")
del_statement = "DELETE FROM users WHERE email = '%s';" % e_mail
db_cursor.execute(del_statement)
un_dom = e_mail.split("@")
username = un_dom[0]
domain = un_dom[1]
domdir = maildir + '%s' % domain
os.rmdir(domdir + '/' + username + '/' + 'cur')
os.rmdir(domdir + '/' + username + '/' + 'new')
os.rmdir(domdir + '/' + username + '/' + 'tmp')
os.rmdir(domdir + '/' + username)
print "User Removed from Database. Now Proceding To associated E-Mail
Aliases"
select_statement = "SELECT source, destination FROM mail.forwardings
WHERE destination = '%s'" % e_mail
result = db_cursor.execute(select_statement)
if result >= 1:
aliasLine = 0
number = result - 1
while aliasLine <= number:
db_cursor.execute(select_statement)
answer = db_cursor.fetchall()
answer_1 = answer[aliasLine]
aliasLine = aliasLine + 1
print '%s is still linked to %s, do you wish to remove 
the E-Mail
Alias?' % (answer_1[0], answer_1[1])

How can I now get this to give me the options to delete an adress, or
everything, or delete one and modify the rest...or all that you
know...

Thank ye once again, This group rocks!

 -- Merrigan
-- 
http://mail.python.org/mailman/listinfo/python-list


making all letters Caps/Small Letters

2007-12-14 Thread Merrigan
Hi There,

I'm sure I have done this before, but cannot remember how, or find out
how to do it quickly - but is there a way/function/something in python
to make all the letters of a raw_input() string small/capital letters?

Thanks!

 -- Merrigan
-- 
http://mail.python.org/mailman/listinfo/python-list


DB Query Parse Hangup

2007-12-14 Thread Merrigan
Hi There,

I have been working on this script, and the part that this issue that
I have occurs in is when iterating through some results from the db,
asking the admin input to delete the entry or not - everything works
fine up until the last entry, then it bombs out. I know why - but I am
not quite sure how to fix it:

The Code:

select_statement = "SELECT source, destination FROM mail.forwardings
WHERE destination = '%s'" % e_mail

result = db_cursor.execute(select_statement)
if result >= 1:
aliasLine = 0
number = result - 1
while aliasLine <= number:
db_cursor.execute(select_statement)
answer = db_cursor.fetchall()
answer_1 = answer[aliasLine]
aliasLine = aliasLine + 1
print '%s is still linked to %s.' % (answer_1[0], 
answer_1[1])
#to_edit = raw_input("Please provide one of the above 
mentioned E-
Mail Aliases to edit: ")
to_do = str.lower(raw_input("Would you like to 
Delete(D) or
Modify(M) the alias? [D/M] "))
delete = 'd'
modify = 'm'
if to_do == delete:
del_statement = "DELETE FROM forwardings WHERE 
source = '%s'" %
answer_1[0]
db_cursor.execute(del_statement)
print "Alias '%s', has been successfully 
deleted." % answer_1[0]
elif to_do == modify:
    print "WILL BE MODIFIED"

any help will be much appreciated.

Thank you!
 -- Merrigan
-- 
http://mail.python.org/mailman/listinfo/python-list


How do I take a directory name from a given dir?

2006-05-01 Thread Merrigan
Hi,

I am trying to write a script to backup all my company's server configs
weekly. The script will run in a cronjob, on whatever I set it.

The issue I am currently having isto "extract" the directory name from
a given directory string. For example: from the string
"/home/testuser/projects/" I need to extract the "projects" part. The
problem is that the directory names that needs to be used will never be
the same lenght, so as far as my (very limited) knowledge stretches,
slicing and indicing is out of the question.

Can anybody help me, or give me an idea of what I should look at,
seeing as I'm seriously stuck. I only started coding at the beginnig of
the year, and was never interested before that, so my knowlege is
basically non-existent.

Thanks in advance for the help :)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I take a directory name from a given dir?

2006-05-01 Thread Merrigan
WOW, Thanks guys. I am really awestruck by the speed you guys relied
with. Thanks a lot for the help. I eventually found a way that did the
job for me.

I will definitely visit this Group more often.

Thanks for all the help! :D

-- 
http://mail.python.org/mailman/listinfo/python-list


Sending mail with attachment...

2006-05-13 Thread Merrigan
Hi,

I have now eventually finished my newbie-backup script and I'm very
proud of the way it functions...

Anyways, I am looking for an easy way to use smtplib to send an email
with the output log of the script to multiple accounts. I need to use
it with a smtp server, and cannot pipe it directly to sendmail.

I have tried about 50 different ways that I have googled for in the
last 6 hours, but none of them work, I keep on getting errors.

The script runs on a Linux system.

Thanks for any help.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sending mail with attachment...

2006-05-13 Thread Merrigan
Hi Guys,

I just wanted to post the error, and then also the coda that causes
itI get this no matter what I do to this, and I don't understand
it. Any help would be welcome. Thank you

Error
::
Traceback (most recent call last):
  File "/home/merrigan/projects/Backup Script/hobbitarchive.py", line
113, in ?
mailSender()
  File "/home/merrigan/projects/Backup Script/hobbitarchive.py", line
74, in mailSender
s.sendmail(fromaddy, recievelist, mesg.as_string())
  File "/usr/lib/python2.4/email/Message.py", line 129, in as_string
g.flatten(self, unixfrom=unixfrom)
  File "/usr/lib/python2.4/email/Generator.py", line 82, in flatten
self._write(msg)
  File "/usr/lib/python2.4/email/Generator.py", line 120, in _write
self._write_headers(msg)
  File "/usr/lib/python2.4/email/Generator.py", line 166, in
_write_headers
header_name=h, continuation_ws='\t').encode()
  File "/usr/lib/python2.4/email/Header.py", line 395, in encode
return self._encode_chunks(newchunks, maxlinelen)
  File "/usr/lib/python2.4/email/Header.py", line 355, in
_encode_chunks
_max_append(chunks, s, maxlinelen, extra)
  File "/usr/lib/python2.4/email/quopriMIME.py", line 79, in
_max_append
L.append(s.lstrip())
AttributeError: 'list' object has no attribute 'lstrip'

::

Code
::
def mailSender():
openlogmsg = open(completelog, 'rb')
mesg = MIMEText(openlogmsg.read())
openlogmsg.close()
mesg['Subject'] = subject
mesg['From'] = fromaddy
mesg['To'] = recievelist
s = smtplib.SMTP(smtpserver)
#   s.connect(smtpserver)
s.sendmail(fromaddy, recievelist, mesg.as_string())
s.quit()

::

Thanks a lot :)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I take a directory name from a given dir?

2006-05-01 Thread Merrigan Took
Daniel Nogradi wrote:
>> Hi,
>>
>> I am trying to write a script to backup all my company's server configs
>> weekly. The script will run in a cronjob, on whatever I set it.
>>
>> The issue I am currently having isto "extract" the directory name from
>> a given directory string. For example: from the string
>> "/home/testuser/projects/" I need to extract the "projects" part. The
>> problem is that the directory names that needs to be used will never be
>> the same lenght, so as far as my (very limited) knowledge stretches,
>> slicing and indicing is out of the question.
>>
>> Can anybody help me, or give me an idea of what I should look at,
>> seeing as I'm seriously stuck. I only started coding at the beginnig of
>> the year, and was never interested before that, so my knowlege is
>> basically non-existent.
> 
> You can try this:
> 
 '/home/testuser/projects/'.strip( '/' ).split( '/' )
> ['home', 'testuser', 'projects']
> 
> strip gets rid of the first and last / and split splits the remaining
> part and puts the results into a list.
> 
> HTH :)
h, ok, Thank you, I will definitely look into this and play with it!
-- 
http://mail.python.org/mailman/listinfo/python-list