Ejemplo n.º 1
0
def parse_args():
    description='Silly Server for mocking real http servers'
    options = [
        {
            "dest": "root_dir",
            "required": False,
            "metavar": "/dir/somedir",
            "help": """Directory where your fake responses are waiting for me.
            If not provided - default response will be used everywhere.""",
            "type": str,
            "key": "-d",
        }, 
        {
            "dest": "port",
            "required": False,
            "metavar": "port",
            "help": "Port to listen on. Default is 8000.",
            "type": int,
            "key": "-p"
        }
    ]
    try:
        import argparse
        parser = argparse.ArgumentParser(description=description)
        for o in options:
            parser.add_argument(o["key"], dest=o["dest"], required=o["required"], metavar=o["metavar"],
                                help=o["help"], type=o["type"])
        return vars(parser.parse_args())
    except ImportError:
        import optparse
        parser = optparse.OptionParser(description=description)
        for o in options:
            parser.add_option(o["key"], dest=o["dest"], metavar=o["metavar"],
                              help=o["help"], type=o["type"])
        return vars(parser.parse_args()[0])
Ejemplo n.º 2
0
def jobParseArgs(args):
    parser = OptionParser()
    parser.add_option("-j", dest="jobid", type="str")
    (opts, args) = parser.parse_args(args)

    opts = parseTaskFile(opts.jobid)
    return opts
 def run(cls):
     parser = argparse.ArgumentParser(description='Adjust the file modification dates of OS X Mail.app .emlx files to match the date in their headers.')
     parser.add_argument('mailroot', nargs='?', default='~/Library/Mail/V2/', help='Toplevel directory in which .emlx files should be changed. Defaults to ~/Library/Mail/V2')
     parser.add_argument('--dry-run', help='Dry run, list the affected files only', action='store_true')
     parser.add_argument('--verbose', help='Log debug output', action='store_true')
     args = parser.parse_args()
     Tool(args.mailroot, args.verbose).adjust_dates(dry_run=args.dry_run)
Ejemplo n.º 4
0
def get_arguments():
    # Get arguments and create link to server
    from optparse import OptionParser
    parser = OptionParser(usage="%prog [options] <mailboxname> [<mailboxname> ...]")
    parser.add_option("-s", "--server",dest='server',help='IMAP server')
    parser.add_option("-p", "--port",  dest='port',  help='IMAP server port', type='int')
    parser.add_option("-x", "--ssl",   dest='ssl',   action="store_true", help='Use SSL')
    parser.add_option("-u", "--user",  dest='user',  help='IMAP user name')
    parser.add_option("-w", "--password", dest='password',  help='IMAP password (Will prompt if not specified)')
    parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="Verbose mode")
    parser.add_option("-n", "--dry-run", dest="dry_run", action="store_true", 
                        help="Don't actually do anything, just report what would be done")
    parser.add_option("-c", "--checksum", dest="use_checksum", action="store_true", 
                        help="Use a checksum of several mail headers, instead of the Message-ID")
    parser.add_option("-m", "--checksum-with-id", dest="use_id_in_checksum", action="store_true", 
                        help="Include the Message-ID (if any) in the -c checksum.")
    parser.add_option("-l", "--list", dest="just_list", action="store_true", 
                                            help="Just list mailboxes")

    parser.set_defaults(verbose=False, ssl=False, dry_run=False, just_list=False)
    (options, args) = parser.parse_args()
    if (not options.server) or (not options.user):
        sys.stderr.write("\nError: Must specify server, user, password and at least one mailbox.\n\n")
        parser.print_help()
        sys.exit(1)
    if not options.password:
        options.password = getpass.getpass()

    return (options, args)
Ejemplo n.º 5
0
    def main(self):
        """Invoke dkms-info."""
        parser = argparse.ArgumentParser()
        parser.add_argument('--format',
                            default="onelines",
                            choices=["summary", "json"],
                            help=("Choose output format type: "
                                  "summary (one line per packages) "
                                  "or json (json format, fully information)"))
        parser.add_argument('--output',
                            default=None,
                            help=("Output filename to store the output date"))
        args = parser.parse_args()

        logging.basicConfig(level=logging.INFO,
                            format='[%(relativeCreated)06dms] %(message)s')
        _logger.info("Started")

        dkms_pkgs = []
        for (dkms_name, dkms_ver) in get_installed_dkms_modules():
            dkms_pkg = DkmsPackage(dkms_name, dkms_ver)
            dkms_pkgs.append(dkms_pkg)

        output = sys.stdout
        if args.output is not None:
            output = open(args.output, 'wt', encoding='UTF-8')

        pkg_handler = DebianPackageHandler(extra_pkgs=dkms_pkgs)
        if args.format == "summary":
            output.write(pkg_handler.to_outline())
        else:
            output.write(pkg_handler.to_json())
        _logger.info("Data collected")
Ejemplo n.º 6
0
def main():
    global CONFIG
    parser = argparse.ArgumentParser()
    parser.add_argument('configfile', help='path to config file')
    options = parser.parse_args()
    config = ConfigParser()
    config.read(options.configfile)
    CONFIG = config['default']
    logging.basicConfig(stream=sys.stdout,
                        format=LOG_FORMAT,
                        level=CONFIG.get('loglevel', 'WARNING'))

    msg = create_message()
    try:
        send(msg)
    except Exception:
        log.info('SMTP error, aborting', exc_info=True)
        return 1

    waited = 0
    interval = int(CONFIG.get('poll_interval', 10))
    timeout = int(CONFIG.get('poll_timeout', 60))
    while waited < timeout:
        time.sleep(interval)
        waited += interval
        try:
            if check_received(msg['X-Mailcheck-Token']):
                return 0
        except Exception:
            log.info('IMAP error, aborting', exc_info=True)
            return 1
        log.info('IMAP not found, retrying in %s', interval)
    log.info('IMAP not found after %s, giving up', timeout)
    return 2
Ejemplo n.º 7
0
def parse_args():
  parser = argparse.ArgumentParser()
  parser.add_argument('host_and_port', help='The IMAP4 host name and '
    'port number in the format <host>:<port>. If the :<port> part is '
    'omitted, the default port of 993 is used.')
  parser.add_argument('user', help='The username to log in with.')
  parser.add_argument('passwd', nargs='?', help='The password for '
    'login. If omitted, the password is requested via the terminal.')
  parser.add_argument('--mailbox', default='INBOX', help='Select the name '
    'of the mailbox to read the mails from. Default is INBOX.')
  parser.add_argument('--sender', help='Only accept emails from the '
    'specified email address. Otherwise, all mails will be accepted.')
  parser.add_argument('--filter-title', help='IMAP subject filter string.')
  parser.add_argument('--interval', type=int, default=5, help='The interval '
    'to check for new mail in seconds. Defaults to 5.')
  parser.add_argument('--list-mailboxes', action='store_true',
    help='List the mailboxes and exit.')
  parser.add_argument('--scale-pdf', type=float, default=1.0,
    help='The anmount by which PDF files should be scaled. Defaults to 1.')
  args = parser.parse_args()
  args.host, args.port = args.host_and_port.partition(':')[::2]
  if args.port:
    try:
      args.port = int(args.port)
    except ValueError:
      parser.error('invalid port')
  if args.interval < 1:
    parser.error('interval must be >= 1')
  return args
Ejemplo n.º 8
0
def parse_args(args: Optional[List[str]]) -> argparse.Namespace:
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "package_names",
        metavar="PACKAGE",
        nargs="+",
        type=packaging.utils.canonicalize_name,
    )
    parser.add_argument(
        "--python-version",
        dest="python_version",
        type=_parse_python_version,
        default=".".join(str(v) for v in sys.version_info[:2]),
    )
    parser.add_argument(
        "--interpreter", default=None,
    )
    parser.add_argument(
        "--platform", dest="platforms", action="append", default=None,
    )
    parser.add_argument(
        "--output", type=_parse_output_path, required=True,
    )
    parser.add_argument(
        "--overwrite", action="store_true", default=False,
    )
    return parser.parse_args(args)
Ejemplo n.º 9
0
def jobParseArgs (args):
  parser = OptionParser()
  parser.add_option("-j", dest="jobid", type="str")
  (opts, args) = parser.parse_args(args)

  opts = parseTaskFile(opts.jobid)
  return opts
Ejemplo n.º 10
0
def process_arguments():
    """ Process command line arguments """
    parser = argparse.ArgumentParser(description="Enron Corpus Parser")
    parser.add_argument("-w",
                        "--whitelist",
                        help='path to e-mail whitelist',
                        type=argparse.FileType('r'),
                        required=True)
    parser.add_argument("-o",
                        "--output",
                        help='path to output file',
                        type=argparse.FileType('w'),
                        required=True)
    parser.add_argument("-p",
                        "--path",
                        help='path to Enron corpus',
                        required=True)
    parser.add_argument("-s",
                        "--sent",
                        help="only parse sent message folders",
                        action="store_true")
    parser.add_argument("-v",
                        "--verbose",
                        help="increase output verbosity",
                        action="store_true")
    return parser.parse_args()
