本文整理汇总了Python中pyaid.json.JSON.JSON类的典型用法代码示例。如果您正苦于以下问题:Python JSON类的具体用法?Python JSON怎么用?Python JSON使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JSON类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
def run(self):
"""Doc..."""
resources = self._compiler.resources
#-------------------------------------------------------------------------------------------
# RESOURCES
# If no resource folders were specified copy the entire contents of the resources
# folder. Make sure to skip the local resources path in the process.
if not resources:
for item in os.listdir(PyGlassEnvironment.getRootResourcePath(isDir=True)):
itemPath = PyGlassEnvironment.getRootResourcePath(item)
if os.path.isdir(itemPath) and not item in ['local', 'apps']:
resources.append(item)
for container in resources:
parts = container.replace('\\', '/').split('/')
self._copyResourceFolder(
PyGlassEnvironment.getRootResourcePath(*parts, isDir=True), parts)
#-------------------------------------------------------------------------------------------
# APP RESOURCES
appResources = self._compiler.resourceAppIds
if not appResources:
appResources = []
for appResource in appResources:
itemPath = PyGlassEnvironment.getRootResourcePath('apps', appResource, isDir=True)
if not os.path.exists(itemPath):
self._log.write('[WARNING]: No such app resource path found: %s' % appResource)
continue
self._copyResourceFolder(itemPath, ['apps', appResource])
#-------------------------------------------------------------------------------------------
# PYGLASS RESOURCES
# Copy the resources from the PyGlass
resources = []
for item in os.listdir(PyGlassEnvironment.getPyGlassResourcePath('..', isDir=True)):
itemPath = PyGlassEnvironment.getPyGlassResourcePath('..', item)
if os.path.isdir(itemPath):
resources.append(item)
for container in resources:
self._copyResourceFolder(
PyGlassEnvironment.getPyGlassResourcePath('..', container), [container])
# Create a stamp file in resources for comparing on future installations
creationStampFile = FileUtils.makeFilePath(self._targetPath, 'install.stamp')
JSON.toFile(creationStampFile, {'CTS':TimeUtils.toZuluPreciseTimestamp()})
#-------------------------------------------------------------------------------------------
# CLEANUP
if self._verbose:
self._log.write('CLEANUP: Removing unwanted destination files.')
self._cleanupFiles(self._targetPath)
self._copyPythonStaticResources()
if self._verbose:
self._log.write('COMPLETE: Resource Collection')
return True
示例2: _deployResources
def _deployResources(cls):
""" On windows the resource folder data is stored within the application install directory.
However, due to permissions issues, certain file types cannot be accessed from that
directory without causing the program to crash. Therefore, the stored resources must
be expanded into the user's AppData/Local folder. The method checks the currently
deployed resources folder and deploys the stored resources if the existing resources
either don't exist or don't match the currently installed version of the program. """
if not OsUtils.isWindows() or not PyGlassEnvironment.isDeployed:
return False
storagePath = PyGlassEnvironment.getInstallationPath('resource_storage', isDir=True)
storageStampPath = FileUtils.makeFilePath(storagePath, 'install.stamp')
resourcePath = PyGlassEnvironment.getRootResourcePath(isDir=True)
resourceStampPath = FileUtils.makeFilePath(resourcePath, 'install.stamp')
try:
resousrceData = JSON.fromFile(resourceStampPath)
storageData = JSON.fromFile(storageStampPath)
if resousrceData['CTS'] == storageData['CTS']:
return False
except Exception as err:
pass
SystemUtils.remove(resourcePath)
FileUtils.mergeCopy(storagePath, resourcePath)
return True
示例3: _createSetupFile
def _createSetupFile(self, binPath):
path = FileUtils.createPath(binPath, 'setup.py', isFile=True)
scriptPath = inspect.getabsfile(self.applicationClass)
try:
sourcePath = PyGlassEnvironment.getPyGlassResourcePath(
'..', 'setupSource.txt', isFile=True)
f = open(sourcePath, 'r+')
source = f.read()
f.close()
except Exception as err:
print(err)
return None
try:
f = open(path, 'w+')
f.write(source.replace(
'##SCRIPT_PATH##', StringUtils.escapeBackSlashes(scriptPath)
).replace(
'##RESOURCES##', StringUtils.escapeBackSlashes(JSON.asString(self.resources))
).replace(
'##INCLUDES##', StringUtils.escapeBackSlashes(JSON.asString(self.siteLibraries))
).replace(
'##ICON_PATH##', StringUtils.escapeBackSlashes(self._createIcon(binPath))
).replace(
'##APP_NAME##', self.appDisplayName
).replace(
'##SAFE_APP_NAME##', self.appDisplayName.replace(' ', '_') ))
f.close()
except Exception as err:
print(err)
return None
return path
示例4: write
def write(self, session, path, pretty =False, gzipped =True, difference =True):
if self.results is None and not self.process(session, difference):
return False
try:
JSON.toFile(path, self.results, pretty=pretty, gzipped=gzipped, throwError=True)
return True
except Exception as err:
self.logger.writeError([
u'ERROR: Unable to write export file',
u'PATH: ' + StringUtils.toUnicode(path)], err)
return False
示例5: _writeError
def _writeError(self, data):
""" Writes import error data to the logger, formatting it for human readable display. """
source = {}
if 'data' in data:
for n,v in DictUtils.iter(data['data']):
source[' '.join(n.split('_')).title()] = v
indexPrefix = ''
if 'index' in data:
indexPrefix = ' [INDEX: %s]:' % data.get('index', 'Unknown')
result = [
'IMPORT ERROR%s: %s' % (indexPrefix, data['message']),
'DATA: ' + DictUtils.prettyPrint(source)]
if 'existing' in data:
source = {}
snapshot = data['existing'].snapshot
if snapshot:
snapshot = JSON.fromString(snapshot)
if snapshot:
for n,v in DictUtils.iter(snapshot):
source[' '.join(n.split('_')).title()] = v
result.append('CONFLICT: ' + DictUtils.prettyPrint(source))
if 'error' in data:
self._logger.writeError(result, data['error'])
else:
self._logger.write(result)
示例6: __init__
def __init__(self, site):
""" Creates a new instance of RobotFileGenerator """
self.site = site
try:
self._data = JSON.fromFile(self.definitionPath)
except Exception, err:
self._data = [{'USER_AGENT':'*'}]
示例7: add
def add(self, *args, **kwargs):
"""Adds value to the existing item, replacing existing entries.
@@@param value:string
The value argument can be a single value.
@@@param group:string
The name of the group in which to add the value. Default of None adds the value to the
root group.
"""
value = ArgsUtils.get('value', None, kwargs, args, 0)
if value is None:
value = u''
elif isinstance(value, dict) or isinstance(value, list):
value = JSON.asString(value)
else:
value = unicode(value)
group = ArgsUtils.get('group', None, kwargs, args, 1)
once = ArgsUtils.get('once', False, kwargs)
if group:
target = self._tempSubs if once else self._subs
target[group] = value
else:
if once:
self._tempRoot = value
else:
self._root = value
示例8: _setEnvValue
def _setEnvValue(cls, key, value):
settings = cls._getEnvValue(None) if cls._ENV_SETTINGS is None else cls._ENV_SETTINGS
if settings is None:
settings = dict()
cls._ENV_SETTINGS = settings
if isinstance(key, basestring):
key = [key]
src = settings
for k in key[:-1]:
src = src[k]
src[key[-1]] = value
envPath = cls.getRootLocalResourcePath(cls._GLOBAL_SETTINGS_FILE, isFile=True)
envDir = os.path.dirname(envPath)
if not os.path.exists(envDir):
os.makedirs(envDir)
f = open(envPath, 'w+')
try:
f.write(JSON.asString(cls._ENV_SETTINGS))
except Exception, err:
print 'ERROR: Unable to write environmental settings file at: ' + envPath
return False
示例9: __init__
def __init__(self, containerPath, isRemoteDeploy =False, sourceRootFolder ='src', **kwargs):
"""Creates a new instance of Site."""
super(Site, self).__init__()
self.errorCount = 0
self.warningCount = 0
self._staticPaths = []
self._logger = ArgsUtils.getLogger(self, kwargs)
self._sourceRootFolderName = sourceRootFolder
# NGinx root path in which all files reside
self._containerPath = FileUtils.cleanupPath(containerPath, isDir=True)
# Location of the source files used to create the website
self._sourceWebRootPath = FileUtils.createPath(containerPath, sourceRootFolder, isDir=True)
# Locations where files should be deployed. If the target root path is None, which is the
# default value, the local web root path is used in its place.
if isRemoteDeploy:
self._targetWebRootPath = FileUtils.cleanupPath(
tempfile.mkdtemp(prefix='staticFlow_'), isDir=True)
else:
self._targetWebRootPath = None
self._localWebRootPath = FileUtils.createPath(
containerPath, ArgsUtils.get('localRootFolder', 'root', kwargs), isDir=True)
path = FileUtils.createPath(self.sourceWebRootPath, '__site__.def', isFile=True)
try:
self._data.data = JSON.fromFile(path, throwError=True)
except Exception, err:
self.writeLogError(u'Unable to load site definition file: "%s"' % path, error=err)
pass
示例10: _writeImpl
def _writeImpl(self, value, *args, **kwargs):
if not value:
return u''
elif isinstance(value, dict) or isinstance(value, list):
value = JSON.asString(value)
elif not isinstance(value, basestring):
value = str(value)
value = value.replace("'", "\'").replace('\n',' ')
offset = value.find('\'')
while offset != -1:
if offset == 0 or value[offset-1] != '\\':
value = value[:offset] + '\\' + value[offset:]
offset = value.find('\'', offset + 1)
if not value:
kwargs['writeEmpty'] = False
for j in self._joins:
v = j.write(*args, **kwargs)
if v:
return v
if not ArgsUtils.get('writeEmpty', True, kwargs):
return None
return u'%s=\'%s\'' % (self._name, value)
示例11: get
def get(cls, url, config):
"""Returns the embedding object for the specified URL and config."""
try:
req = requests.get(config['url'] + '?url=' + urllib2.quote(url) + '&format=json')
return JSON.fromString(req.text)
except Exception, err:
return None
示例12: _parseData
def _parseData(self, data):
if not data:
return None
try:
return JSON.fromString(data)
except Exception, err:
return data
示例13: _saveSettings
def _saveSettings(self):
if self._settings is None:
return
if not JSON.toFile(self._path, self._settings, pretty=self._pretty):
print 'ERROR: Unable to save application settings file: ' + self._path
return False
return True
示例14: flush
def flush(self):
if not self._buffer:
return
if sys.platform.startswith('win'):
return
items = []
for b in self._buffer:
try:
d = DictUtils.merge(self._meta, b['data'])
item = b['prefix'] + ' ' + JSON.asString(d)
except Exception as err:
item = '>> EXCEPTION: JSON ENCODING FAILED >> ' + str(err).replace('\n', '\t')
try:
item = item.encode('utf8', 'ignore')
except Exception as err:
item = '>> EXCEPTION: UNICODE DECODING FAILED >> ' + str(err).replace('\n', '\t')
items.append(item)
count = self._fileCount
offset = random.randint(0, count - 1)
success = False
path = self.getReportFolder() + self._timeCode + '/'
if not os.path.exists(path):
os.makedirs(path)
for i in range(count):
index = (i + offset) % count
p = path + str(index) + '.report'
lock = FileLock(p)
if lock.i_am_locking() and i < count - 1:
continue
try:
lock.acquire()
except Exception:
continue
try:
out = StringUtils.toUnicode('\n'.join(items) + '\n')
f = open(p, 'a+')
f.write(out.encode('utf8'))
f.close()
success = True
except Exception as err:
print("REPORTER ERROR: Unable to write report file.")
print(err)
lock.release()
if success:
break
self.clear()
return success
示例15: _loadBuildSnapshot
def _loadBuildSnapshot(self):
settings = SettingsConfig(CompilerDeckEnvironment.projectSettingsPath, pretty=True)
snap = settings.get(['BUILD', 'LAST_SNAPSHOT'])
if snap is None:
return
try:
self._buildSnapshot = JSON.fromString(snap)
except Exception, err:
pass