From 6894453ab500f4f7cae4058bc9cd086f16c114dd Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Mon, 28 Oct 2013 10:54:32 -0400 Subject: [PATCH] Use os.path directly rather than sometimes importing it separately. (imported from commit 48486c4ea64d02a15faeebb0f490d31e9b113d62) --- bots/check-rabbitmq-consumers | 7 +++---- bots/check-rabbitmq-queue | 7 +++---- bots/gcal-bot | 6 +++--- bots/sync-public-streams | 4 ++-- bots/tddium-notify-humbug | 18 +++++++++--------- examples/edit-message | 4 ++-- examples/get-public-streams | 4 ++-- examples/list-members | 4 ++-- examples/list-subscriptions | 4 ++-- examples/print-messages | 4 ++-- examples/print-next-message | 4 ++-- examples/send-message | 4 ++-- examples/subscribe | 4 ++-- examples/unsubscribe | 4 ++-- 14 files changed, 38 insertions(+), 40 deletions(-) diff --git a/bots/check-rabbitmq-consumers b/bots/check-rabbitmq-consumers index 071d2d5..d0103d3 100755 --- a/bots/check-rabbitmq-consumers +++ b/bots/check-rabbitmq-consumers @@ -4,10 +4,9 @@ import sys import time import optparse from collections import defaultdict +import os -from os import path, environ - -sys.path.append(path.join(path.dirname(__file__), '..')) +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) from zulip_tools import check_output states = { @@ -17,7 +16,7 @@ states = { 3: "UNKNOWN" } -if 'USER' in environ and not environ['USER'] in ['root', 'rabbitmq']: +if 'USER' in os.environ and not os.environ['USER'] in ['root', 'rabbitmq']: print "This script must be run as the root or rabbitmq user" diff --git a/bots/check-rabbitmq-queue b/bots/check-rabbitmq-queue index ef57dcb..d29bc20 100755 --- a/bots/check-rabbitmq-queue +++ b/bots/check-rabbitmq-queue @@ -3,10 +3,9 @@ import sys import re import time +import os -from os import path, environ - -sys.path.append(path.join(path.dirname(__file__), '..')) +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) from zulip_tools import check_output WARN_THRESHOLD = 50 @@ -26,7 +25,7 @@ status = 0 max_count = 0 warn_queues = [] -if 'USER' in environ and not environ['USER'] in ['root', 'rabbitmq']: +if 'USER' in os.environ and not os.environ['USER'] in ['root', 'rabbitmq']: print "This script must be run as the root or rabbitmq user" for line in output.split("\n"): diff --git a/bots/gcal-bot b/bots/gcal-bot index 38957bf..650c2d4 100755 --- a/bots/gcal-bot +++ b/bots/gcal-bot @@ -6,9 +6,9 @@ import optparse import urlparse import itertools import traceback -from os import path +import os -sys.path.append(path.join(path.dirname(__file__), '../api')) +sys.path.append(os.path.join(os.path.dirname(__file__), '../api')) import zulip parser = optparse.OptionParser(r""" @@ -57,7 +57,7 @@ except ImportError: def get_calendar_url(): parts = urlparse.urlparse(options.calendar) - pat = path.split(parts.path) + pat = os.path.split(parts.path) if pat[1] != 'basic': parser.error('The --calendar URL should be the XML "Private Address" ' + 'from your calendar settings') diff --git a/bots/sync-public-streams b/bots/sync-public-streams index ebbbefb..5f11ce3 100755 --- a/bots/sync-public-streams +++ b/bots/sync-public-streams @@ -1,13 +1,13 @@ #!/usr/bin/env python import sys -from os import path +import os import logging import time import simplejson import subprocess import unicodedata -sys.path.append(path.join(path.dirname(__file__), '..', 'api')) +sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'api')) import zulip zulip_client = zulip.Client() diff --git a/bots/tddium-notify-humbug b/bots/tddium-notify-humbug index 0dc7995..7e69115 100755 --- a/bots/tddium-notify-humbug +++ b/bots/tddium-notify-humbug @@ -22,7 +22,7 @@ # SOFTWARE. import sys -from os import path, environ +import os # Configure this script as a Tddium post-build task and it will send @@ -42,26 +42,26 @@ from os import path, environ # Here we assume it's in the parent of the directory # where this script lives. -zulip_directory = path.join(path.dirname(__file__), '../api') +zulip_directory = os.path.join(os.path.dirname(__file__), '../api') sys.path.append(zulip_directory) import zulip client = zulip.Client( - email = environ['ZULIP_USER'], - api_key = environ.get('ZULIP_API_KEY')) + email = os.environ['ZULIP_USER'], + api_key = os.environ.get('ZULIP_API_KEY')) -tddium_server = environ.get('TDDIUM_API_SERVER', 'api.tddium.com') -report_url = 'https://%s/1/reports/%s' % (tddium_server, environ['TDDIUM_SESSION_ID']) -repo_name = path.basename(environ['TDDIUM_REPO_ROOT']) +tddium_server = os.environ.get('TDDIUM_API_SERVER', 'api.tddium.com') +report_url = 'https://%s/1/reports/%s' % (tddium_server, os.environ['TDDIUM_SESSION_ID']) +repo_name = os.path.basename(os.environ['TDDIUM_REPO_ROOT']) result = client.send_message(dict( type = 'stream', - to = environ['ZULIP_STREAM'], + to = os.environ['ZULIP_STREAM'], subject = 'build for ' + repo_name, content = '%s [%s](%s)' % - (repo_name, environ['TDDIUM_BUILD_STATUS'], report_url))) + (repo_name, os.environ['TDDIUM_BUILD_STATUS'], report_url))) if result['result'] != 'success': sys.stderr.write('Error sending to Zulip:\n%s\n' % (result['msg'],)) diff --git a/examples/edit-message b/examples/edit-message index e9119f7..af61fb7 100755 --- a/examples/edit-message +++ b/examples/edit-message @@ -22,7 +22,7 @@ # THE SOFTWARE. import sys -from os import path +import os import optparse usage = """edit-message [options] --message= --subject= --content= --user= --api-key= @@ -34,7 +34,7 @@ Example: edit-message --message-id="348135" --subject="my subject" --content="te You can omit --user and --api-key arguments if you have a properly set up ~/.zuliprc """ -sys.path.insert(0, path.join(path.dirname(__file__), '..')) +sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) import zulip parser = optparse.OptionParser(usage=usage) diff --git a/examples/get-public-streams b/examples/get-public-streams index ea2cc82..c71c354 100755 --- a/examples/get-public-streams +++ b/examples/get-public-streams @@ -22,7 +22,7 @@ # THE SOFTWARE. import sys -from os import path +import os import optparse usage = """get-public-streams --user= --api-key= [options] @@ -34,7 +34,7 @@ Example: get-public-streams --user=othello-bot@example.com --api-key=a0b1c2d3e4f You can omit --user and --api-key arguments if you have a properly set up ~/.zuliprc """ -sys.path.append(path.join(path.dirname(__file__), '..')) +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) import zulip parser = optparse.OptionParser(usage=usage) diff --git a/examples/list-members b/examples/list-members index 0976f66..2226bc3 100755 --- a/examples/list-members +++ b/examples/list-members @@ -22,7 +22,7 @@ # THE SOFTWARE. import sys -from os import path +import os import optparse usage = """list-members --user= --api-key= [options] @@ -32,7 +32,7 @@ List the names and e-mail addresses of the people in your realm. You can omit --user and --api-key arguments if you have a properly set up ~/.zuliprc """ -sys.path.append(path.join(path.dirname(__file__), '..')) +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) import zulip parser = optparse.OptionParser(usage=usage) diff --git a/examples/list-subscriptions b/examples/list-subscriptions index 00623af..4d674fc 100755 --- a/examples/list-subscriptions +++ b/examples/list-subscriptions @@ -22,7 +22,7 @@ # THE SOFTWARE. import sys -from os import path +import os import optparse usage = """list-subscriptions --user= --api-key= [options] @@ -33,7 +33,7 @@ Example: list-subscriptions --user=tabbott@zulip.com --api-key=a0b1c2d3e4f5a6b7c You can omit --user and --api-key arguments if you have a properly set up ~/.zuliprc """ -sys.path.append(path.join(path.dirname(__file__), '..')) +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) import zulip parser = optparse.OptionParser(usage=usage) diff --git a/examples/print-messages b/examples/print-messages index ac66dd0..d8077ff 100755 --- a/examples/print-messages +++ b/examples/print-messages @@ -22,7 +22,7 @@ # THE SOFTWARE. import sys -from os import path +import os import optparse usage = """print-messages --user= --api-key= [options] @@ -33,7 +33,7 @@ Example: print-messages --user=tabbott@zulip.com --api-key=a0b1c2d3e4f5a6b7c8d9e You can omit --user and --api-key arguments if you have a properly set up ~/.zuliprc """ -sys.path.append(path.join(path.dirname(__file__), '..')) +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) import zulip parser = optparse.OptionParser(usage=usage) diff --git a/examples/print-next-message b/examples/print-next-message index 5c0d3cb..e6334a3 100755 --- a/examples/print-next-message +++ b/examples/print-next-message @@ -22,7 +22,7 @@ # THE SOFTWARE. import sys -from os import path +import os import optparse usage = """print-next-message --user= --api-key= [options] @@ -33,7 +33,7 @@ Example: print-next-messages --user=tabbott@zulip.com --api-key=a0b1c2d3e4f5a6b7 You can omit --user and --api-key arguments if you have a properly set up ~/.zuliprc """ -sys.path.append(path.join(path.dirname(__file__), '..')) +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) import zulip parser = optparse.OptionParser(usage=usage) diff --git a/examples/send-message b/examples/send-message index f9edabc..582ae6b 100755 --- a/examples/send-message +++ b/examples/send-message @@ -22,9 +22,9 @@ # THE SOFTWARE. import sys -from os import path +import os import optparse -sys.path.append(path.join(path.dirname(__file__), '..')) +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) import zulip usage = """send-message --user= --api-key= [options] diff --git a/examples/subscribe b/examples/subscribe index 1593fe8..069f8ff 100755 --- a/examples/subscribe +++ b/examples/subscribe @@ -22,7 +22,7 @@ # THE SOFTWARE. import sys -from os import path +import os import optparse usage = """subscribe --user= --api-key= [options] --streams= @@ -34,7 +34,7 @@ Examples: subscribe --user=tabbott@zulip.com --api-key=a0b1c2d3e4f5a6b7c8d9e0f1a You can omit --user and --api-key arguments if you have a properly set up ~/.zuliprc """ -sys.path.append(path.join(path.dirname(__file__), '..')) +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) import zulip parser = optparse.OptionParser(usage=usage) diff --git a/examples/unsubscribe b/examples/unsubscribe index 104e03e..d2e1b86 100755 --- a/examples/unsubscribe +++ b/examples/unsubscribe @@ -22,7 +22,7 @@ # THE SOFTWARE. import sys -from os import path +import os import optparse usage = """unsubscribe --user= --api-key= [options] --streams= @@ -34,7 +34,7 @@ Examples: unsubscribe --user=tabbott@zulip.com --api-key=a0b1c2d3e4f5a6b7c8d9e0f You can omit --user and --api-key arguments if you have a properly set up ~/.zuliprc """ -sys.path.append(path.join(path.dirname(__file__), '..')) +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) import zulip parser = optparse.OptionParser(usage=usage)