Ejemplo n.º 11
0
 def parse_command_line(self):
     epilog = 'Latest version: <{url}>\n\nLicense: {license}'.format(
                                                 url=url, license=license)
     parser = argparse.ArgumentParser(prog=name, description=description, 
         epilog=epilog, formatter_class=argparse.RawDescriptionHelpFormatter)
     parser.add_argument('-V', '--version', action='version', 
                         version='{} v{}'.format(name, version))
     parser.add_argument('-v', '--verbose', action='store_true', 
                         help='show detailed info')
     parser.add_argument('-s', '--settings', 
                         help='specify a custom settings file path')
     parser.add_argument('-p', '--profile', 
                         help='choose a profile from the settings file')
     parser.add_argument('-u', '--user', help='specify the user')
     parser.add_argument('-x', '--pass', help='specify the password', 
                         dest='pass_', metavar='PASS')
     args = parser.parse_args()
     self.read_config(args.settings)
     self.config['general']['verbose'] = str(args.verbose or __debug__)
     if args.profile is not None:
         self.config['general']['profile'] = args.profile
         self.profile = self.config[args.profile]
     if args.user is not None:
         self.profile['user_id'] = args.user
     if args.pass_ is not None:
         self.profile['password'] = args.pass_
Ejemplo n.º 12
0
def options_and_logging():
    """Handle command line options and start logging
    Args:
        None
    """
    from optparse import OptionParser
    parser = OptionParser(version="%%prog v%s" % __version__,
            usage="%prog [options] <argument> ...",
            description=__doc__.replace('\r\n', '\n').split('\n--snip--\n')[0])
    parser.add_option('-v', '--verbose', action="count", dest="verbose",
        default=2, help="Increase the verbosity. Use twice for extra effect")
    parser.add_option('-q', '--quiet', action="count", dest="quiet",
        default=0, help="Decrease the verbosity. Use twice for extra effect")
    #Reminder: %default can be used in help strings.
 
    # Allow pre-formatted descriptions
    parser.formatter.format_description = lambda description: description
 
    opts, args  = parser.parse_args()

    # Set up clean logging to stderr
    log_levels = [logging.CRITICAL, logging.ERROR, logging.WARNING,
                  logging.INFO, logging.DEBUG]
    opts.verbose = min(opts.verbose - opts.quiet, len(log_levels) - 1)
    opts.verbose = max(opts.verbose, 0)
    logging.basicConfig(level=log_levels[opts.verbose],
                        format='%(levelname)s: %(message)s')
Ejemplo n.º 13
0
def process_arguments():
    """ Process command line arguments """
    parser = argparse.ArgumentParser(description="Enron Corpus Parser")
    parser.add_argument("-a", "--aliases", help='Path to Alias file',
                        type=argparse.FileType('r'), required=True)
    parser.add_argument("-p", "--path", help='Path to Enron corpus',
                        required=True)
    return parser.parse_args()
Ejemplo n.º 14
0
def main():
   description = '指定邮箱的所有邮件附件存储到指定目录里。'
   parser = argparse.ArgumentParser(description=description)
   parser.add_argument('-d','--directory',default='./attachment',help='指定目录[缺省目录是:./attachment]')
   parser.add_argument('-i','--interactive',help='交互式方法')
   parser.add_argument('-f','--file',help='电邮和密码在指定配置文件里')
   args = parser.parse_args()
   # print(args.directory,args.email,args.password)
   getEmailattachment(args.password,args.email,args.directory)
Ejemplo n.º 15
0
def main():
    from ..jobs import setup_logger

    args = parser.parse_args()
    setup_logger(logfile=args.logfile, log_level=args.loglevel)

    headers, params = _collect_headers(args.header), _collect_params(args.param)

    return esri2geojson(args.esri_url, args.geojson_path, headers, params)
Ejemplo n.º 16
0
def main():
    """Parse command-line arguments and invoke the RemoveAttachments program class."""
    parser = OptionParser()
    parser.add_option("-s", "--server", help="IMAP4 server")
    parser.add_option("--port", help="IMAP4 server port")
    parser.add_option("--ssl", help="Use SSL connectivity", action="store_true")
    parser.add_option("-u", "--username", help="IMAP4 username")
    parser.add_option("-p", "--password", help="IMAP4 password")
    parser.add_option("--only-mailbox", help="Specify a single mailbox to process (default: all, recursive)")
    parser.add_option("--couchdb-server", help="CouchDB server address")
    parser.add_option("--couchdb-db", help="CouchDB database name (default: attachments)")
    parser.add_option("--before-date",
                      help="Only check messages sent before this date (format YYYY-MM-DD)")
    parser.add_option("--min-size", default=5000,
                      help="Ignore mails smaller than this size, in kB [%default]")
    parser.add_option("-r", "--remove", help="Remove attachments after processing", action="store_true")
    parser.add_option("--eat-more-attachments", help="Use looser criteria for detecting attachments",
                      action="store_true")
    parser.add_option("--gmail", help="Enable Gmail quirks mode (see README) (default off)",
                      action="store_true")
    parser.add_option("-v", "--verbose", help="Log debug messages", action="store_true")
    options = parser.parse_args()[0]

    if options.verbose:
        logging.getLogger().setLevel(logging.DEBUG)

    if options.before_date is not None:
        before_date = parse_date(options.before_date)
    else:
        before_date = None

    if options.min_size is not None:
        try:
            min_size = int(options.min_size)
        except ValueError:
            die("--min-size requires integer argument")
    else:
        min_size = 0

    if options.port is not None:
        try:
            port = int(options.port)
        except ValueError:
            die("--port requires integer argument")
    else:
        if options.ssl:
            port = 993
        else:
            port = 143

    try:
        RemoveAttachments(options.server, port, options.ssl, options.username, options.password,
                          options.only_mailbox, options.couchdb_server, options.couchdb_db, options.remove,
                          options.eat_more_attachments, options.gmail, min_size, before_date).run()
    except RemoveAttachmentsException, e:
        logging.error(e)
        sys.exit(1)
Ejemplo n.º 17
0
Archivo: gmute.py Proyecto: cdown/gmute
def parse_args():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument(
        "-n",
        "--dry-run",
        action="store_true",
        help="print what we would do, but don't actually mute the messages",
    )
    return parser.parse_args()
Ejemplo n.º 18
0
def _parse_args(args):
    parser = argparse.ArgumentParser(
        description="Convert a single Esri feature service URL to GeoJSON")
    parser.add_argument("url", help="Esri layer URL")
    parser.add_argument("outfile",
                        type=argparse.FileType('w'),
                        help="Output file name (use - for stdout)")
    parser.add_argument(
        "--jsonlines",
        action='store_true',
        default=False,
        help=
        "Output newline-delimited GeoJSON Features instead of a FeatureCollection"
    )
    parser.add_argument("-v",
                        "--verbose",
                        action='store_const',
                        dest='loglevel',
                        const=logging.DEBUG,
                        default=logging.INFO,
                        help="Turn on verbose logging")
    parser.add_argument("-q",
                        "--quiet",
                        action='store_const',
                        dest='loglevel',
                        const=logging.WARNING,
                        default=logging.INFO,
                        help="Turn off most logging")
    parser.add_argument(
        "-f",
        "--fields",
        help=
        "Specify a comma-separated list of fields to request from the server")
    parser.add_argument(
        "--no-geometry",
        dest='request_geometry',
        action='store_false',
        default=True,
        help=
        "Don't request geometry for the feature so the server returns attributes only"
    )
    parser.add_argument(
        "-H",
        "--header",
        action='append',
        dest='headers',
        default=[],
        help="Add an HTTP header to send when requesting from Esri server")
    parser.add_argument(
        "-p",
        "--param",
        action='append',
        dest='params',
        default=[],
        help="Add a URL parameter to send when requesting from Esri server")

    return parser.parse_args(args)
Ejemplo n.º 19
0
def parse_arguments():
    from optparse import OptionParser
    parser = OptionParser('usage: %prog [options] db-file')
    parser.add_option("-v", "--verbose", dest="verbose",
            default=False, help="verbose")
    (options, args) = parser.parse_args()
    if len(args) != 1:
        parser.error('db-file argument is required')

    return {'file': args[0], 'verbose':options.verbose}
Ejemplo n.º 20
0
def main():
    from ..jobs import setup_logger

    args = parser.parse_args()
    setup_logger(logfile=args.logfile, log_level=args.loglevel)

    headers, params = _collect_headers(args.header), _collect_params(
        args.param)

    return esri2geojson(args.esri_url, args.geojson_path, headers, params)
