Add script to extract and gather analytics event names.

// FREEBIE
pull/1/head
Matthew Chen 7 years ago
parent e9cf39a4c4
commit 31ab9a00da

@ -82,8 +82,8 @@
34D8C0281ED3673300188D7C /* DebugUITableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D8C0261ED3673300188D7C /* DebugUITableViewController.m */; };
34D8C02B1ED3685800188D7C /* DebugUIContacts.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D8C02A1ED3685800188D7C /* DebugUIContacts.m */; };
34D99C8C1F27B13B00D284D6 /* OWSViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D99C8B1F27B13B00D284D6 /* OWSViewController.m */; };
34D99C8E1F28DDCD00D284D6 /* OWSSwiftUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34D99C8D1F28DDCD00D284D6 /* OWSSwiftUtils.swift */; };
34D99C901F29067D00D284D6 /* OWSSwiftUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34D99C8D1F28DDCD00D284D6 /* OWSSwiftUtils.swift */; };
34D99C931F2937CC00D284D6 /* OWSAnalytics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34D99C911F2937CC00D284D6 /* OWSAnalytics.swift */; };
34D99C941F2937CC00D284D6 /* OWSSwiftUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34D99C921F2937CC00D284D6 /* OWSSwiftUtils.swift */; };
34DFCB851E8E04B500053165 /* AddToBlockListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34DFCB841E8E04B500053165 /* AddToBlockListViewController.m */; };
34E3E5681EC4B19400495BAC /* AudioProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34E3E5671EC4B19400495BAC /* AudioProgressView.swift */; };
34E3EF0D1EFC235B007F6822 /* DebugUIDiskUsage.m in Sources */ = {isa = PBXBuildFile; fileRef = 34E3EF0C1EFC235B007F6822 /* DebugUIDiskUsage.m */; };
@ -513,7 +513,8 @@
34D8C02A1ED3685800188D7C /* DebugUIContacts.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DebugUIContacts.m; sourceTree = "<group>"; };
34D99C8A1F27B13B00D284D6 /* OWSViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSViewController.h; sourceTree = "<group>"; };
34D99C8B1F27B13B00D284D6 /* OWSViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSViewController.m; sourceTree = "<group>"; };
34D99C8D1F28DDCD00D284D6 /* OWSSwiftUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OWSSwiftUtils.swift; sourceTree = "<group>"; };
34D99C911F2937CC00D284D6 /* OWSAnalytics.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OWSAnalytics.swift; sourceTree = "<group>"; };
34D99C921F2937CC00D284D6 /* OWSSwiftUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OWSSwiftUtils.swift; sourceTree = "<group>"; };
34DFCB831E8E04B400053165 /* AddToBlockListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AddToBlockListViewController.h; sourceTree = "<group>"; };
34DFCB841E8E04B500053165 /* AddToBlockListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AddToBlockListViewController.m; sourceTree = "<group>"; };
34E3E5671EC4B19400495BAC /* AudioProgressView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AudioProgressView.swift; sourceTree = "<group>"; };
@ -1356,6 +1357,7 @@
BFB074C619A5611000F2947C /* ObservableValue.m */,
76EB04EE18170B33006006FC /* Operation.h */,
76EB04EF18170B33006006FC /* Operation.m */,
34D99C911F2937CC00D284D6 /* OWSAnalytics.swift */,
34D5CC941EA6AFAD005515DB /* OWSContactsSyncing.h */,
34D5CC951EA6AFAD005515DB /* OWSContactsSyncing.m */,
45CD81F01DC03A22004C9430 /* OWSLogger.h */,
@ -1363,7 +1365,7 @@
34009B651EC4CB11001D95D1 /* OWSMath.h */,
45666F541D9B2827008FE134 /* OWSScrubbingLogFormatter.h */,
45666F551D9B2827008FE134 /* OWSScrubbingLogFormatter.m */,
34D99C8D1F28DDCD00D284D6 /* OWSSwiftUtils.swift */,
34D99C921F2937CC00D284D6 /* OWSSwiftUtils.swift */,
4579431C1E7C8CE9008ED0C0 /* Pastelog.h */,
4579431D1E7C8CE9008ED0C0 /* Pastelog.m */,
450DF2041E0D74AC003D14BE /* Platform.swift */,
@ -2106,6 +2108,7 @@
34B3F8741E8DF1700035BE1A /* AttachmentSharing.m in Sources */,
34D8C02B1ED3685800188D7C /* DebugUIContacts.m in Sources */,
45C9DEB81DF4E35A0065CA84 /* WebRTCCallMessageHandler.swift in Sources */,
34D99C931F2937CC00D284D6 /* OWSAnalytics.swift in Sources */,
34B3F88E1E8DF1700035BE1A /* PrivacySettingsTableViewController.m in Sources */,
4505C2C21E648F7A00CEBF41 /* ExperienceUpgradeFinder.swift in Sources */,
34E3EF0D1EFC235B007F6822 /* DebugUIDiskUsage.m in Sources */,
@ -2236,7 +2239,6 @@
3448BFD01EDF0EA7005B2D69 /* MessagesViewController.m in Sources */,
34CCAF3B1F0C2748004084F4 /* OWSAddToContactViewController.m in Sources */,
45F659731E1BD99C00444429 /* CallKitCallUIAdaptee.swift in Sources */,
34D99C8E1F28DDCD00D284D6 /* OWSSwiftUtils.swift in Sources */,
45BB93381E688E14001E3939 /* UIDevice+featureSupport.swift in Sources */,
458DE9D61DEE3FD00071BB03 /* PeerConnectionClient.swift in Sources */,
451DE9FD1DC1A28200810E42 /* SyncPushTokensJob.swift in Sources */,
@ -2269,6 +2271,7 @@
34B3F88B1E8DF1700035BE1A /* OWSLinkedDevicesTableViewController.m in Sources */,
45666F7E1D9C0814008FE134 /* OWSDatabaseMigrationRunner.m in Sources */,
4579431E1E7C8CE9008ED0C0 /* Pastelog.m in Sources */,
34D99C941F2937CC00D284D6 /* OWSSwiftUtils.swift in Sources */,
34B3F8941E8DF1710035BE1A /* SignalsViewController.m in Sources */,
34E8BF381EE9E2FD00F5F4CA /* FingerprintViewScanController.m in Sources */,
76EB058818170B33006006FC /* PropertyListPreferences.m in Sources */,
@ -2285,7 +2288,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
34D99C901F29067D00D284D6 /* OWSSwiftUtils.swift in Sources */,
4505C2C31E648F7A00CEBF41 /* ExperienceUpgradeFinder.swift in Sources */,
456F6E241E24133E00FD2210 /* CallKitCallUIAdaptee.swift in Sources */,
451DA3C81F14898E008E2423 /* Strings.swift in Sources */,

