Exemplo n.º 1
0
 def start(self, extension_port):
     '''Starts Firefox at extension_port. If start up fails, it cleans up 
     and returns False, otherwise returns the associated extension 
     instance.
     '''
     profile_path = os.path.join(crawlglobs.tmp_dir, config.PROFILE_DIR,
                                 "ff_" + str(extension_port))
     self.profile(profile_path, extension_port)
     if not os.path.isdir(self.profile_dir):
         raise Exception('No profile')
     self.process = subprocess.Popen(
         ['firefox', '-no-remote', '-profile', self.profile_dir])
     self.logger.debug("Starting extention.")
     ext = extension.Extension(self.logger, port=extension_port)
     if not ext.reset():
         self.logger.error(("Extension could not be restarted for " +
                            "Firefox instance at port %s. \n Cleaning up " +
                            "that instance.") % extension_port)
         self.cleanup()
         return False
     return ext
Exemplo n.º 2
0
def startswith_command(input_, invoice_):
    # Possible Return Values:
    # 1. ["continue", "continue"]
    if input_.startswith('pr '):
        no_of_prints = int(input_.split("pr ")[1])
        if no_of_prints < 3:
            invoice_.update_invoice_with_sub_total()
            # create pdf of invoice
            sale_report.create_(invoice_, 'A6', no_of_print=no_of_prints)
    if input_.startswith('lr '):
        transport_lr_no = input_.split(" ")[1]
        invoice_.transport_lr_no = transport_lr_no
        cf.log_("transport_lr_no is {}".format(transport_lr_no))
        cf.cursor_(sql.SQL(
            "update {} set (transport_lr_no) = (%s) where id = %s returning id"
        ).format(sql.Identifier(invoice_.invoice_type)),
                   arguments=(transport_lr_no, invoice_.id))

    if input_.startswith('fr '):
        freight = input_.split(" ")[1]
        cf.log_("freight is {}".format(freight))
        try:
            if not float(freight).is_integer:
                freight = float(freight)
        except Exception as e:
            cf.log_(e)
            cf.log_("Incorrect value for freight")
            return {"arg1": "continue"}
        invoice_.set_freight(Decimal(freight))
        invoice_.update_invoice_with_sub_total()
        invoice_.view_invoice_details(invoice_.fetch_invoice_details())
    if input_.startswith('bn '):
        print('invoice_.gst_invoice_no is {}'.format(invoice_.gst_invoice_no))
        if invoice_.gst_invoice_no is None:
            barrel_nipple.BarrelNipple(input_, invoice_)
        else:
            barrel_nipple.BarrelNipple(input_, invoice_, gst_=True)

        invoice_.update_invoice_with_sub_total()
        invoice_.view_invoice_details(invoice_.fetch_invoice_details())
    if input_.startswith('ex '):
        print('invoice_.gst_invoice_no is {}'.format(invoice_.gst_invoice_no))
        if invoice_.gst_invoice_no is None:
            extension.Extension(input_, invoice_)
        else:
            extension.Extension(input_, invoice_, gst_=True)
        # after implementing init_by_id in invoice_detail, the following code can be used as starting point to see only the added Extension items
        '''
        id_result = ex.invoice_detail_id_list
        id_list = [element for tupl in id_result for element in tupl]
        cf.log_(id_list)
        temp_list = []
        for id_ in id_list:
            i_detail_ = invoice_detail.InvoiceDetail(invoice_, product_name, id_=id_list)
            temp_list.append(i_detail_.get_detail_values())
        cf.log_(temp_list)
        '''
        invoice_.update_invoice_with_sub_total()
        invoice_.view_invoice_details(invoice_.fetch_invoice_details())
    if input_.startswith(','):
        if input_ == ",,":
            return {"arg1": ","}
        return {"arg1": input_.split(",")[1]}
    return {"arg1": "continue"}