Ejemplo n.º 21
0
def main():
    description = ("Parse an e-mail from STDIN and add a task to Things with "
                   "message details in the note")
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument("-q",
                        action="store_true",
                        help="Use the quick entry window")
    args = parser.parse_args()

    title, note = parse_message(sys.stdin.read())
    send_to_omnifocus(title=title, note=note, quickentry=args.q)
Ejemplo n.º 22
0
def main():

    # handle args

    parser = argparse.ArgumentParser(description='Parse Enron emails into structured csv')
    parser.add_argument('outfile', type=str, help='name of output file')
    parser.add_argument('--rootdir', type=str, default='.', help='path to the maildir')

    args = parser.parse_args()

    process_mails(args.outfile, args.rootdir)
Ejemplo n.º 23
0
def get_arguments():

    from optparse import OptionParser
    parser = OptionParser(usage="%prog options ")
    parser.add_option("-f","--config",    dest='config_file',      help='Config File ')
    parser.add_option("-s","--src-server",dest='src_server',help='Source IMAP server')
    parser.add_option("-S","--dst-server",dest='dst_server',help='Destination IMAP server')
    parser.add_option("-p","--src-port",  dest='src_port',  help='Source IMAP server port', type='int')
    parser.add_option("-P","--dst-port",  dest='dst_port',  help='Destination IMAP server port', type='int')
    parser.add_option("-u","--src-user",  dest='src_user',  help='Source IMAP user')
    parser.add_option("-U","--dst-user",  dest='dst_user',  help='Destination IMAP user')
    parser.add_option("-w","--src-password",  dest='src_password',  help='Source IMAP password',type="string")
    parser.add_option("-W","--dst-password",  dest='dst_password',  help='Destination IMAP password',type="string")
    parser.add_option("-x", "--src-ssl",   dest='src_ssl',   action="store_true", help='Use SSL')
    parser.add_option("-X", "--dst-ssl",   dest='dst_ssl',   action="store_true", help='Use SSL')
    parser.add_option("-d","--start-date", dest='start_date',help='Start from date YYYYMMDD ')
    parser.add_option("-D","--end-date"  , dest='end_date',  help='End date YYYYMMDD')
    parser.add_option("-v", "--verbose",   dest="verbose",   action="store_true", help="Verbose mode")
    parser.add_option("-c", "--checksum", dest="use_checksum", action="store_true", 
                        help="Use a checksum of several mail headers, instead of the Message-ID")
    parser.add_option("-m", "--checksum-with-id", dest="use_id_in_checksum", action="store_true", 
                        help="Include the Message-ID (if any) in the -c checksum.")
    parser.add_option("-l", "--list", dest="just_list", action="store_true", 
                                            help="Just list mailboxes on Source Server")

    parser.set_defaults(verbose=False, ssl=False, dry_run=False, just_list=False,src_port=143,dst_port=143)
    (options, args) = parser.parse_args()
  
    config = ConfigParser.ConfigParser()    
    #Load Data from config file
    if options.config_file:
        config.read(options.config_file)
        for a in config.items("IMAPCopy"):
            setattr(options, a[0],a[1])
              
    if (not options.start_date) or (not options.end_date):
            sys.stderr.write("\nError: Must specify Start and End dates. \n")
            parser.print_help()
            sys.exit(1)
         
    
    if options.just_list:
        if (not options.src_server) or (not options.src_user) :
            sys.stderr.write("\nError: Must specify src-server, src-users, src-passwords.\n")
            parser.print_help()
            sys.exit(1)
    else:
        if (not options.src_server) or (not options.dst_server) or (not options.src_user) or (not options.dst_user):
            sys.stderr.write("\nError: Must specify servers, users, passwords .\n\n")
            parser.print_help()
            sys.exit(1)


    return (options, args)
Ejemplo n.º 24
0
def process_arguments():
    """ Process command line arguments """
    parser = argparse.ArgumentParser(description="Enron Corpus Parser")
    parser.add_argument("-p", "--path", help='Path to Enron corpus',
                        required=True)
    parser.add_argument("-u", "--unique", help="Remove Duplicate messages",
                        action="store_true")
    parser.add_argument("-r", "--records", help="Number of records to display",
                        type=int, default=5)
    parser.add_argument("-v", "--verbose", help="increase output verbosity",
                        action="store_true")
    return parser.parse_args()
Ejemplo n.º 25
0
def parse_arguments():
    from optparse import OptionParser
    import getpass
    parser = OptionParser('usage: %prog [options] gmail-username')
    parser.add_option("-f", "--file", dest="file", default="emails.sql",
            help="destination database file [default: %default]")
    (options, args) = parser.parse_args()
    if len(args) != 1:
        parser.error('email argument is required')
    password = getpass.getpass('Password: '******'email':args[0], 'password':password, 'file':options.file}
Ejemplo n.º 26
0
def main():
    parser = OptionParser(usage='usage: firetower options args')
    parser.add_option(
        '-c', '--conf', action='store', dest='conf_path',
         help='Path to YAML configuration file.')
    (options, args) = parser.parse_args()
    conf = config.Config(options.conf_path)

    conn = imaplib.IMAP4_SSL(conf.imap_host)
    imap_user = conf.imap_user

    queue = Redis(host=conf.redis_host, port=conf.redis_port)

    processed = 0

    print "Enter email password"
    imap_password = getpass.getpass()

    conn.login(imap_user, imap_password)
    conn.select("Inbox")

    while True:
        _, msg_ids = conn.search(None, "(ALL)")
        msg_ids = msg_ids[0].split()
        if len(msg_ids) == 0:
            time.sleep(0.5)
            continue
        print "Processing %s messages" %len(msg_ids)

        _, msgs = conn.fetch(",".join(msg_ids), '(BODY[])')
        for msg in msgs:
            if not msg or msg == ")":
                continue
            msg_obj = email.message_from_string(msg[1])
            ft_dict = {}
            ft_dict['hostname'] = msg_obj['Received'].split(' ')[1] if msg_obj['Received'] else '????'
            ft_dict['sig'] = msg_obj.get_payload() or '????'
            ft_dict['date'] = msg_obj["Date"]
            ft_dict['programname'] = 'Maildir Util'

            # We don't huge signatures clogging the classification
            if len(ft_dict['sig']) < 10000 and isinstance(ft_dict['sig'], str):
                queue.push(conf.queue_key, json.dumps(ft_dict))
            processed += 1
            if not processed % 100:
                print "Processed: %s" %processed
        print "Processed: %s" %processed

        for msg_id in msg_ids:
            conn.store(msg_id, '+FLAGS', '\\Deleted')

        conn.expunge()
Ejemplo n.º 27
0
def process_arguments():
    """ Process command line arguments """
    parser = argparse.ArgumentParser(description="Enron Corpus Parser")
    parser.add_argument("-a",
                        "--aliases",
                        help='Path to Alias file',
                        type=argparse.FileType('r'),
                        required=True)
    parser.add_argument("-p",
                        "--path",
                        help='Path to Enron corpus',
                        required=True)
    return parser.parse_args()
Ejemplo n.º 28
0
def main():
    global config

    parser = argparse.ArgumentParser()
    parser.add_argument('--config')
    args = parser.parse_args()

    config = Config(args.config)

    if config['logging']:
        logging.config.dictConfig(config['logging'])

    deliver()
Ejemplo n.º 29
0
def process_arguments():
    """ Process command line arguments """
    parser = argparse.ArgumentParser(description="Enron Corpus Parser")
    parser.add_argument("-a", "--addressbook", help='path to e-mail addressbook',
                        type=argparse.FileType('r'), required=True)
    parser.add_argument("-o", "--output", help='path to output file',
                        type=argparse.FileType('w'), required=True)
    parser.add_argument("-p", "--path", help='path to Enron corpus',
                        required=True)
    parser.add_argument("-s", "--sent", help="only parse sent message folders",
                        action="store_true")
    parser.add_argument("-v", "--verbose", help="increase output verbosity",
                        action="store_true")
    return parser.parse_args()
Ejemplo n.º 30
0
def process_args():
    import argparse

    parser = argparse.ArgumentParser(description='Load emails into Minezy')
    parser.add_argument('-d', '--depot_dir', required=True,
                       help="The [depot_dir] parameter should point to a parent folder of a parsed PST dump (eg: as generated by <a href='http://www.five-ten-sg.com/libpst/rn01re01.html'>readpst</a> tool)")
    parser.add_argument('-n', '--depot_name',  default="Un-named", help='Name of the account')
    parser.add_argument('-p', '--processes', default=8, type=int, help="Number of parallel processes to use to parse emails ")
    parser.add_argument('-v', '--verbose', nargs='?', const=True, default=False, type=bool, help="Print additional progress output")
    opts = neo4jLoader.options()
    parser.add_argument('-l', '--load_options', nargs='*', choices=opts, default=opts, help="Select which email elements to load.")
    parser.add_argument('-s', '--sample', default=1, type=int, help="Use every n-th email from the depot (used for debugging).")

    return parser.parse_args()