@ -81,11 +81,6 @@ enum CallError: Error {
// Should be roughly synced with Android client for consistency
fileprivate let connectingTimeoutSeconds = 120
func OWSProdCallAssertionError(description: String, file: String, function: String, line: Int32) -> CallError {
OWSProdError(description, file:file, function:function, line:line)
return .assertionError(description: description)
}
// All Observer methods will be invoked from the main thread.
protocol CallServiceObserver: class {
/**
@ -278,7 +273,8 @@ protocol CallServiceObserver: class {
let errorDescription = "\(TAG) call was unexpectedly already set."
Logger.error(errorDescription)
call.state = .localFailure
return Promise(error: OWSProdCallAssertionError(description: errorDescription, file:#file, function:#function, line:#line))
OWSProdError("call_service_call_already_set", file:#file, function:#function, line:#line)
return Promise(error: .assertionError(errorDescription))
}
self.call = call
@ -300,7 +296,8 @@ protocol CallServiceObserver: class {
guard self.peerConnectionClient == nil else {
let errorDescription = "\(self.TAG) peerconnection was unexpectedly already set."
Logger.error(errorDescription)
throw OWSProdCallAssertionError(description: errorDescription, file:#file, function:#function, line:#line)
OWSProdError("call_service_peer_connection_already_set", file:#file, function:#function, line:#line)
throw .assertionError(errorDescription)
}
let useTurnOnly = Environment.getCurrent().preferences.doCallsHideIPAddress()
@ -376,7 +373,8 @@ protocol CallServiceObserver: class {
}
guard let fulfillReadyToSendIceUpdatesPromise = self.fulfillReadyToSendIceUpdatesPromise else {
self.handleFailedCall(failedCall: call, error: OWSProdCallAssertionError(description: "failed to create fulfillReadyToSendIceUpdatesPromise", file:#file, function:#function, line:#line))
OWSProdError("call_service_missing_fulfill_ready_to_send_ice_updates_promise", file:#file, function:#function, line:#line)
self.handleFailedCall(failedCall: call, error: .assertionError("failed to create fulfillReadyToSendIceUpdatesPromise"))
return
}
@ -414,7 +412,8 @@ protocol CallServiceObserver: class {
}
guard let peerConnectionClient = self.peerConnectionClient else {
handleFailedCall(failedCall: call, error: OWSProdCallAssertionError(description: "peerConnectionClient was unexpectedly nil in \(#function)", file:#file, function:#function, line:#line))
OWSProdError("call_service_peer_connection_missing", file:#file, function:#function, line:#line)
handleFailedCall(failedCall: call, error: .assertionError("peerConnectionClient was unexpectedly nil in \(#function)"))
return
}
@ -702,7 +701,8 @@ protocol CallServiceObserver: class {
AssertIsOnMainThread()
guard let call = self.call else {
self.handleFailedCurrentCall(error: OWSProdCallAssertionError(description: "ignoring local ice candidate, since there is no current call.", file:#file, function:#function, line:#line))
OWSProdError("call_service_call_missing", file:#file, function:#function, line:#line)
self.handleFailedCurrentCall(error: .assertionError("ignoring local ice candidate, since there is no current call."))
return
}
@ -717,7 +717,8 @@ protocol CallServiceObserver: class {
guard call.state != .idle else {
// This will only be called for the current peerConnectionClient, so
// fail the current call.
self.handleFailedCurrentCall(error: OWSProdCallAssertionError(description: "ignoring local ice candidate, since call is now idle.", file:#file, function:#function, line:#line))
OWSProdError("call_service_call_unexpectedly_idle", file:#file, function:#function, line:#line)
self.handleFailedCurrentCall(error: .assertionError("ignoring local ice candidate, since call is now idle."))
return
}
@ -753,7 +754,8 @@ protocol CallServiceObserver: class {
guard let call = self.call else {
// This will only be called for the current peerConnectionClient, so
// fail the current call.
handleFailedCurrentCall(error: OWSProdCallAssertionError(description:"\(TAG) ignoring \(#function) since there is no current call.", file:#file, function:#function, line:#line))
OWSProdError("call_service_call_missing", file:#file, function:#function, line:#line)
handleFailedCurrentCall(error: .assertionError("\(TAG) ignoring \(#function) since there is no current call."))
return
}
@ -822,14 +824,16 @@ protocol CallServiceObserver: class {
guard let call = self.call else {
// This should never happen; return to a known good state.
owsFail("\(TAG) call was unexpectedly nil in \(#function)")
handleFailedCurrentCall(error: OWSProdCallAssertionError(description:"\(TAG) call was unexpectedly nil in \(#function)", file:#file, function:#function, line:#line))
OWSProdError("call_service_call_missing", file:#file, function:#function, line:#line)
handleFailedCurrentCall(error: .assertionError("\(TAG) call was unexpectedly nil in \(#function)"))
return
}
guard call.localId == localId else {
// This should never happen; return to a known good state.
owsFail("\(TAG) callLocalId:\(localId) doesn't match current calls: \(call.localId)")
handleFailedCurrentCall(error: OWSProdCallAssertionError(description:"\(TAG) callLocalId:\(localId) doesn't match current calls: \(call.localId)", file:#file, function:#function, line:#line))
OWSProdError("call_service_call_id_mismatch", file:#file, function:#function, line:#line)
handleFailedCurrentCall(error: .assertionError("\(TAG) callLocalId:\(localId) doesn't match current calls: \(call.localId)"))
return
}
@ -845,7 +849,8 @@ protocol CallServiceObserver: class {
Logger.debug("\(TAG) in \(#function)")
guard let currentCall = self.call else {
handleFailedCall(failedCall: call, error: OWSProdCallAssertionError(description:"\(TAG) ignoring \(#function) since there is no current call", file:#file, function:#function, line:#line))
OWSProdError("call_service_call_missing", file:#file, function:#function, line:#line)
handleFailedCall(failedCall: call, error: .assertionError("\(TAG) ignoring \(#function) since there is no current call"))
return
}
@ -857,7 +862,8 @@ protocol CallServiceObserver: class {
}
guard let peerConnectionClient = self.peerConnectionClient else {
handleFailedCall(failedCall: call, error: OWSProdCallAssertionError(description:"\(TAG) missing peerconnection client in \(#function)", file:#file, function:#function, line:#line))
OWSProdError("call_service_peer_connection_missing", file:#file, function:#function, line:#line)
handleFailedCall(failedCall: call, error: .assertionError("\(TAG) missing peerconnection client in \(#function)"))
return
}
@ -882,7 +888,8 @@ protocol CallServiceObserver: class {
AssertIsOnMainThread()
guard let peerConnectionClient = self.peerConnectionClient else {
handleFailedCall(failedCall: call, error: OWSProdCallAssertionError(description:"\(TAG) peerConnectionClient unexpectedly nil in \(#function)", file:#file, function:#function, line:#line))
OWSProdError("call_service_peer_connection_missing", file:#file, function:#function, line:#line)
handleFailedCall(failedCall: call, error: .assertionError("\(TAG) peerConnectionClient unexpectedly nil in \(#function)"))
return
}
@ -912,14 +919,16 @@ protocol CallServiceObserver: class {
guard let call = self.call else {
// This should never happen; return to a known good state.
owsFail("\(TAG) call was unexpectedly nil in \(#function)")
handleFailedCurrentCall(error: OWSProdCallAssertionError(description:"\(TAG) call was unexpectedly nil in \(#function)", file:#file, function:#function, line:#line))
OWSProdError("call_service_call_missing", file:#file, function:#function, line:#line)
handleFailedCurrentCall(error: .assertionError("\(TAG) call was unexpectedly nil in \(#function)"))
return
}
guard call.localId == localId else {
// This should never happen; return to a known good state.
owsFail("\(TAG) callLocalId:\(localId) doesn't match current calls: \(call.localId)")
handleFailedCurrentCall(error: OWSProdCallAssertionError(description:"\(TAG) callLocalId:\(localId) doesn't match current calls: \(call.localId)", file:#file, function:#function, line:#line))
OWSProdError("call_service_call_id_mismatch", file:#file, function:#function, line:#line)
handleFailedCurrentCall(error: .assertionError("\(TAG) callLocalId:\(localId) doesn't match current calls: \(call.localId)"))
return
}
@ -958,17 +967,20 @@ protocol CallServiceObserver: class {
AssertIsOnMainThread()
guard let currentCall = self.call else {
handleFailedCall(failedCall: call, error: OWSProdCallAssertionError(description:"\(TAG) ignoring \(#function) since there is no current call", file:#file, function:#function, line:#line))
OWSProdError("call_service_call_missing", file:#file, function:#function, line:#line)
handleFailedCall(failedCall: call, error: .assertionError("\(TAG) ignoring \(#function) since there is no current call"))
return
}
guard call == currentCall else {
handleFailedCall(failedCall: call, error: OWSProdCallAssertionError(description:"\(TAG) ignoring \(#function) for call other than current call", file:#file, function:#function, line:#line))
OWSProdError("call_service_call_mismatch", file:#file, function:#function, line:#line)
handleFailedCall(failedCall: call, error: .assertionError("\(TAG) ignoring \(#function) for call other than current call"))
return
}
guard let peerConnectionClient = self.peerConnectionClient else {
handleFailedCall(failedCall: call, error: OWSProdCallAssertionError(description:"\(TAG) missing peerconnection client in \(#function)", file:#file, function:#function, line:#line))
OWSProdError("call_service_peer_connection_missing", file:#file, function:#function, line:#line)
handleFailedCall(failedCall: call, error: .assertionError("\(TAG) missing peerconnection client in \(#function)"))
return
}
@ -1008,7 +1020,8 @@ protocol CallServiceObserver: class {
guard let call = self.call else {
// This should never happen; return to a known good state.
owsFail("\(TAG) call was unexpectedly nil in \(#function)")
handleFailedCurrentCall(error: OWSProdCallAssertionError(description:"\(TAG) call unexpectedly nil in \(#function)", file:#file, function:#function, line:#line))
OWSProdError("call_service_call_missing", file:#file, function:#function, line:#line)
handleFailedCurrentCall(error: .assertionError("\(TAG) call unexpectedly nil in \(#function)"))
return
}
@ -1062,7 +1075,8 @@ protocol CallServiceObserver: class {
guard let call = self.call else {
// This should never happen; return to a known good state.
owsFail("\(TAG) call was unexpectedly nil in \(#function)")
handleFailedCurrentCall(error: OWSProdCallAssertionError(description:"\(TAG) call unexpectedly nil in \(#function)", file:#file, function:#function, line:#line))
OWSProdError("call_service_call_missing", file:#file, function:#function, line:#line)
handleFailedCurrentCall(error: .assertionError("\(TAG) call unexpectedly nil in \(#function)"))
return
}
@ -1100,7 +1114,8 @@ protocol CallServiceObserver: class {
guard let call = self.call else {
// This should never happen; return to a known good state.
owsFail("\(TAG) received data message, but there is no current call. Ignoring.")
handleFailedCurrentCall(error: OWSProdCallAssertionError(description:"\(TAG) received data message, but there is no current call. Ignoring.", file:#file, function:#function, line:#line))
OWSProdError("call_service_call_missing", file:#file, function:#function, line:#line)
handleFailedCurrentCall(error: .assertionError("\(TAG) received data message, but there is no current call. Ignoring."))
return
}
@ -1112,7 +1127,8 @@ protocol CallServiceObserver: class {
guard connected.id == call.signalingId else {
// This should never happen; return to a known good state.
owsFail("\(TAG) received connected message for call with id:\(connected.id) but current call has id:\(call.signalingId)")
handleFailedCurrentCall(error: OWSProdCallAssertionError(description:"\(TAG) received connected message for call with id:\(connected.id) but current call has id:\(call.signalingId)", file:#file, function:#function, line:#line))
OWSProdError("call_service_call_id_mismatch", file:#file, function:#function, line:#line)
handleFailedCurrentCall(error: .assertionError("\(TAG) received connected message for call with id:\(connected.id) but current call has id:\(call.signalingId)"))
return
}
@ -1127,7 +1143,8 @@ protocol CallServiceObserver: class {
guard hangup.id == call.signalingId else {
// This should never happen; return to a known good state.
owsFail("\(TAG) received hangup message for call with id:\(hangup.id) but current call has id:\(call.signalingId)")
handleFailedCurrentCall(error: OWSProdCallAssertionError(description:"\(TAG) received hangup message for call with id:\(hangup.id) but current call has id:\(call.signalingId)", file:#file, function:#function, line:#line))
OWSProdError("call_service_call_id_mismatch", file:#file, function:#function, line:#line)
handleFailedCurrentCall(error: .assertionError("\(TAG) received hangup message for call with id:\(hangup.id) but current call has id:\(call.signalingId)"))
return
}
@ -1234,7 +1251,8 @@ protocol CallServiceObserver: class {
}
guard let readyToSendIceUpdatesPromise = self.readyToSendIceUpdatesPromise else {
return Promise(error: OWSProdCallAssertionError(description: "failed to create readyToSendIceUpdatesPromise", file:#file, function:#function, line:#line))
OWSProdError("call_service_could_not_create_ready_to_send_ice_updates_promise", file:#file, function:#function, line:#line)
return Promise(error: .assertionError("failed to create readyToSendIceUpdatesPromise"))
}
return readyToSendIceUpdatesPromise
@ -1277,7 +1295,8 @@ protocol CallServiceObserver: class {
}
guard let peerConnectionClientPromise = self.peerConnectionClientPromise else {
return Promise(error: OWSProdCallAssertionError(description: "failed to create peerConnectionClientPromise", file:#file, function:#function, line:#line))
OWSProdError("call_service_could_not_create_peer_connection_client_promise", file:#file, function:#function, line:#line)
return Promise(error: .assertionError("failed to create peerConnectionClientPromise"))
}
return peerConnectionClientPromise

@ -0,0 +1,11 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
import Foundation
func OWSProdError(_ eventName: String, file: String, function: String, line: Int32) {
let location = "\((file as NSString).lastPathComponent):\(function)"
OWSAnalytics
.logEvent(eventName, severity: .error, parameters: nil, location: (location as NSString).utf8String!, line:line)
}

@ -3,10 +3,6 @@
//
import Foundation
//import PromiseKit
//import WebRTC
// MARK: Helpers
/**
* We synchronize access to state in this class using this queue.
@ -24,10 +20,3 @@ func owsFail(_ message: String) {
Logger.flush()
assertionFailure(message)
}
// Example: OWSProdError("blah", #file, #function, #line)
func OWSProdError(_ eventName: String, file: String, function: String, line: Int32) {
let location = "\((file as NSString).lastPathComponent):\(function)"
OWSAnalytics
.logEvent(eventName, severity: .error, parameters: nil, location: (location as NSString).utf8String!, line:line)
}

@ -0,0 +1,208 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import subprocess
import datetime
import argparse
import commands
import re
git_repo_path = os.path.abspath(subprocess.check_output(['git', 'rev-parse', '--show-toplevel']).strip())
def splitall(path):
allparts = []
while 1:
parts = os.path.split(path)
if parts[0] == path: # sentinel for absolute paths
allparts.insert(0, parts[0])
break
elif parts[1] == path: # sentinel for relative paths
allparts.insert(0, parts[1])
break
else:
path = parts[0]
allparts.insert(0, parts[1])
return allparts
def process(filepath, macros):
short_filepath = filepath[len(git_repo_path):]
if short_filepath.startswith(os.sep):
short_filepath = short_filepath[len(os.sep):]
filename = os.path.basename(filepath)
if filename.startswith('.'):
return
if filename == 'OWSAnalytics.h':
return
file_ext = os.path.splitext(filename)[1]
is_swift = file_ext in ('.swift')
if is_swift:
macros = macros + ['OWSProdCallAssertionError',]
# print 'macros', macros
if file_ext in ('.swift'):
# env_copy = os.environ.copy()
# env_copy["SCRIPT_INPUT_FILE_COUNT"] = "1"
# env_copy["SCRIPT_INPUT_FILE_0"] = '%s' % ( short_filepath, )
# lint_output = subprocess.check_output(['swiftlint', 'autocorrect', '--use-script-input-files'], env=env_copy)
# print lint_output
# try:
# lint_output = subprocess.check_output(['swiftlint', 'lint', '--use-script-input-files'], env=env_copy)
# except subprocess.CalledProcessError, e:
# lint_output = e.output
# print lint_output
pass
# print short_filepath, is_swift
with open(filepath, 'rt') as f:
text = f.read()
position = 0
has_printed_filename = False
while True:
best_match = None
best_macro = None
for macro in macros:
pattern = r'''%s\(([^,\)]+)[,\)]''' % macro
# print '\t pattern', pattern
matcher = re.compile(pattern)
# matcher = re.compile(r'#define (OWSProd)')
match = matcher.search(text, pos=position)
if match:
event_name = match.group(1).strip()
# Ignore swift func definitions
if is_swift and ':' in event_name:
continue
# print '\t', 'event_name', event_name
if not best_match:
pass
elif best_match.start(1) > match.start(1):
pass
else:
continue
best_match = match
best_macro = macro
# TODO:
if not best_match:
break
event_name = best_match.group(1).strip()
if not has_printed_filename:
has_printed_filename = True
print short_filepath
print '\t', 'event_name', event_name
position = best_match.end(1)
# macros.append(macro)
# break
return
with open(filepath, 'rt') as f:
text = f.read()
original_text = text
lines = text.split('\n')
while lines and lines[0].startswith('//'):
lines = lines[1:]
text = '\n'.join(lines)
text = text.strip()
header = '''//
// Copyright (c) %s Open Whisper Systems. All rights reserved.
//
''' % (
datetime.datetime.now().year,
)
text = header + text + '\n'
if original_text == text:
return
print 'Updating:', short_filepath
with open(filepath, 'wt') as f:
f.write(text)
def should_ignore_path(path):
ignore_paths = [
os.path.join(git_repo_path, '.git')
]
for ignore_path in ignore_paths:
if path.startswith(ignore_path):
return True
for component in splitall(path):
if component.startswith('.'):
return True
if component.endswith('.framework'):
return True
if component in ('Pods', 'ThirdParty', 'Carthage',):
return True
return False
def process_if_appropriate(filepath, macros):
filename = os.path.basename(filepath)
if filename.startswith('.'):
return
file_ext = os.path.splitext(filename)[1]
if file_ext not in ('.h', '.hpp', '.cpp', '.m', '.mm', '.pch', '.swift'):
return
if should_ignore_path(filepath):
return
process(filepath, macros)
def extract_macros(filepath):
macros = []
with open(filepath, 'rt') as f:
text = f.read()
lines = text.split('\n')
for line in lines:
# Match lines of this form:
# #define OWSProdCritical(__eventName) ...
matcher = re.compile(r'#define (OWSProd[^\(]+)\(.+[,\)]')
# matcher = re.compile(r'#define (OWSProd)')
match = matcher.search(line)
if match:
macro = match.group(1).strip()
# print 'macro', macro
macros.append(macro)
return macros
if __name__ == "__main__":
# print 'git_repo_path', git_repo_path
macros_header_file_path = os.path.join(git_repo_path, 'SignalServiceKit', 'src', 'Util', 'OWSAnalytics.h')
if not os.path.exists(macros_header_file_path):
print 'Macros header does not exist:', macros_header_file_path
sys.exit(1)
macros = extract_macros(macros_header_file_path)
print 'macros:', macros
for rootdir, dirnames, filenames in os.walk(git_repo_path):
for filename in filenames:
file_path = os.path.abspath(os.path.join(rootdir, filename))
process_if_appropriate(file_path, macros)

@ -299,7 +299,9 @@ NSString *NSStringForOWSAnalyticsSeverity(OWSAnalyticsSeverity severity)
- (void)addEvent:(NSString *)eventName severity:(OWSAnalyticsSeverity)severity properties:(NSDictionary *)properties
{
OWSAssert(eventName.length > 0);
OWSAssert(properties);
#ifndef NO_SIGNAL_ANALYTICS
BOOL isError = severity == OWSAnalyticsSeverityError;
BOOL isCritical = severity == OWSAnalyticsSeverityCritical;
@ -309,7 +311,6 @@ NSString *NSStringForOWSAnalyticsSeverity(OWSAnalyticsSeverity severity)
return;
}
#ifndef NO_SIGNAL_ANALYTICS
void (^addEvent)() = ^{
// Add super properties.
NSMutableDictionary *eventProperties = (properties ? [properties mutableCopy] : [NSMutableDictionary new]);

@ -0,0 +1,7 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
NS_ASSUME_NONNULL_END

@ -0,0 +1,10 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "OWSAnalyticsEvents.h"
NS_ASSUME_NONNULL_BEGIN
NS_ASSUME_NONNULL_END
Loading…
Cancel
Save