Skip to content

Commit

Permalink
Merge pull request #5 from BurtBiel/burtbiel/Support27
Browse files Browse the repository at this point in the history
Support Python 2.7 again
  • Loading branch information
yugangw-msft committed Feb 24, 2016
2 parents c929bfc + 8838939 commit 85a9c17
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
10 changes: 1 addition & 9 deletions src/azure/cli/__main__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import time
_import_time = time.perf_counter()

import sys

import azure.cli.main
from azure.cli._logging import logging

try:
sys.exit(azure.cli.main.main(sys.argv[1:]))
finally:
# Note: script time includes idle and network time
logging.info('Execution time: %8.3fms', 1000 * (time.perf_counter() - _import_time))
sys.exit(azure.cli.main.main(sys.argv[1:]))
22 changes: 14 additions & 8 deletions src/azure/cli/_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def execute(self, args, show_usage=False, show_completions=False, out=sys.stdout
all_global_args = set(a.lstrip('-/') for a in self.help_args | self.complete_args | self.global_args)
def not_global(a):
return a.lstrip('-/') not in all_global_args
it = filter(not_global, args)
it = filter(not_global, args).__iter__()

m = self.noun_map
nouns = []
Expand Down Expand Up @@ -215,30 +215,35 @@ def not_global(a):
def _display_usage(self, nouns, noun_map, arguments, out=sys.stdout):
spec = ' '.join(noun_map.get('$spec') or nouns)
print(' {} {}'.format(self.prog, spec), file=out)
print(file=out, flush=True)
print(file=out)
out.flush()

subnouns = sorted(k for k in noun_map if not k.startswith('$'))
if subnouns:
print('Subcommands', file=out)
for n in subnouns:
print(' {}'.format(n), file=out)
print(file=out, flush=True)
print(file=out)
out.flush()

argdoc = noun_map.get('$argdoc')
if argdoc:
print('Arguments', file=out)
maxlen = max(len(a) for a, d in argdoc)
for a, d in argdoc:
print(' {0:<{1}} - {2}'.format(a, maxlen, d), file=out)
print(file=out, flush=True)
print(file=out)
out.flush()

doc_file = locale_get_file(noun_map['$doc'])
try:
with open(doc_file, 'r') as f:
print(f.read(), file=out, flush=True)
except OSError:
print(f.read(), file=out)
f.flush()
except (OSError, IOError):
# TODO: Behave better when no docs available
print('No documentation available', file=out, flush=True)
print('No documentation available', file=out)
out.flush()
logging.debug('Expected documentation at %s', doc_file)

def _display_completions(self, nouns, noun_map, arguments, out=sys.stdout):
Expand All @@ -248,4 +253,5 @@ def _display_completions(self, nouns, noun_map, arguments, out=sys.stdout):
if kwargs:
completions.extend('--' + a for a in kwargs if a)

print('\n'.join(sorted(completions)), file=out, flush=True)
print('\n'.join(sorted(completions)), file=out)
out.flush()
8 changes: 6 additions & 2 deletions src/azure/cli/_session.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import collections.abc
import json
import os
import time
try:
import collections.abc as collections
except ImportError:
import collections


from codecs import open

class Session(collections.abc.MutableMapping):
class Session(collections.MutableMapping):
'''A simple dict-like class that is backed by a JSON file.
All direct modifications will save the file. Indirect modifications should
Expand Down
2 changes: 1 addition & 1 deletion src/azure/cli/commands/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def list_accounts(args, unexpected):
profile = Profile()
#credentials, subscription_id = profile.get_credentials()
smc = StorageManagementClient(StorageManagementClientConfiguration(
*profile.get_credentials(),
*profile.get_credentials()
))

group = args.get('resource-group')
Expand Down

0 comments on commit 85a9c17

Please sign in to comment.