Ejemplo n.º 31
0
def _parse_args(args):
    parser = argparse.ArgumentParser(
        description="Convert a single Esri feature service URL to GeoJSON")
    parser.add_argument("url",
        help="Esri layer URL")
    parser.add_argument("outfile",
        type=argparse.FileType('w'),
        help="Output file name (use - for stdout)")
    parser.add_argument("--proxy",
        help="Proxy string to send requests through ie: https://example.com/proxy.ashx?<SERVER>")
    parser.add_argument("--jsonlines",
        action='store_true',
        default=False,
        help="Output newline-delimited GeoJSON Features instead of a FeatureCollection")
    parser.add_argument("-v", "--verbose",
        action='store_const',
        dest='loglevel',
        const=logging.DEBUG,
        default=logging.INFO,
        help="Turn on verbose logging")
    parser.add_argument("-q", "--quiet",
        action='store_const',
        dest='loglevel',
        const=logging.WARNING,
        default=logging.INFO,
        help="Turn off most logging")
    parser.add_argument("-f", "--fields",
        help="Specify a comma-separated list of fields to request from the server")
    parser.add_argument("--no-geometry",
        dest='request_geometry',
        action='store_false',
        default=True,
        help="Don't request geometry for the feature so the server returns attributes only")
    parser.add_argument("-H", "--header",
        action='append',
        dest='headers',
        default=[],
        help="Add an HTTP header to send when requesting from Esri server")
    parser.add_argument("-p", "--param",
        action='append',
        dest='params',
        default=[],
        help="Add a URL parameter to send when requesting from Esri server")
    parser.add_argument("-t", "--timeout",
        type=int,
        default=30,
        help="HTTP timeout in seconds, default 30")

    return parser.parse_args(args)
Ejemplo n.º 32
0
 def parse_cmdline(self):
     parser = optparse.OptionParser()
     parser.add_option("-f", "--filter-address", dest="filter_address", help="Use EMAIL as filter", metavar="EMAIL")
     parser.add_option("-L", "--log-to", dest="logTo", default="/var/log/pymm", help="Log to FILE", metavar="FILE")
     parser.add_option("-p", "--pre-domain", dest="pre_domain", help="Use DOMAIN as pre domain", metavar="DOMAIN")
     parser.add_option(
         "-P", "--post-address", dest="post_address", help="Use EMAIL as post address", metavar="EMAIL"
     )
     parser.add_option(
         "-t", "--target-domain", dest="target_domain", help="Use DOMAIN as target domain", metavar="DOMAIN"
     )
     parser.add_option(
         "-x", "--header-key", dest="header_key", default="X-37-For", help="Use KEY as header key", metavar="KEY"
     )
     return parser.parse_args()
Ejemplo n.º 33
0
def process_arguments():
    """ Process command line arguments """
    parser = argparse.ArgumentParser(description="Enron Corpus Parser")
    parser.add_argument("-p", "--path", help='Path to Enron corpus',
                        required=True)
    parser.add_argument("-o", "--output", help='Path to output file',
                        required=True)
    parser.add_argument("-s", "--sent", help='Only parse sent message folders',
                        action="store_true")
    parser.add_argument("-u", "--unique", help="Remove Duplicate messages",
                        action="store_true")
    parser.add_argument("-i", "--internal", help="Remove external messages",
                        action="store_true")
    parser.add_argument("-v", "--verbose", help="increase output verbosity",
                        action="store_true")
    return parser.parse_args()
Ejemplo n.º 34
0
def run():
    parser = argparse.ArgumentParser(description='Recreate wheel of package with given RECORD.')
    parser.add_argument('record_path',
                        help='Path to RECORD file')
    parser.add_argument('-o', '--output-dir',
                        help='Dir where to place the wheel, defaults to current working dir.',
                        dest='outdir',
                        default=os.path.curdir)

    ns = parser.parse_args()
    retcode = 0
    try:
        print(rewheel_from_record(**vars(ns)))
    except BaseException as e:
        print('Failed: {}'.format(e))
        retcode = 1
    sys.exit(1)
Ejemplo n.º 35
0
def main(argv):
    parser = OptionParser()
    parser.add_option("-b",
                      "--base",
                      dest="base_url",
                      help="specify base Fossil URL",
                      metavar="URL")
    parser.add_option("-R",
                      "--repository",
                      dest="repo",
                      help="Fossil repository to add ticket to",
                      metavar="FILE")

    global options, args
    (options, args) = parser.parse_args()

    if not options.base_url:
        parser.error("Base URL not given.")
    elif not options.repo:
        parser.error("Repository path not given.")

    if len(argv) < 2:
        print("Usage: {0} repository".format(argv[0]))
        return False

    msg = parse_message(sys.stdin.read())

    if not msg:
        print("Unable to parse message.", file=sys.stderr)
        return False
    elif not msg["id"]:
        print("No Message-Id, ignoring.", file=sys.stderr)
        return False

    cache = Cache()
    if msg["id"] in cache:
        print("Message {0} already was processed.".format(msg["id"]),
              file=sys.stderr)
        return True

    uuid = handle_message(msg)

    cache[msg["id"]] = uuid
    cache.save()

    return True
Ejemplo n.º 36
0
def parse_options():
    parser = OptionParser(usage = "usage: %prog [options]")
    parser.set_defaults(port = LISTEN_PORT, timeout = CHK_TIMEOUT,
            pcc_endpoint = PCC_ENDPOINT, xds_endpoint = XDS_ENDPOINT)
    parser.add_option("-p", action="store", dest="port", type="int",
                      help='The TCP port to listen to for the HTTP interface. Default: %s'% LISTEN_PORT)
    parser.add_option("-x", action="store", dest="xds_endpoint", 
                      help='The server endpoint for sending the XDS (Provide & Register) messages. Default: %s'% XDS_ENDPOINT)
    parser.add_option("-c", action="store", dest="pcc_endpoint", 
                      help='The server endpoint for sending the PCC-9 messages. Default: %s'% PCC_ENDPOINT)
    parser.add_option("-t", action="store", dest="timeout", type="int",
                      help='Timeout in seconds to be used for the periodic check. Default: %s (i.e. %s minutes).  Minimum: 5 seconds.'%
                      (CHK_TIMEOUT, CHK_TIMEOUT/60))
    (options, args) = parser.parse_args()
    if options.timeout < 5:
        options.timeout = 5
    return options
Ejemplo n.º 37
0
def main():
    """
  Generate a BUILD file for an unzipped Wheel

  We allow for empty Python sources as for Wheels containing only compiled C code
  there may be no Python sources whatsoever (e.g. packages written in Cython: like `pymssql`).
  """

    args = parser.parse_args()
    whl = Wheel(args.whl)

    # Extract the files into the current directory
    whl.expand(args.directory)

    with open(os.path.join(args.directory, 'BUILD'), 'w') as f:
        f.write("""
package(default_visibility = ["//visibility:public"])

load("@rules_python//python:defs.bzl", "py_library")
load("{requirements}", "requirement")

py_library(
    name = "pkg",
    srcs = glob(["**/*.py"], allow_empty = True),
    data = glob(["**/*"], exclude=["**/*.py", "**/* *", "BUILD", "WORKSPACE"]),
    # This makes this directory a top-level in the python import
    # search path for anything that depends on this.
    imports = ["."],
    deps = [{dependencies}],
)
{extras}""".format(requirements=args.requirements,
                   dependencies=','.join(
                       ['requirement("%s")' % d for d in whl.dependencies()]),
                   extras='\n\n'.join([
                       """py_library(
    name = "{extra}",
    deps = [
        ":pkg",{deps}
    ],
)""".format(extra=extra,
            deps=','.join(
                ['requirement("%s")' % dep
                 for dep in whl.dependencies(extra)]))
                       for extra in args.extras or []
                   ])))
Ejemplo n.º 38
0
def main():
    parser = ArgumentParser()
    parser.add_argument('-V', '--version', action='version', version="v%s" % __version__)
    parser.add_argument("-i", '--in-place', action="store_true", help="Demangle files in-place (possibly dangerous) [default: %(default)s]")
    parser.add_argument("-s", '--suffix', help="Suffix for demangled files, when not operating in-place [default: %(default)s]", default=".demangled")
    parser.add_argument("-n", '--dry-run', help="Don't actually write anything", action="store_true")
    parser.add_argument(dest="file", help="Name of the message file(s) to demangle", metavar="file", nargs="*")

    # Process arguments
    args = parser.parse_args()
    
    if len(args.file) == 0: args.file.append(None) 
    
    for f in args.file:
        try:
            handle_file(f, args.in_place, args.suffix, args.dry_run)
        except Exception as e:
            print >>sys.stderr, "%s: %s" % (f, e)