Exemplo n.º 3
0
	def scanExtensionsFirefox(self):

		#results
		results = []

		#get list of all firefox's profile directories
		# ->these contain profiles, that in turn, contain a file ('addons.json') about the extensions
		firefoxProfileDirectories = utils.expandPath(FIREFOX_PROFILE_DIRECTORY)

		#iterate over all extension profile directories
		# ->get list of 'addons.json' files
		for firefoxProfileDirectory in firefoxProfileDirectories:

			#get list of all 'addon.json'files
			firefoxExtensionFiles = glob.glob(firefoxProfileDirectory + '/*.default/addons.json')

			#open/parse each addon file
			# ->contains list of addons (extensions)
			for firefoxExtensionFile in firefoxExtensionFiles:

				#wrap
				try:

					#open extension file and load it
					with open(firefoxExtensionFile, 'r') as file:

						#load as JSON
						addons = json.loads(file.read())['addons']
						if not addons:

							#skip/try next
							continue

				#ignore exceptions
				except:

					#skip/try next
					continue

				#extract all addons
				for addon in addons:

					#dictionary for extension info
					extensionInfo = {}

					#wrap
					try:

						#extract id
						if 'id' in addon:

							#save
							extensionInfo['id'] = addon['id']

						#extract name
						if 'name' in addon:

							#save
							extensionInfo['name'] = addon['name']

						#extract description
						if 'description' in addon:

							#save
							extensionInfo['description'] = addon['description'].replace('\n', ' ')

						#build path
						# ->should be in the extensions/ folder, under <id>.XPI
						path = os.path.split(firefoxExtensionFile)[0] + '/extensions/' + addon['id'] + '.xpi'

						#ignore .xpi's that don't exist
						if not os.path.exists(path):

							#skip
							continue

						#save path
						extensionInfo['path'] = path

						#create and append addon (extension)
						results.append(extension.Extension(extensionInfo))

					#ignore exceptions
					except Exception, e:

						print e
						traceback.print_exc()

						#skip/try next
						continue
Exemplo n.º 4
0
	def scanExtensionsChrome(self):

		#results
		results = []

		#get list of all chrome's preferences file
		# ->these contain JSON w/ info about all extensions
		chromePreferences = utils.expandPaths(CHROME_DIRECTORIES)

		#parse each for extensions
		for chromePreferenceFile in chromePreferences:

			#wrap
			try:

				#open preference file and load it
				with open(chromePreferenceFile, 'r') as file:

					#load as JSON
					preferences = json.loads(file.read())
					if not preferences:

						#skip/try next
						continue

				#the list of extensions are stored in the 'settings' key
				extensions = preferences['extensions']['settings']

				#scan all extensions
				# ->skip ones that are disabled, white listed, etc
				# TODO: skip ones that don't exist (path)
				for extensionKey in extensions:

					#dictionary for extension info
					extensionInfo = {}

					#save key
					extensionInfo['id'] = extensionKey

					#get extension dictionary
					currentExtension = extensions[extensionKey]

					#skip extensions if they are disabled
					# ->'state' set to 0 means disabled
					if 'state' in currentExtension and not currentExtension['state']:

						#skip
						continue

					#skip extensions that are installed by default
					# ->assuming these are legit/ok
					if 'was_installed_by_default' in currentExtension and currentExtension['was_installed_by_default']:

						#skip
						continue

					#extract manifest
					# ->contains name, description, etc
					if 'manifest' in currentExtension:

						manifest = currentExtension['manifest']
						if manifest:

							#extract name
							if 'name' in manifest:

								#name
								extensionInfo['name'] = manifest['name']

							#extract description
							if 'description' in manifest:

								#description
								extensionInfo['description'] = manifest['description']

					#extract path
					if 'path' in currentExtension:

						#create full path
						extensionInfo['path'] = os.path.dirname(chromePreferenceFile) + '/Extensions/' + currentExtension['path']

					#create and append
					results.append(extension.Extension(extensionInfo))

			#ignore exceptions
			except Exception, e:

				print e
				traceback.print_exc()


				#skip/try next
				continue
