2017-08-25 12:02:53 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import os
|
|
|
|
import zulip
|
|
|
|
|
2017-09-15 04:55:55 -04:00
|
|
|
import argparse
|
|
|
|
|
2017-08-25 12:02:53 -04:00
|
|
|
def main():
|
2017-09-15 07:24:24 -04:00
|
|
|
# type: () -> None
|
2017-09-15 04:55:55 -04:00
|
|
|
usage = """zulip-api-examples [script_name]
|
|
|
|
|
|
|
|
Prints the path to the Zulip API example scripts."""
|
|
|
|
parser = argparse.ArgumentParser(usage=usage)
|
|
|
|
parser.add_argument('script_name',
|
|
|
|
nargs='?',
|
|
|
|
default='',
|
|
|
|
help='print path to the script <script_name>')
|
|
|
|
args = parser.parse_args()
|
2017-08-25 12:02:53 -04:00
|
|
|
zulip_path = os.path.abspath(os.path.dirname(zulip.__file__))
|
2017-09-15 04:55:55 -04:00
|
|
|
examples_path = os.path.abspath(os.path.join(zulip_path, 'examples', args.script_name))
|
|
|
|
if os.path.isdir(examples_path) or (args.script_name and os.path.isfile(examples_path)):
|
2017-08-25 12:02:53 -04:00
|
|
|
print(examples_path)
|
|
|
|
else:
|
2017-09-15 04:55:55 -04:00
|
|
|
raise OSError("Examples cannot be accessed at {}: {} does not exist!"
|
|
|
|
.format(examples_path,
|
|
|
|
"File" if args.script_name else "Directory"))
|
2017-08-25 12:02:53 -04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|