Ejemplo n.º 39
0
def process_args():
    parser = argparse.ArgumentParser(description='Load emails into Minezy')
    parser.add_argument('-c', '--complete', default=False, help="Run only the completion step")
    parser.add_argument('-d', '--depot_dir', required=True,
                       help="The [depot_dir] parameter should point to a parent folder of a parsed PST dump (eg: as generated by <a href='http://www.five-ten-sg.com/libpst/rn01re01.html'>readpst</a> tool)")
    parser.add_argument('-n', '--depot_name',  default="Un-named", help='Name of the account')
    parser.add_argument('-p', '--processes', default=8, type=int, help="Number of parallel processes to use to parse emails ")
    parser.add_argument('-v', '--verbose', nargs='?', const=True, default=False, type=bool, help="Print additional progress output")
    loader_opts = neo4jLoader.options()
    parser.add_argument('-l', '--load_options', nargs='*', choices=loader_opts, default=loader_opts, help="Select which email elements to load.")
    parser.add_argument('-s', '--sample', default=1, type=int, help="Use every n-th email from the depot (used for debugging).")
    word_types = wordCounter.word_types()
    parser.add_argument('-w', '--word_types', nargs='*', choices=word_types, default=word_types, help="Select which types of words to count.")
    parser.add_argument('-m', '--words_max_per_message', default=-1, type=int, help="How many word counts to save from each email message. (-1 for all)")
    parser.add_argument('-j', '--words_subject_only', nargs='?', const=True, default=False, type=bool, help="Only scan email subject for word counts")

    global args
    args = parser.parse_args()
Ejemplo n.º 40
0
def run():
    parser = argparse.ArgumentParser(description="Recreate wheel of package with given RECORD.")
    parser.add_argument("record_path", help="Path to RECORD file")
    parser.add_argument(
        "-o",
        "--output-dir",
        help="Dir where to place the wheel, defaults to current working dir.",
        dest="outdir",
        default=os.path.curdir,
    )

    ns = parser.parse_args()
    retcode = 0
    try:
        print(rewheel_from_record(**vars(ns)))
    except BaseException as e:
        print("Failed: {}".format(e))
        retcode = 1
    sys.exit(1)
Ejemplo n.º 41
0
def parse_args():
    "Pass command line arguments"
    # if not sys.argv[1:]:
    #     sys.argv.append('-h')
    parser = argparse.ArgumentParser(description='Match predefined parameters for creating features from text data')
    parser.add_argument('-c','--characters',
                        help='Characters to match, list of characters from txt file',
                        default='char_freq.txt')
    parser.add_argument('-w','--words',
                        help='words to match, list of words from txt file',
                        default='word_freq.txt')
    parser.add_argument('-i','--input_folder',
                        help='input folder, with subfolders for spam and ham',
                        default='enron-spam')
    parser.add_argument('-o', '--output',
                        help='tab separated output file with features formatted',
                        default='enron-spam/output_100K_spambase_538.tsv')
    args = parser.parse_args()
    return args
Ejemplo n.º 42
0
def run():
    parser = argparse.ArgumentParser(
        description='Recreate wheel of package with given RECORD.')
    parser.add_argument('record_path', help='Path to RECORD file')
    parser.add_argument(
        '-o',
        '--output-dir',
        help='Dir where to place the wheel, defaults to current working dir.',
        dest='outdir',
        default=os.path.curdir)

    ns = parser.parse_args()
    retcode = 0
    try:
        print(rewheel_from_record(**vars(ns)))
    except BaseException as e:
        print('Failed: {}'.format(e))
        retcode = 1
    sys.exit(1)
Ejemplo n.º 43
0
 def run(cls):
     parser = argparse.ArgumentParser(
         description=
         'Adjust the file modification dates of OS X Mail.app .emlx files to match the date in their headers.'
     )
     parser.add_argument(
         'mailroot',
         nargs='?',
         default='~/Library/Mail/V2/',
         help=
         'Toplevel directory in which .emlx files should be changed. Defaults to ~/Library/Mail/V2'
     )
     parser.add_argument('--dry-run',
                         help='Dry run, list the affected files only',
                         action='store_true')
     parser.add_argument('--verbose',
                         help='Log debug output',
                         action='store_true')
     args = parser.parse_args()
     Tool(args.mailroot, args.verbose).adjust_dates(dry_run=args.dry_run)
Ejemplo n.º 44
0
def main():
    signal.signal(signal.SIGINT, handle_signal)

    setupLogging()
    parser = argparse.ArgumentParser()
    parser.add_argument('--configFile', help='JSON configuration file')
    args = parser.parse_args()

    config = {}
    if args.configFile is not None:
        with open(args.configFile, "r") as fp:
            config = json.load(fp)
    if config.get('json_output_file') is None:
        config['json_output_file'] = 'dmarc.json'
    if config.get('sleep_seconds') is None:
        config['sleep_seconds'] = 300
    if config.get('socket_timeout_seconds') is None:
        config['socket_timeout_seconds'] = 30

    server = os.environ.get('POP3_SERVER', config.get('pop3_server'))
    username = os.environ.get('POP3_USERNAME', config.get('pop3_username'))
    password = os.environ.get('POP3_PASSWORD', config.get('pop3_password'))
    sleepSec = os.environ.get('SLEEP_SECONDS', config.get('sleep_seconds'))
    jsonOutputFile = os.environ.get('JSON_OUTPUT_FILE',
                                    config.get('json_output_file'))
    timeout = os.environ.get('SOCKET_TIMEOUT_SECONDS',
                             config.get('socket_timeout_seconds'))
    shouldDelete = os.environ.get('DELETE_MESSAGES',
                                  config.get('delete_messages'))
    shouldDeleteFailures = os.environ.get('DELETE_FAILURES',
                                          config.get('delete_failures'))

    if not server or not username or not password or not shouldDelete:
        log.error(
            "POP3_SERVER, POP3_USERNAME, POP3_PASSWORD, and DELETE_MESSAGES are required environment variables"
        )
    else:
        start(server, username, password, int(sleepSec), jsonOutputFile,
              float(timeout), shouldDelete, shouldDeleteFailures)
Ejemplo n.º 45
0
def parse_options():
    parser = OptionParser(usage="usage: %prog [options]")
    parser.set_defaults(port=LISTEN_PORT,
                        timeout=CHK_TIMEOUT,
                        pcc_endpoint=PCC_ENDPOINT,
                        xds_endpoint=XDS_ENDPOINT)
    parser.add_option(
        "-p",
        action="store",
        dest="port",
        type="int",
        help='The TCP port to listen to for the HTTP interface. Default: %s' %
        LISTEN_PORT)
    parser.add_option(
        "-x",
        action="store",
        dest="xds_endpoint",
        help=
        'The server endpoint for sending the XDS (Provide & Register) messages. Default: %s'
        % XDS_ENDPOINT)
    parser.add_option(
        "-c",
        action="store",
        dest="pcc_endpoint",
        help='The server endpoint for sending the PCC-9 messages. Default: %s'
        % PCC_ENDPOINT)
    parser.add_option(
        "-t",
        action="store",
        dest="timeout",
        type="int",
        help=
        'Timeout in seconds to be used for the periodic check. Default: %s (i.e. %s minutes).  Minimum: 5 seconds.'
        % (CHK_TIMEOUT, CHK_TIMEOUT / 60))
    (options, args) = parser.parse_args()
    if options.timeout < 5:
        options.timeout = 5
    return options
Ejemplo n.º 46
0
def main():
    args = parser.parse_args()
    whl = Wheel(args.whl)

    # Extract the files into the current directory
    whl.expand(args.directory)

    with open(os.path.join(args.directory, 'BUILD'), 'w') as f:
        f.write("""
package(default_visibility = ["//visibility:public"])

load("@rules_python//python:defs.bzl", "py_library")
load("{requirements}", "requirement")

py_library(
    name = "pkg",
    srcs = glob(["**/*.py"]),
    data = glob(["**/*"], exclude=["**/*.py", "**/* *", "BUILD", "WORKSPACE"]),
    # This makes this directory a top-level in the python import
    # search path for anything that depends on this.
    imports = ["."],
    deps = [{dependencies}],
)
{extras}""".format(requirements=args.requirements,
                   dependencies=','.join(
                       ['requirement("%s")' % d for d in whl.dependencies()]),
                   extras='\n\n'.join([
                       """py_library(
    name = "{extra}",
    deps = [
        ":pkg",{deps}
    ],
)""".format(extra=extra,
            deps=','.join(
                ['requirement("%s")' % dep
                 for dep in whl.dependencies(extra)]))
                       for extra in args.extras or []
                   ])))