Exemplo n.º 5
0
	def scanExtensionsSafari(self):

		#results
		results = []

		#get list of all chrome's preferences file
		# ->these contain JSON w/ info about all extensions
		safariExtensionFiles = utils.expandPath(SAFARI_EXTENSION_DIRECTORY)

		#parse each for extensions
		for safariExtensionFile in safariExtensionFiles:

			#wrap
			try:

				#load extension file
				plistData = utils.loadPlist(safariExtensionFile)

				#ensure data looks ok
				if not plistData or 'Installed Extensions' not in plistData:

						#skip/try next
						continue

				#the list of extensions are stored in the 'settings' key
				extensions = plistData['Installed Extensions']

				#scan all extensions
				# ->skip ones that are disabled, white listed, etc
				for currentExtension in extensions:

					#dictionary for extension info
					extensionInfo = {}

					#skip disabled plugins
					if 'Enabled' in currentExtension and not currentExtension['Enabled']:

						#skip
						continue

					#extract path
					if 'Archive File Name' in currentExtension:

						#name
						extensionInfo['path'] = safariExtensionFile + '/' + currentExtension['Archive File Name']

					#extract name
					if 'Bundle Directory Name' in currentExtension:

						#path
						extensionInfo['name'] = currentExtension['Bundle Directory Name']

					#create and append
					results.append(extension.Extension(extensionInfo))

			#ignore exceptions
			except Exception, e:

				print e
				traceback.print_exc()


				#skip/try next
				continue
Exemplo n.º 6
0
	def scanExtensionsFirefox(self):

		#results
		results = []

		#dictionary of extension IDs
		# ->needed since they can show up in both addons.json and extensions.json
		extensionIDs = []

		#get list of all firefox's profile directories
		# ->these contain profiles, that in turn, contain a files ('addons.json/extensions.json') about the extensions
		firefoxProfileDirectories = utils.expandPath(FIREFOX_PROFILE_DIRECTORY)

		#iterate over all addons and extensions files in profile directories
		# ->extact all addons and extensions
		for firefoxProfileDirectory in firefoxProfileDirectories:

			#get list of all 'addon.json' files
			firefoxExtensionFiles = glob.glob(firefoxProfileDirectory + '/*.default*/addons.json')

			#and also all 'extensions.json' files
			firefoxExtensionFiles.extend(glob.glob(firefoxProfileDirectory + '/*.default*/extensions.json'))

			#open/parse each addon file
			# ->contains list of addons (extensions)
			for firefoxExtensionFile in firefoxExtensionFiles:

				#wrap
				try:

					#open extension file and load it
					with open(firefoxExtensionFile, 'r') as file:

						#load as JSON
						addons = json.loads(file.read())['addons']
						if not addons:

							#skip/try next
							continue

				#ignore exceptions
				except:

					#skip/try next
					continue

				#extract all addons/extensions
				# ->in both addons and extensions json files, called addons :/
				for addon in addons:

					#dictionary for addon/extension info
					extensionInfo = {}

					#wrap
					try:

						#extract id
						if 'id' in addon:

							#save
							extensionInfo['id'] = addon['id']

						#skip duplicates
						# ->extensions can show up in addons.json and extensions.json
						if addon['id'] in extensionIDs:

							#skip dupe
							continue

						#json in addons.json file is formatted one way
						if 'addons.json' == os.path.split(firefoxExtensionFile)[1]:

							#extract name
							if 'name' in addon:

								#save
								extensionInfo['name'] = addon['name']

							#extract description
							if 'description' in addon:

								#save
								extensionInfo['description'] = addon['description'].replace('\n', ' ')

							#build path
							# ->should be in the extensions/ folder, under <id>.XPI
							path = os.path.split(firefoxExtensionFile)[0] + '/extensions/' + addon['id'] + '.xpi'

							#ignore .xpi's that don't exist
							if not os.path.exists(path):

								#skip
								continue

							#save path
							extensionInfo['path'] = path

						#json in extensions.json file is formatted another way
						else:

							#extract name
							if 'defaultLocale' in addon and 'name' in addon['defaultLocale']:

								#save
								extensionInfo['name'] = addon['defaultLocale']['name']

							#extract description
							if 'defaultLocale' in addon and 'description' in addon['defaultLocale']:

								#save
								extensionInfo['description'] = addon['defaultLocale']['description']

							#build path
							# ->should be a directory in the extensions/ folder, under <id>
							path = os.path.split(firefoxExtensionFile)[0] + '/extensions/' + addon['id']

							#ignore those that don't exist
							if not os.path.exists(path):

								#skip
								continue

							#save path
							extensionInfo['path'] = path

						#save extension id
						# ->used to prevent dupes
						extensionIDs.append(extensionInfo['id'])

						#create and append addon (extension)
						results.append(extension.Extension(extensionInfo))

					#ignore exceptions
					except Exception, e:

						#leave in err msg (for now)
						print e
						traceback.print_exc()

						#skip/try next
						continue
