def get_config_files(): """ return the path to the config files or and empty list. The search path is based on the paths returned by load_config_paths but it's returned in reverse order (e.g: /etc/xdg first). """ config_files = [] for xdg_config_dir in load_config_paths("ubuntuone"): xdg_config_dir = native_path(xdg_config_dir) config_file = os.path.join(xdg_config_dir, CONFIG_FILE) if os.path.exists(config_file): config_files.append(config_file) config_logs = os.path.join(xdg_config_dir, CONFIG_LOGS) if os.path.exists(config_logs): config_files.append(config_logs) # reverse the list as load_config_paths returns the user dir first config_files.reverse() # if we are running from a branch, get the config files from it too config_file = os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir, "data", CONFIG_FILE) if os.path.exists(config_file): config_files.append(config_file) config_logs = os.path.join("data", CONFIG_LOGS) if os.path.exists(config_logs): config_files.append(config_logs) return config_files
def __init__(self, root_dir, shares_dir, data_dir, partials_dir, host='fs-1.one.ubuntu.com', port=443, dns_srv=None, ssl=True, disable_ssl_verify=False, mark_interval=120, broadcast_events=False, handshake_timeout=30, shares_symlink_name='Shared With Me', read_limit=None, write_limit=None, throttling_enabled=False, ignore_files=None, oauth_credentials=None): self.root_dir = root_dir self.shares_dir = shares_dir self.shares_dir_link = os.path.join(self.root_dir, shares_symlink_name) self.data_dir = data_dir self.partials_dir = partials_dir tritcask_dir = os.path.join(self.data_dir, 'tritcask') self.logger = logging.getLogger('ubuntuone.SyncDaemon.Main') user_config = config.get_user_config() if read_limit is None: read_limit = user_config.get_throttling_read_limit() if write_limit is None: write_limit = user_config.get_throttling_write_limit() if not throttling_enabled: throttling_enabled = user_config.get_throttling() self.logger.info("Starting Ubuntu One client version %s", clientdefs.VERSION) self.logger.info("Using %r as root dir", self.root_dir) self.logger.info("Using %r as data dir", self.data_dir) self.logger.info("Using %r as shares root dir", self.shares_dir) self.db = tritcask.Tritcask(native_path(tritcask_dir)) self.vm = volume_manager.VolumeManager(self) self.fs = filesystem_manager.FileSystemManager( data_dir, partials_dir, self.vm, self.db) self.event_q = event_queue.EventQueue(self.fs, ignore_files) self.fs.register_eq(self.event_q) # subscribe VM to EQ, to be unsubscribed in shutdown self.event_q.subscribe(self.vm) self.vm.init_root() # we don't have the oauth tokens yet, we 'll get them later self.action_q = action_queue.ActionQueue(self.event_q, self, host, port, dns_srv, ssl, disable_ssl_verify, read_limit, write_limit, throttling_enabled) self.hash_q = hash_queue.HashQueue(self.event_q) events_nanny.DownloadFinishedNanny(self.fs, self.event_q, self.hash_q) # call StateManager after having AQ self.state_manager = StateManager(self, handshake_timeout) self.sync = sync.Sync(self) self.lr = local_rescan.LocalRescan(self.vm, self.fs, self.event_q, self.action_q) self.external = SyncdaemonService(main=self, send_events=broadcast_events) self.external.oauth_credentials = oauth_credentials if user_config.get_autoconnect(): self.external.connect(autoconnecting=True) self.eventlog_listener = None self.start_event_logger() self.status_listener = None self.start_status_listener() self.mark = task.LoopingCall(self.log_mark) self.mark.start(mark_interval)
del new_tcp # end of naming shenanigans CONFIG_FILE = "syncdaemon.conf" CONFIG_LOGS = "logging.conf" # sections THROTTLING = "bandwidth_throttling" NOTIFICATIONS = "notifications" MAIN = "__main__" # global logger logger = logging.getLogger("ubuntuone.SyncDaemon.config") # get (and possibly create if don't exists) the user config file _user_config_path = os.path.join(native_path(save_config_path("ubuntuone")), CONFIG_FILE) # module private config instance. # this object is the shared config _user_config = None path_from_unix = lambda path: path.replace("/", os.path.sep) def home_dir_parser(value): """Parser for the root_dir and shares_dir options. Return the path using user home + value. """ path = path_from_unix(value)
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR # PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program. If not, see <http://www.gnu.org/licenses/>. # # In addition, as a special exception, the copyright holders give # permission to link the code of portions of this program with the # OpenSSL library under certain conditions as described in each # individual source file, and distribute linked combinations # including the two. # You must obey the GNU General Public License in all respects # for all of the code used other than OpenSSL. If you modify # file(s) with this exception, you may extend this exception to your # version of the file(s), but you are not obligated to do so. If you # do not wish to do so, delete this exception statement from your # version. If you delete this exception statement from all source # files in the program, then also delete it here. """Defines a constant for ubuntuone's log folder based on XDG.""" import os from ubuntu_sso.xdg_base_directory import xdg_cache_home, native_path # All usage of the ubuntuone_log_dir is for native access, # so we only change it here ubuntuone_log_dir = os.path.join(xdg_cache_home, 'ubuntuone', 'log') ubuntuone_log_dir = native_path(ubuntuone_log_dir) if not os.path.exists(ubuntuone_log_dir): os.makedirs(ubuntuone_log_dir)