Ejemplo n.º 47
0
def main(args=None):
    parser = argparse.ArgumentParser()
    parser.add_argument('-c', '--config-file', default='~/.imapautofiler.yml')
    parser.add_argument(
        '--list-mailboxes',
        default=False,
        action='store_true',
        help='instead of processing rules, print a list of mailboxes')
    args = parser.parse_args()

    try:
        cfg = config.get_config(args.config_file)
        conn = imapclient.IMAPClient(
            cfg['server']['hostname'],
            use_uid=True,
            ssl=True,
        )
        username = cfg['server']['username']
        password = cfg['server'].get('password')
        if not password:
            password = getpass.getpass('Password for {}:'.format(username))
        conn.login(username, password)
        try:
            if args.list_mailboxes:
                list_mailboxes(cfg, args.debug, conn)
            else:
                process_rules(cfg, args.debug, conn)
        finally:
            try:
                conn.close()
            except:
                pass
            conn.logout()
    except Exception as err:
        if args.debug:
            raise
        parser.error(err)
    return 0
Ejemplo n.º 48
0
def get_arguments(args):
    # Get arguments and create link to server
    from optparse import OptionParser
    parser = OptionParser(usage="%prog [options] <mailboxname> [<mailboxname> ...]")
    parser.add_option("-P", "--process",dest='process', help='IMAP process to access mailboxes')
    parser.add_option("-s", "--server",dest='server',help='IMAP server')
    parser.add_option("-p", "--port",  dest='port',  help='IMAP server port', type='int')
    parser.add_option("-x", "--ssl",   dest='ssl',   action="store_true", help='Use SSL')
    parser.add_option("-a", "--authuser", dest='authuser', help='IMAP admin user (e.g. for Zimbra)')
    parser.add_option("-u", "--user",  dest='user',  help='IMAP user name')
    parser.add_option("-w", "--password", dest='password',  help='IMAP password (Will prompt if not specified)')
    parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="Verbose mode")
    parser.add_option("-n", "--dry-run", dest="dry_run", action="store_true",
                        help="Don't actually do anything, just report what would be done")
    parser.add_option("-c", "--checksum", dest="use_checksum", action="store_true",
                        help="Use a checksum of several mail headers, instead of the Message-ID")
    parser.add_option("-m", "--checksum-with-id", dest="use_id_in_checksum", action="store_true",
                        help="Include the Message-ID (if any) in the -c checksum.")
    parser.add_option("",   "--no-close",  dest='no_close', action="store_true",
                        help='Do not "close" mailbox when done. Some servers will purge deleted messages on a close command.')
    parser.add_option("-l", "--list", dest="just_list", action="store_true",
                                            help="Just list mailboxes")

    parser.set_defaults(verbose=False, ssl=False, dry_run=False, no_close=False, just_list=False)
    (options, mboxes) = parser.parse_args(args)
    if ((not options.server) or (not options.user)) and not options.process:
        sys.stderr.write("\nError: Must specify server, user, and at least one mailbox.\n\n")
        parser.print_help()
        sys.exit(1)
    if not options.password and not options.process:
        # Read from IMAPDEDUP_PASSWORD env variable, or prompt for one.
        options.password = os.getenv("IMAPDEDUP_PASSWORD") or getpass.getpass()

    if options.use_id_in_checksum and not options.use_checksum:
        sys.stderr.write("\nError: If you use -m you must also use -c.\n")
        sys.exit(1)

    return (options, mboxes)
Ejemplo n.º 49
0
def get_arguments(args):
    # Get arguments and create link to server
    from optparse import OptionParser
    parser = OptionParser(usage="%prog [options] <mailboxname> [<mailboxname> ...]")
    parser.add_option("-P", "--process",dest='process', help='IMAP process to access mailboxes')
    parser.add_option("-s", "--server",dest='server',help='IMAP server')
    parser.add_option("-p", "--port",  dest='port',  help='IMAP server port', type='int')
    parser.add_option("-x", "--ssl",   dest='ssl',   action="store_true", help='Use SSL')
    parser.add_option("-u", "--user",  dest='user',  help='IMAP user name')
    parser.add_option("-w", "--password", dest='password',  help='IMAP password (Will prompt if not specified)')
    parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="Verbose mode")
    parser.add_option("-n", "--dry-run", dest="dry_run", action="store_true",
                        help="Don't actually do anything, just report what would be done")
    parser.add_option("-c", "--checksum", dest="use_checksum", action="store_true",
                        help="Use a checksum of several mail headers, instead of the Message-ID")
    parser.add_option("-m", "--checksum-with-id", dest="use_id_in_checksum", action="store_true",
                        help="Include the Message-ID (if any) in the -c checksum.")
    parser.add_option("",   "--no-close",  dest='no_close', action="store_true",
                        help='Do not "close" mailbox when done. Some servers will purge deleted messages on a close command.')
    parser.add_option("-l", "--list", dest="just_list", action="store_true",
                                            help="Just list mailboxes")

    parser.set_defaults(verbose=False, ssl=False, dry_run=False, no_close=False, just_list=False)
    (options, mboxes) = parser.parse_args(args)
    if ((not options.server) or (not options.user)) and not options.process:
        sys.stderr.write("\nError: Must specify server, user, and at least one mailbox.\n\n")
        parser.print_help()
        sys.exit(1)
    if not options.password and not options.process:
        # Read from IMAPDEDUP_PASSWORD env variable, or prompt for one.
        options.password = os.getenv("IMAPDEDUP_PASSWORD") or getpass.getpass()

    if options.use_id_in_checksum and not options.use_checksum:
        sys.stderr.write("\nError: If you use -m you must also use -c.\n")
        sys.exit(1)

    return (options, mboxes)
Ejemplo n.º 50
0
def main():
    parser = ArgumentParser()
    parser.add_argument('-V',
                        '--version',
                        action='version',
                        version="v%s" % __version__)
    parser.add_argument(
        "-i",
        '--in-place',
        action="store_true",
        help=
        "Demangle files in-place (possibly dangerous) [default: %(default)s]")
    parser.add_argument(
        "-s",
        '--suffix',
        help=
        "Suffix for demangled files, when not operating in-place [default: %(default)s]",
        default=".demangled")
    parser.add_argument("-n",
                        '--dry-run',
                        help="Don't actually write anything",
                        action="store_true")
    parser.add_argument(dest="file",
                        help="Name of the message file(s) to demangle",
                        metavar="file",
                        nargs="*")

    # Process arguments
    args = parser.parse_args()

    if len(args.file) == 0: args.file.append(None)

    for f in args.file:
        try:
            handle_file(f, args.in_place, args.suffix, args.dry_run)
        except Exception as e:
            print >> sys.stderr, "%s: %s" % (f, e)
Ejemplo n.º 51
0
        'archivedir': '/x1/archives',
        'restricteddir': '/x1/restricted',
        'dumpfile': '/x1/archives/bademails.txt'
    }

# validate an email argument
def valid_mail(m):
    if re.match(r"^.+?@(.*apache\.org|apachecon\.com)$", m):
        return m
    else:
        raise argparse.ArgumentTypeError("%r is not a valid ASF email address" % m)

parser = argparse.ArgumentParser()
parser.add_argument("--lid", type=valid_mail, help="override list id")
parser.add_argument("security", nargs='?') # e.g. restricted, private or omitted
args = parser.parse_args()

def lock(fd):
    """ Attempt to lock a file, wait 0.1 secs if failed. """
    while True:
        try:
            fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
            break
        except BlockingIOError as e:
            if e.errno == errno.EAGAIN or e.errno == errno.EACCES:
                time.sleep(0.1)
            else:
                raise

def dumpbad(what):
    with open(config['dumpfile'], "ab") as f:
Ejemplo n.º 52
0
    def logout(self):
        self.logger.debug('Closing connection to imap.google.com')
        self.M.close()
        self.M.logout()


if __name__ == '__main__':

    parser = OptionParser()
    parser.add_option("-c",
                      "--config",
                      default='/root/.mailfv',
                      dest="filename",
                      help="location of config file",
                      metavar="CONFIG")
    options, args = parser.parse_args()
    retCode = 0

    waitDaemon = threading.Event()
    waitDaemon.clear()
    retCode = Daemonize.createDaemon(022, '/', 1024, waitDaemon)
    waitDaemon.wait()

    def handler(signum, frame):
        gmail.exit()
        gmail.join()
        sys.exit(retCode)

    signal.signal(signal.SIGINT, handler)
    signal.signal(signal.SIGTERM, handler)
