Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Passing in package name and version to Insight so we dont need to man…

…ually update them. Relates to #578
  • Loading branch information...
commit f725197f55ec5db2e90373bd71d83541e820a731 1 parent 264ff72
@ebidel ebidel authored
View
1  cli/bin/yeoman
@@ -102,6 +102,7 @@ function init() {
insight.init({
pkgname : pkg.name,
+ pkgversion : pkg.version,
getUserHome: getUserHome,
cmds : cmds,
cb : cb
View
49 cli/bin/yeomaninsight.py
@@ -5,6 +5,7 @@
__author__ = 'ebidel@gmail.com (Eric Bidelman)'
+import getopt
import os
import random
import shutil
@@ -14,12 +15,7 @@
import urllib2
NO_STATS = 'NO_STATS'
-CLI_NAME = 'yeoman'
-
-# TODO(ericbidelman): Verify expanduser('~') works on other platforms.
-# ~/.yeoman/insight
-INSIGHT_DIR = os.path.join(os.path.expanduser('~'), '.' + CLI_NAME, 'insight')
-LOG_FILE = os.path.join(INSIGHT_DIR, '.log') # ~/.yeoman/insight/.log
+DEFAULT_CLI_NAME = 'yeoman'
NUM_SUB_CMDS = 2 # Subcommand depth. TODO: This assumes only "cmd subcmd" format.
NUM_SECONDS_TO_STASH_DATA = 0 # Send data as it happens.
@@ -30,11 +26,14 @@ class Analytics(object):
TRACKING_CODE = 'UA-31537568-1'
BASE_URL = 'http://www.google-analytics.com/collect/__utm.gif'
- def __init__(self, tracking_code):
+ def __init__(self, tracking_code, av):
@sindresorhus Owner

yak, app_version please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
if not tracking_code:
- raise Exception('No tracking code is given')
+ raise Exception('No tracking code was given')
+ if not av:
+ raise Exception('No application version was given')
self.tracking_code = tracking_code
+ self.av = av
self.do_stats = True
# Create ~/.yeoman/insight if it doesn't exist.
@@ -113,8 +112,8 @@ def _send(self, path='/', recorded_at=None):
'aip': '1', # Anonymize IP
'qt': int((time.time() - recorded_at) * 1e3), # Queue Time. Delta (milliseconds) between now and when hit was recorded.
'dp': path,
- 'an': 'Yeoman Insight', #settings.APP['title'], # Application Name.
- 'av': '0.9.3', #settings.APP['version'], # Application Version.
+ 'an': 'Yeoman Insight', # Application Name.
+ 'av': self.av, # Application Version.
'z': time.time() # Cache bust. Probably don't need, but be safe. Should be last param.
}
@@ -174,15 +173,37 @@ def record(self, cmd_str):
def main(args):
+ global INSIGHT_DIR
+ global LOG_FILE
+ global CLI_NAME
if len(sys.argv) < 2:
- print 'Yo! invalid number of arguments.'
+ print 'Invalid number of arguments.'
+ sys.exit(1)
+
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], 'v:n:', ['version=', 'name='])
@sindresorhus Owner

Why not use argparse?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ except getopt.GetoptError, err:
+ print str(err)
sys.exit(1)
- method = sys.argv[1]
- args = ' '.join(sys.argv[2:])
+ av = 'x.x.x'
+ CLI_NAME = DEFAULT_CLI_NAME
+ for opt, val in opts:
+ if opt in ('-v', '--version'):
+ av = val
+ elif opt in ('-n', '--name'):
+ CLI_NAME = val
+
+ method = args[0]
+ args = ' '.join(args[1:])
+
+ # TODO(ericbidelman): Verify expanduser('~') works on other platforms.
+ # ~/.yeoman/insight
+ INSIGHT_DIR = os.path.join(os.path.expanduser('~'), '.' + CLI_NAME, 'insight')
+ LOG_FILE = os.path.join(INSIGHT_DIR, '.log') # ~/.yeoman/insight/.log
- ga = Analytics(Analytics.TRACKING_CODE)
+ ga = Analytics(Analytics.TRACKING_CODE, av)
#if callable(getattr(ga, method)):
# getattr(ga, method)()
View
8 cli/lib/plugins/insight.js
@@ -14,12 +14,14 @@ module.exports = {
// This should correspond to whatever name is used in package.json.
var INSIGHT_SCRIPT = '_' + opts.pkgname + 'insight'
+ // e.g. /Users/username/.yeoman/insight
var insightFolder = join(YEOMAN_DIR, 'insight');
- // Assume yeomaninsight.py is installed globally (/usr/local/bin/)
- var insightRecordCmd = ['record'];
+ var insightRecordCmd = ['-n', opts.pkgname, '-v', opts.pkgversion, 'record'];
- // Record this action in Insight (e.g. python yeomaninsight.py record cmd cmd2).
+ // Record this action in Insight.
+ // Assume yeomaninsight.py is installed globally (/usr/local/bin/) as _yeomaninsight.
+ // _yeomaninsight -n yeoman -v 0.0.1 record cmd cmd2).
spawn(INSIGHT_SCRIPT, insightRecordCmd.concat(opts.cmds));
//insight.stdout.pipe(process.stdout);
View
3  cli/test/test-insight.py
@@ -13,6 +13,9 @@ class YeomanInsightTest(unittest.TestCase):
def test_init_should_error_when_no_tracking_code_is_passed(self):
self.assertRaises(Exception, Analytics, tracking_code='')
+ def test_init_should_error_when_no_av_is_passed(self):
+ self.assertRaises(Exception, Analytics, av='')
+
def test_main_should_error_when_arguments_are_less_than_two(self):
# temporally disables print function, because it's used on main.
# just to keep the tests output clean.
Please sign in to comment.
Something went wrong with that request. Please try again.