zephyr_mirror: Add option to specify user used for mirroring.
(imported from commit c9dfe4f8d12f2e234c85d96ba7ca59e0a59c1bd4)
This commit is contained in:
parent
4fb6a4ab7c
commit
3fc636838a
|
@ -51,21 +51,23 @@ parser.add_option('--site',
|
||||||
dest='site',
|
dest='site',
|
||||||
default="https://app.humbughq.com",
|
default="https://app.humbughq.com",
|
||||||
action='store')
|
action='store')
|
||||||
parser.add_option('--api-key',
|
parser.add_option('--user',
|
||||||
dest='api_key',
|
dest='user',
|
||||||
default=None,
|
default=os.environ["USER"],
|
||||||
|
action='store')
|
||||||
|
parser.add_option('--api-key-file',
|
||||||
|
dest='api_key_file',
|
||||||
|
default=os.path.join(os.environ["HOME"], "Private", ".humbug-api-key"),
|
||||||
action='store')
|
action='store')
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
if options.api_key is None:
|
api_key = file(options.api_key_file).read().strip()
|
||||||
api_key_file = os.path.join(os.environ["HOME"], "Private", ".humbug-api-key")
|
|
||||||
options.api_key = file(api_key_file).read().strip()
|
|
||||||
|
|
||||||
sys.path.append(".")
|
sys.path.append(".")
|
||||||
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
|
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
|
||||||
import api.common
|
import api.common
|
||||||
humbug_client = api.common.HumbugAPI(email=os.environ["USER"] + "@mit.edu",
|
humbug_client = api.common.HumbugAPI(email=options.user + "@mit.edu",
|
||||||
api_key=options.api_key,
|
api_key=api_key,
|
||||||
verbose=True,
|
verbose=True,
|
||||||
site=options.site)
|
site=options.site)
|
||||||
|
|
||||||
|
@ -153,7 +155,7 @@ def update_subscriptions_from_humbug():
|
||||||
|
|
||||||
def maybe_restart_mirroring_script():
|
def maybe_restart_mirroring_script():
|
||||||
if os.stat(root_path + "/restart_stamp").st_mtime > start_time or \
|
if os.stat(root_path + "/restart_stamp").st_mtime > start_time or \
|
||||||
(os.environ["USER"] == "tabbott" and
|
(options.user == "tabbott" and
|
||||||
os.stat(root_path + "/tabbott_stamp").st_mtime > start_time):
|
os.stat(root_path + "/tabbott_stamp").st_mtime > start_time):
|
||||||
print
|
print
|
||||||
print "%s: zephyr mirroring script has been updated; restarting..." % \
|
print "%s: zephyr mirroring script has been updated; restarting..." % \
|
||||||
|
@ -281,9 +283,9 @@ def zephyr_to_humbug(options):
|
||||||
ensure_subscribed(sub)
|
ensure_subscribed(sub)
|
||||||
update_subscriptions_from_humbug()
|
update_subscriptions_from_humbug()
|
||||||
if options.forward_personals:
|
if options.forward_personals:
|
||||||
subs.add(("message", "*", os.environ["USER"] + "@ATHENA.MIT.EDU"))
|
subs.add(("message", "*", options.user + "@ATHENA.MIT.EDU"))
|
||||||
if subscribed_to_mail_messages():
|
if subscribed_to_mail_messages():
|
||||||
subs.add(("mail", "inbox", os.environ["USER"] + "@ATHENA.MIT.EDU"))
|
subs.add(("mail", "inbox", options.user + "@ATHENA.MIT.EDU"))
|
||||||
|
|
||||||
if options.resend_log:
|
if options.resend_log:
|
||||||
with open('zephyrs', 'r') as log:
|
with open('zephyrs', 'r') as log:
|
||||||
|
@ -363,7 +365,7 @@ def forward_to_zephyr(message):
|
||||||
zeph.send()
|
zeph.send()
|
||||||
|
|
||||||
def maybe_forward_to_zephyr(message):
|
def maybe_forward_to_zephyr(message):
|
||||||
if message["sender_email"] == os.environ["USER"] + "@mit.edu":
|
if message["sender_email"] == options.user + "@mit.edu":
|
||||||
timestamp_now = datetime.datetime.now().strftime("%s")
|
timestamp_now = datetime.datetime.now().strftime("%s")
|
||||||
if float(message["timestamp"]) < float(timestamp_now) - 15:
|
if float(message["timestamp"]) < float(timestamp_now) - 15:
|
||||||
print "%s humbug=>zephyr: Alert! Out of order message: %s < %s" % \
|
print "%s humbug=>zephyr: Alert! Out of order message: %s < %s" % \
|
||||||
|
@ -411,7 +413,7 @@ def parse_zephyr_subs(verbose=False):
|
||||||
if verbose:
|
if verbose:
|
||||||
print >>sys.stderr, "Couldn't find .zephyr.subs!"
|
print >>sys.stderr, "Couldn't find .zephyr.subs!"
|
||||||
print >>sys.stderr, "Do you mean to run with --no-auto-subscribe?"
|
print >>sys.stderr, "Do you mean to run with --no-auto-subscribe?"
|
||||||
return
|
return []
|
||||||
|
|
||||||
for line in file(subs_file, "r").readlines():
|
for line in file(subs_file, "r").readlines():
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
|
|
Loading…
Reference in a new issue