Ejemplo n.º 53
0
def py_nipubdir():
    """
    @brief Command line program to perform a NetInf 'publish' operation using http
    @brief convergence layer.
    
    Uses NIproc global instance of NI operations class

    Run:
    
    >  nipub.py --help

    to see usage and options.

    Exit code is 0 for success, 1 if HTTP returned something except 200,
    and negative for local errors.
    """
    

    # Options parsing and verification stuff
    usage = "%%prog -d <pathname of content directory> -n <FQDN of netinf node> [-a <hash alg>] [-m NN] [-c count]"

    parser = OptionParser(usage)
    
    parser.add_option("-d", "--dir", dest="dir_name",
                      type="string",
                      help="Pathname for directory to be published.")
    parser.add_option("-a", "--alg", dest="hash_alg", default="sha-256",
                      type="string",
                      help="Hash algorithm to be used for NI URIs. Defaults to sha-256.")
    parser.add_option("-n", "--node", dest="host",
                      type="string",
                      help="The FQDN where I'll send PUBLISH messages.")
    parser.add_option("-m", "--multiprocess", dest="mprocs", default=1,
                      type="int",
                      help="The number of client processes to use in a pool (default 1)")
    parser.add_option("-c", "--count", dest="count", default=0,
                      type="int",
                      help="The number of files to publish (default: all)")

    (options, args) = parser.parse_args()

    # Check command line options:
    # Arguments -h is optional, all others needed


    # Specifying more than one of -w, -p, -j and -v is inappropriate.
    if len(args) != 0:
        parser.error("Unrecognized arguments %s supplied." % str(args))
        sys.exit(-1)
    if options.dir_name == None:
        parser.error("You must supply a directory name with -d")
        sys.exit(-1)
    if options.host == None: 
        parser.error("You must supply a host name with -n")
        sys.exit(-1)

    nilog("Starting nipubdir,dir,%s,to,%s,alg,%s,processes,%d,count,%d" 
            % (options.dir_name,options.host,options.hash_alg,options.mprocs,options.count))

    # loop over all files below directory and putone() for each we find
    count,goodlist,badlist=pubdirs(options.dir_name,options.hash_alg,options.host,options.mprocs,options.count)

    # print goodlist
    # print badlist

    nilog("Finished nipubdir,dir,%s,to,%s,alg,%s,processes,%d,count,%d" 
        % (options.dir_name,options.host,options.hash_alg,options.mprocs,count))

    sys.exit(0)
Ejemplo n.º 54
0
def getopts():
    import argparse

    parser = argparse.ArgumentParser(description='Manage work queue.')

    default_logname = os.getenv('LOGNAME', 'zoo-animals')    

    parser.add_argument('keys', nargs='*')

    parser.add_argument('-c', '--count', type=int, default=0, help='limit to this many')

    parser.add_argument('-d', '--database',
                        help='use a specific database. (default: WORKDIR/work)')

    parser.add_argument('-D', '--delete', metavar='KEY', action='append', help='delete KEY')

    parser.add_argument('--dump', action='store_true')

    parser.add_argument('-F', '--priority-full', action='store_true',
                        help='enter a request for a full build into the head of the queue')
    parser.add_argument('-f', '--force-full', action='store_true',
                        help='enter a request for a full build into the queue')
    
    parser.add_argument('-H', '--homedir', default='',
                        help='set home directory. (default: ~LOGNAME)')

    parser.add_argument('-I', '--priority-incremental', action='store_true',
                        help='enter a request for an incremental build into the head of the queue')
    parser.add_argument('-i', '--force-incremental', action='store_true',
                        help='enter a request for an incremental build into the queue')

    parser.add_argument('-j', '--just-keys', action='store_true',
                        help='list the keys currently in the database')

    parser.add_argument('-l', '--logname', default=default_logname,
                        help='set LOGNAME. (default: {})'.format(default_logname))

    parser.add_argument('--print-count', action='store_true')
    parser.add_argument('--print-comment', action='store_true')
    parser.add_argument('--print-releasenotes', action='store_true')
    parser.add_argument('--print-requester', action='store_true')
    parser.add_argument('--print-submission', action='store_true')
    parser.add_argument('--print-validation', action='store_true')

    parser.add_argument('-Q', '--init', action='store_true',
                        help='initialize a fresh database')

    parser.add_argument('-R', '--reorganize', action='store_true')

    parser.add_argument('-r', '--requester', action='store_true')

    parser.add_argument('-s', '--submission', nargs='?', action='append', type=argparse.FileType('r'), default=[],
                        help='add SUBMISSION')

    parser.add_argument('-w', '--workdir', default='',
                        help='specify a WORKDIR. (default: HOMEDIR/workdir)')

    parser.add_argument('-x', '--trace', action='store_true')

    options = parser.parse_args()

    if not options.homedir:
        options.homedir = os.path.expanduser('~{}'.format(options.logname))

    if not options.workdir:
        options.workdir = os.path.join(options.homedir, 'workdir')

    if not options.database:
        options.database = os.path.join(options.workdir, 'work')

    return options
Ejemplo n.º 55
0
def getopts():
    import argparse

    parser = argparse.ArgumentParser(description='Manage work queue.')

    default_logname = os.getenv('LOGNAME', 'zoo-animals')

    parser.add_argument('keys', nargs='*')

    parser.add_argument('-c',
                        '--count',
                        type=int,
                        default=0,
                        help='limit to this many')

    parser.add_argument(
        '-d',
        '--database',
        help='use a specific database. (default: WORKDIR/work)')

    parser.add_argument('-D',
                        '--delete',
                        metavar='KEY',
                        action='append',
                        help='delete KEY')

    parser.add_argument('--dump', action='store_true')

    parser.add_argument(
        '-F',
        '--priority-full',
        action='store_true',
        help='enter a request for a full build into the head of the queue')
    parser.add_argument('-f',
                        '--force-full',
                        action='store_true',
                        help='enter a request for a full build into the queue')

    parser.add_argument('-H',
                        '--homedir',
                        default='',
                        help='set home directory. (default: ~LOGNAME)')

    parser.add_argument(
        '-I',
        '--priority-incremental',
        action='store_true',
        help=
        'enter a request for an incremental build into the head of the queue')
    parser.add_argument(
        '-i',
        '--force-incremental',
        action='store_true',
        help='enter a request for an incremental build into the queue')

    parser.add_argument('-j',
                        '--just-keys',
                        action='store_true',
                        help='list the keys currently in the database')

    parser.add_argument(
        '-l',
        '--logname',
        default=default_logname,
        help='set LOGNAME. (default: {})'.format(default_logname))

    parser.add_argument('--print-count', action='store_true')
    parser.add_argument('--print-comment', action='store_true')
    parser.add_argument('--print-releasenotes', action='store_true')
    parser.add_argument('--print-requester', action='store_true')
    parser.add_argument('--print-submission', action='store_true')
    parser.add_argument('--print-validation', action='store_true')

    parser.add_argument('-Q',
                        '--init',
                        action='store_true',
                        help='initialize a fresh database')

    parser.add_argument('-R', '--reorganize', action='store_true')

    parser.add_argument('-r', '--requester', action='store_true')

    parser.add_argument('-s',
                        '--submission',
                        nargs='?',
                        action='append',
                        type=argparse.FileType('r'),
                        default=[],
                        help='add SUBMISSION')

    parser.add_argument('-w',
                        '--workdir',
                        default='',
                        help='specify a WORKDIR. (default: HOMEDIR/workdir)')

    parser.add_argument('-x', '--trace', action='store_true')

    options = parser.parse_args()

    if not options.homedir:
        options.homedir = os.path.expanduser('~{}'.format(options.logname))

    if not options.workdir:
        options.workdir = os.path.join(options.homedir, 'workdir')

    if not options.database:
        options.database = os.path.join(options.workdir, 'work')

    return options
Ejemplo n.º 56
0
def get_arguments():
    # Get arguments and create link to server
    from optparse import OptionParser
    parser = OptionParser(
        usage="%prog [options] <mailboxname> [<mailboxname> ...]")
    parser.add_option("-s", "--server", dest='server', help='IMAP server')
    parser.add_option("-p",
                      "--port",
                      dest='port',
                      help='IMAP server port',
                      type='int')
    parser.add_option("-x",
                      "--ssl",
                      dest='ssl',
                      action="store_true",
                      help='Use SSL')
    parser.add_option("-u", "--user", dest='user', help='IMAP user name')
    parser.add_option("-w",
                      "--password",
                      dest='password',
                      help='IMAP password (Will prompt if not specified)')
    parser.add_option("-v",
                      "--verbose",
                      dest="verbose",
                      action="store_true",
                      help="Verbose mode")
    parser.add_option(
        "-n",
        "--dry-run",
        dest="dry_run",
        action="store_true",
        help="Don't actually do anything, just report what would be done")
    parser.add_option(
        "-c",
        "--checksum",
        dest="use_checksum",
        action="store_true",
        help="Use a checksum of several mail headers, instead of the Message-ID"
    )
    parser.add_option(
        "-m",
        "--checksum-with-id",
        dest="use_id_in_checksum",
        action="store_true",
        help="Include the Message-ID (if any) in the -c checksum.")
    parser.add_option("-l",
                      "--list",
                      dest="just_list",
                      action="store_true",
                      help="Just list mailboxes")

    parser.set_defaults(verbose=False,
                        ssl=False,
                        dry_run=False,
                        just_list=False)
    (options, args) = parser.parse_args()
    if (not options.server) or (not options.user):
        sys.stderr.write(
            "\nError: Must specify server, user, password and at least one mailbox.\n\n"
        )
        parser.print_help()
        sys.exit(1)
    if not options.password:
        options.password = getpass.getpass()

    return (options, args)