Exemplo n.º 7
0
	def scanExtensionsChrome(self):

		#results
		results = []

		#get list of all chrome's preferences file
		# ->these contain JSON w/ info about all extensions
		chromePreferences = utils.expandPaths(CHROME_DIRECTORIES)

		#parse each for extensions
		for chromePreferenceFile in chromePreferences:

			#wrap
			try:

				#open preference file and load it
				with open(chromePreferenceFile, 'r') as file:

					#load as JSON
					preferences = json.loads(file.read())
					if not preferences:

						#skip/try next
						continue

				#the list of extensions are stored in the 'settings' key
				extensions = preferences['extensions']['settings']

				#scan all extensions
				# ->skip ones that are disabled, white listed, etc
				for extensionKey in extensions:

					#dictionary for extension info
					extensionInfo = {}

					#save key
					extensionInfo['id'] = extensionKey

					#get extension dictionary
					currentExtension = extensions[extensionKey]

					#skip extensions if they are disabled
					# ->'state' set to 0 means disabled
					if 'state' in currentExtension and not currentExtension['state']:

						#skip
						continue

					#skip extensions that are installed by default
					# ->assuming these are legit/ok
					if 'was_installed_by_default' in currentExtension and currentExtension['was_installed_by_default']:

						#skip
						continue

					#extract manifest
					# ->contains name, description, etc
					if 'manifest' in currentExtension:

						manifest = currentExtension['manifest']
						if manifest:

							#extract name
							if 'name' in manifest:

								#name
								extensionInfo['name'] = manifest['name']

							#extract description
							if 'description' in manifest:

								#description
								extensionInfo['description'] = manifest['description']

					#extract path
					if 'path' in currentExtension:

						#sometimes path is (already) full path
						# e.g. /Applications/Google Chrome.app/.../Google Chrome Framework.framework/Resources/<blah>
						if os.path.exists(currentExtension['path']):

							#save
							extensionInfo['path'] = currentExtension['path']

						#generally though the full path has to be built
						else:

							#build full path
							extensionInfo['path'] = os.path.dirname(chromePreferenceFile) + '/Extensions/' + currentExtension['path']

						#ignore path's that don't exist
						# ->uninstallers may not clean up things correctly
						if not os.path.exists(extensionInfo['path']):

							#skip
							continue

					#create and append
					results.append(extension.Extension(extensionInfo))

			#ignore exceptions
			except Exception, e:

				#leave in err msg (for now)
				print e
				traceback.print_exc()

				#skip/try next
				continue
Exemplo n.º 8
0
    def scanExtensionsChrome(self):

        #results
        results = []

        #get list of all chrome's preferences file
        # ->these contain JSON w/ info about all extensions
        chromePreferences = utils.expandPaths(CHROME_DIRECTORIES)

        #parse each for extensions
        for chromePreferenceFile in chromePreferences:

            #wrap
            try:

                #open preference file and load it
                with open(chromePreferenceFile, 'r') as file:

                    #load as JSON
                    preferences = json.loads(file.read())
                    if not preferences:

                        #skip/try next
                        continue

                # pref file just has the list of ids,
                # everything else we might want is in
                # os.path.dirname(chromePreferenceFile) + '/Extensions/' + id + version + manifest.json
                # manifest has name, description

                extensions = preferences['extensions']['install_signature'][
                    'ids']

                #scan all extensions
                # ->skip ones that are disabled, white listed, etc
                for extensionKey in extensions:

                    #dictionary for extension info
                    extensionInfo = {}

                    #save key
                    extensionInfo['id'] = extensionKey
                    extensionPath = os.path.dirname(
                        chromePreferenceFile
                    ) + '/Extensions/' + extensionInfo['id']

                    extdir = os.listdir(extensionPath)
                    for verdir in extdir:
                        manpath = extensionPath + '/' + verdir + '/manifest.json'

                        with open(manpath, 'r') as file:
                            manifest = json.loads(file.read())
                            if not manifest:
                                continue

                        extensionInfo['path'] = manpath
                        extensionInfo['name'] = manifest['name']
                        extensionInfo['description'] = manifest['description']

                        #create and append
                        results.append(extension.Extension(extensionInfo))

            #ignore exceptions
            except Exception, e:

                #leave in err msg (for now)
                print e
                traceback.print_exc()

                #skip/try next
                continue