本文整理汇总了Python中gdrivefs.conf.Conf类的典型用法代码示例。如果您正苦于以下问题:Python Conf类的具体用法?Python Conf怎么用?Python Conf使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Conf类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __build_stat_from_entry
def __build_stat_from_entry(self, entry):
(uid, gid, pid) = fuse_get_context()
if entry.is_directory:
effective_permission = int(Conf.get("default_perm_folder"), 8)
elif entry.editable:
effective_permission = int(Conf.get("default_perm_file_editable"), 8)
else:
effective_permission = int(Conf.get("default_perm_file_noneditable"), 8)
stat_result = {
"st_mtime": entry.modified_date_epoch, # modified time.
"st_ctime": entry.modified_date_epoch, # changed time.
"st_atime": time(),
"st_uid": uid,
"st_gid": gid,
}
if entry.is_directory:
# Per http://sourceforge.net/apps/mediawiki/fuse/index.php?title=SimpleFilesystemHowto,
# default size should be 4K.
# TODO(dustin): Should we just make this (0), since that's what it is?
stat_result["st_size"] = 1024 * 4
stat_result["st_mode"] = stat.S_IFDIR | effective_permission
stat_result["st_nlink"] = 2
else:
stat_result["st_size"] = DisplacedFile.file_size if entry.requires_mimetype else entry.file_size
stat_result["st_mode"] = stat.S_IFREG | effective_permission
stat_result["st_nlink"] = 1
stat_result["st_blocks"] = int(math.ceil(float(stat_result["st_size"]) / 512.0))
return stat_result
示例2: __init__
def __init__(self):
cache_filepath = Conf.get('auth_cache_filepath')
api_credentials = Conf.get('api_credentials')
self.cache_filepath = cache_filepath
self.credentials = None
with NamedTemporaryFile() as f:
json.dump(api_credentials, f)
f.flush()
self.flow = flow_from_clientsecrets(f.name,
scope=self.__get_scopes(),
redirect_uri=OOB_CALLBACK_URN)
示例3: __init__
def __init__(self):
self.__log = logging.getLogger().getChild('OauthAuth')
cache_filepath = Conf.get('auth_cache_filepath')
api_credentials = Conf.get('api_credentials')
self.cache_filepath = cache_filepath
with NamedTemporaryFile() as f:
json.dump(api_credentials, f)
f.flush()
self.flow = flow_from_clientsecrets(f.name,
scope=self.__get_scopes(),
redirect_uri=OOB_CALLBACK_URN)
示例4: get_client
def get_client(self):
if self.__client is None:
authed_http = self.get_authed_http()
# Build a client from the passed discovery document path
discoveryUrl = Conf.get('google_discovery_service_url')
# TODO: We should cache this, since we have, so often, had a problem
# retrieving it. If there's no other way, grab it directly, and then pass
# via a file:// URI.
try:
client = build(_CONF_SERVICE_NAME,
_CONF_SERVICE_VERSION,
http=authed_http,
discoveryServiceUrl=discoveryUrl)
except HttpError as e:
# We've seen situations where the discovery URL's server is down,
# with an alternate one to be used.
#
# An error here shouldn't leave GDFS in an unstable state (the
# current command should just fail). Hoepfully, the failure is
# momentary, and the next command succeeds.
_logger.exception("There was an HTTP response-code of (%d) while "
"building the client with discovery URL [%s].",
e.resp.status, discoveryUrl)
raise
self.__client = client
return self.__client
示例5: deposit_file
def deposit_file(self, mime_type):
"""Write the file to a temporary path, and present a stub (JSON) to the
user. This is the only way of getting files that don't have a
well-defined filesize without providing a type, ahead of time.
"""
temp_path = Conf.get('file_download_temp_path')
file_path = ("%s/displaced/%s.%s" % (temp_path,
self.__normalized_entry.title,
mime_type.replace('/', '+')))
try:
result = drive_proxy('download_to_local',
output_file_path=file_path,
normalized_entry=self.__normalized_entry,
mime_type=mime_type)
(length, cache_fault) = result
except:
self.__log.exception("Could not localize displaced file with "
"entry having ID [%s]." %
(self.__normalized_entry.id))
raise
self.__log.debug("Displaced entry [%s] deposited to [%s] with length "
"(%d)." %
(self.__normalized_entry, file_path, length))
try:
return self.get_stub(mime_type, length, file_path)
except:
self.__log.exception("Could not build stub for [%s]." %
(self.__normalized_entry))
raise
示例6: __check_changes
def __check_changes(self):
_logger.info("Change-processing thread running.")
interval_s = Conf.get('change_check_frequency_s')
cm = get_change_manager()
while self.__t_quit_ev.is_set() is False and \
gdrivefs.state.GLOBAL_EXIT_EVENT.is_set() is False:
_logger.debug("Checking for changes.")
try:
is_done = cm.process_updates()
except:
_logger.exception("Squelching an exception that occurred "
"while reading/processing changes.")
# Force another check, soon.
is_done = False
# If there are still more changes, take them as quickly as
# possible.
if is_done is True:
_logger.debug("No more changes. Waiting.")
time.sleep(interval_s)
else:
_logger.debug("There are more changes to be applied. Cycling "
"immediately.")
_logger.info("Change-processing thread terminating.")
示例7: get_temp_filepath
def get_temp_filepath(normalized_entry, mime_type):
temp_filename = ("%s.%s" %
(normalized_entry.id, mime_type.replace('/', '+'))).\
encode('ascii')
temp_path = Conf.get('file_download_temp_path')
return ("%s/local/%s" % (temp_path, temp_filename))
示例8: is_visible
def is_visible(self):
if [ flag
for flag, value
in self.labels.items()
if flag in Conf.get('hidden_flags_list_local') and value ]:
return False
else:
return True
示例9: create_directory
def create_directory(self, filename, parents, **kwargs):
mimetype_directory = Conf.get('directory_mimetype')
return self.__insert_entry(
False,
filename,
parents,
mimetype_directory,
**kwargs)
示例10: __create
def __create(self, filepath, mode=None):
"""Create a new file.
We don't implement "mode" (permissions) because the model doesn't agree
with GD.
"""
# TODO: Fail if it already exists.
try:
result = split_path(filepath, path_resolver)
(parent_clause, path, filename, mime_type, is_hidden) = result
except GdNotFoundError:
_logger.exception("Could not process [%s] (i-create).", filepath)
raise FuseOSError(ENOENT)
except:
_logger.exception("Could not split path [%s] (i-create).",
filepath)
raise FuseOSError(EIO)
distilled_filepath = build_filepath(path, filename)
# Try to guess at a mime-type, if not otherwise given.
if mime_type is None:
(mimetype_guess, _) = guess_type(filename, True)
if mimetype_guess is not None:
mime_type = mimetype_guess
else:
mime_type = Conf.get('default_mimetype')
gd = get_gdrive()
try:
entry = gd.create_file(
filename,
[parent_clause[3]],
mime_type,
is_hidden=is_hidden)
except:
_logger.exception("Could not create empty file [%s] under "
"parent with ID [%s].",
filename, parent_clause[3])
raise FuseOSError(EIO)
path_relations = PathRelations.get_instance()
try:
path_relations.register_entry(entry)
except:
_logger.exception("Could not register created file in cache.")
raise FuseOSError(EIO)
_logger.info("Inner-create of [%s] completed.", distilled_filepath)
return (entry, path, filename, mime_type)
示例11: __get_entries_to_update
def __get_entries_to_update(self, requested_entry_id):
# Get more entries than just what was requested, while we're at it.
try:
parent_ids = drive_proxy('get_parents_containing_id',
child_id=requested_entry_id)
except:
self.__log.exception("Could not retrieve parents for child with ID "
"[%s]." % (requested_entry_id))
raise
self.__log.debug("Found (%d) parents." % (len(parent_ids)))
affected_entries = [ requested_entry_id ]
considered_entries = { }
max_readahead_entries = Conf.get('max_readahead_entries')
for parent_id in parent_ids:
self.__log.debug("Retrieving children for parent with ID [%s]." %
(parent_id))
try:
child_ids = drive_proxy('get_children_under_parent_id',
parent_id=parent_id)
except:
self.__log.exception("Could not retrieve children for parent with"
" ID [%s]." % (requested_entry_id))
raise
self.__log.debug("(%d) children found under parent with ID [%s]." %
(len(child_ids), parent_id))
for child_id in child_ids:
if child_id == requested_entry_id:
continue
# We've already looked into this entry.
try:
considered_entries[child_id]
continue
except:
pass
considered_entries[child_id] = True
# Is it already cached?
if self.cache.exists(child_id):
continue
affected_entries.append(child_id)
if len(affected_entries) >= max_readahead_entries:
break
return affected_entries
示例12: _sched_check_changes
def _sched_check_changes():
logging.debug("Doing scheduled check for changes.")
get_change_manager().process_updates()
# Schedule next invocation.
t = Timer(Conf.get('change_check_frequency_s'), _sched_check_changes)
Timers.get_instance().register_timer('change', t)
示例13: __emit_log
def __emit_log(self):
for source_name, source_data in self.data.iteritems():
pairs = [ ("%s= [%s]" % (k, v))
for k, v
in source_data.iteritems() ]
logging.info("RPT EMIT(%s): %s" % (source_name, ', '.join(pairs)))
report_emit_interval_s = Conf.get('report_emit_frequency_s')
emit_timer = Timer(report_emit_interval_s, self.__emit_log)
Timers.get_instance().register_timer('emit', emit_timer)
示例14: __post_status
def __post_status(self):
"""Send the current status to our reporting tool."""
num_values = self.registry.count(self.resource_name)
self.report.set_values(self.report_source_name, 'count',
num_values)
status_post_interval_s = Conf.get('cache_status_post_frequency_s')
status_timer = Timer(status_post_interval_s, self.__post_status)
Timers.get_instance().register_timer('status', status_timer)
示例15: __load_mappings
def __load_mappings(self):
# Allow someone to override our default mappings of the GD types.
gd_to_normal_mapping_filepath = \
Conf.get('gd_to_normal_mapping_filepath')
try:
with open(gd_to_normal_mapping_filepath, 'r') as f:
self.gd_to_normal_mime_mappings.extend(json.load(f))
except:
logging.info("No mime-mapping was found.")
# Allow someone to set file-extensions for mime-types, and not rely on
# Python's educated guesses.
extension_mapping_filepath = Conf.get('extension_mapping_filepath')
try:
with open(extension_mapping_filepath, 'r') as f:
self.default_extensions.extend(json.load(f))
except:
logging.info("No extension-mapping was found.")