Ejemplo n.º 57
0
        if status != 204 and not self.fail_silently:
            raise MessageSendingFailure(errmsg)


if __name__ == '__main__':
    """mail -s [space-separated to-addresses] to-address
       and the message on stdin"""
    parser = optparse.OptionParser()
    parser.add_option("-s", dest="subject", help="subject of message")
    parser.add_option(
        "--fix-sender",
        action="store_true",
        dest="fix_sender",
        help=
        "If sender is not authorized, replace From with an authorized sender")
    options, to_addresses = parser.parse_args()
    if to_addresses:
        msg = email.message.Message()
        msg['From'] = os.environ['USER']
        msg['To'] = ",".join(to_addresses)  # escaping necessary?
        msg['Subject'] = options.subject
        msg.set_payload(sys.stdin.read())
    else:
        # We're expecting a whole message on stdin:
        msg = email.parser.Parser().parse(sys.stdin)
        recipient = os.environ.get('RECIPIENT')
        if recipient:
            msg['To'] = recipient
    GmailProxy(fix_sender=options.fix_sender).send_mail(msg)
Ejemplo n.º 58
0
    def parse_parameters(self, argv):
        parser = argparse.ArgumentParser()

        #==================================================
        # Input Files
        #==================================================
        filesgroup = parser.add_argument_group('input files')
        filesgroup.add_argument("-C",
                                metavar="<config.txt>",
                                dest="config_file",
                                action='store',
                                help="config file")
        filesgroup.add_argument("-U",
                                metavar="<users.txt>",
                                dest="usernamefile",
                                action='store',
                                help="file containing list of username")
        filesgroup.add_argument("-P",
                                metavar="<passwords.txt>",
                                dest="passwordfile",
                                action='store',
                                help="file containing list of passwords")
        filesgroup.add_argument(
            "--COMBINED",
            metavar="<username_passwords.txt>",
            dest="usernamepasswordfile",
            action='store',
            help="file containing list of username:password")
        filesgroup.add_argument(
            "--searchstringifile",
            metavar="<searchstrings.txt>",
            dest="searchstringfile",
            action='store',
            help="file containing list of search strings or regexes, 1 per line"
        )

        #==================================================
        # Enable Flags
        #==================================================
        enablegroup = parser.add_argument_group('enable flags')
        enablegroup.add_argument("--emails",
                                 dest="downloademails",
                                 action='store_true',
                                 help="download any identified emails?")
        enablegroup.add_argument("--attachments",
                                 dest="downloadattachments",
                                 action='store_true',
                                 help="download any identified attachments?")
        enablegroup.add_argument("--contacts",
                                 dest="buildcontactlist",
                                 action='store_true',
                                 help="collect contact list?")

        #==================================================
        # Other Args
        #==================================================
        parser.add_argument("-s",
                            metavar="<server>",
                            dest="server",
                            default="",
                            action='store',
                            help="target mail server ip or fqdn")
        parser.add_argument(
            "-t",
            metavar="<type of mail server>",
            dest="servertype",
            default="",
            action='store',
            help="valid choices are: IMAP, IMAPS, POP3, POP3S, OWA, EWS")
        parser.add_argument("-d",
                            metavar="<domain>",
                            dest="domain",
                            action='store',
                            help="domain name to phish")
        parser.add_argument("-u",
                            metavar="<username>",
                            dest="username",
                            action='store',
                            help="username")
        parser.add_argument("-p",
                            metavar="<password>",
                            dest="password",
                            action='store',
                            help="password")
        parser.add_argument("--searchstring",
                            metavar="\"term1,term2,term3,...\"",
                            dest="searchstring",
                            action='store',
                            help="list of search terms seperated by commas")
        parser.add_argument("-o",
                            metavar="<output directory>",
                            dest="outdir",
                            action='store',
                            help="directory to which to save any loot")
        parser.add_argument("-v",
                            "--verbosity",
                            dest="verbose",
                            action='count',
                            help="increase output verbosity")

        # parse args
        args = parser.parse_args()

        # convert parameters to values in the config dict
        self.config["verbose"] = args.verbose
        self.config["downloadattachments"] = args.downloadattachments
        self.config["downloademails"] = args.downloademails
        self.config["buildcontactlist"] = args.buildcontactlist
        self.config["searchstringfile"] = args.searchstringfile
        self.config["searchstring"] = args.searchstring
        self.config["server"] = args.server
        self.config["servertype"] = args.servertype
        self.config["domain"] = args.domain
        self.config["username"] = args.username
        self.config["usernamefile"] = args.usernamefile
        self.config["password"] = args.password
        self.config["passwordfile"] = args.passwordfile
        self.config["usernamepasswordfile"] = args.usernamepasswordfile
        if args.outdir:
            self.config["outdir"] = args.outdir

        if self.config["searchstring"]:
            self.config["searchterms"] = self.config["searchstring"].split(",")

        if Utils.isReadable(self.config["searchstringfile"]):
            with open(self.config["searchstringfile"]) as f:
                self.config["searchterms"] = f.read().splitlines()

        # validate we have required fields
        valid = True
        if (self.config["username"] and self.config["password"]) or (
                Utils.isReadable(self.config["usernamefile"])
                and Utils.isReadable(self.config["passwordfile"])) or (
                    Utils.isReadable(self.config["usernamepasswordfile"])):
            pass
        else:
            self.display.error(
                "Please enable at least one of the following parameters: --COMBINED or (-U and -P) or (-u and -p)"
            )
            valid = False
        if (self.config["server"] and self.config["servertype"]):
            self.config["servertype"] = self.config["servertype"].lower()
            pass
        else:
            self.display.error("Please enable at both of: -s and -t")
            valid = False

        if not valid:
            parser.print_help()
            sys.exit(1)
Ejemplo n.º 59
0
def run_cli(main):
    try:
        [summary, details] = splitdoc(main.__doc__)
        parser = ArgumentParser(formatter_class=RawDescriptionHelpFormatter,
                                description=summary,
                                epilog=details)

        groups = dict()
        paired = set()
        pos = None
        for param in signature(main).parameters.values():
            attrs = param.annotation
            if attrs is Parameter.empty:
                attrs = dict()
            kw = dict(default=param.default)
            if param.kind == Parameter.KEYWORD_ONLY:
                name = "--" + param.name
                short = attrs.pop("short", None)
                if short is None:
                    short = ()
                else:
                    short = (short, )
                if kw["default"] is Parameter.empty:
                    attrs.setdefault("required", True)
            else:
                name = param.name
                short = ()
                if param.kind == Parameter.VAR_POSITIONAL:
                    pos = param.name
                    attrs.setdefault("nargs", "*")
                else:
                    assert param.kind == Parameter.POSITIONAL_OR_KEYWORD
            if param.kind == Parameter.KEYWORD_ONLY \
                    and kw["default"] is False:
                kw.update(action="store_true")
            else:
                if isinstance(kw["default"], int):
                    assert param.kind == Parameter.KEYWORD_ONLY
                    attrs.setdefault("type", int)
                elif isinstance(
                        kw["default"],
                    (list, tuple, set, frozenset)) and not kw["default"]:
                    if param.kind == Parameter.KEYWORD_ONLY:
                        kw.update(action="append", default=list())
                    else:
                        attrs.setdefault("nargs", "*")
                elif kw["default"] is Parameter.empty:
                    del kw["default"]
                else:
                    assert param.kind == Parameter.KEYWORD_ONLY

            required = attrs.pop("mutex_required", None)
            group_id = attrs.pop("mutex", required)
            if group_id is None:
                group = parser
            else:
                try:
                    group = groups[group_id]
                    paired.add(group_id)
                except LookupError:
                    group = parser.add_mutually_exclusive_group(
                        required=required is not None)
                    groups[group_id] = group

            name = name.replace("_", "-")
            group.add_argument(*short, name, **kw, **attrs)
        assert paired == groups.keys()

        args = dict(vars(parser.parse_args()))
        if pos is None:
            pos = ()
        else:
            pos = args.pop(pos)
        main(*pos, **args)
    except KeyboardInterrupt:
        signal(SIGINT, SIG_DFL)
        kill(getpid(), SIGINT)
    except BrokenPipeError:
        signal(SIGPIPE, SIG_DFL)
        kill(getpid(), SIGPIPE)