def save_metadata(self, root_dir, starting_dir, json_file): ''' Save the metadata from the starting_dir. >>> from blockchain_backup.bitcoin.tests import utils as test_utils >>> test_utils.init_database() >>> backup_task = BackupTask() >>> backup_task.manager = BitcoinManager(backup_task.log_name) >>> backup_task.prep_backup() >>> root_dir = backup_task.manager.data_dir >>> json_filename = os.path.join('/tmp', constants.METADATA_FILENAME) >>> with open(json_filename, 'w') as json_file: ... backup_task.save_metadata(root_dir, root_dir, json_file) >>> os.path.exists(json_filename) True ''' entries = os.scandir(starting_dir) for entry in entries: # there's no need to change the status of wallets if (entry.name.startswith(constants.DEFAULT_BACKUPS_DIR) or entry.name.startswith('wallet') or entry.name == '.walletlock'): pass else: # remove the root dir so if the directory is moved, everything still works path = entry.path.replace(root_dir, '') stat_result = os.stat(entry.path) stats_dict = { 'st_mode': stat_result.st_mode, 'st_ino': stat_result.st_ino, 'st_dev': stat_result.st_dev, 'st_nlink': stat_result.st_nlink, 'st_uid': stat_result.st_uid, 'st_gid': stat_result.st_gid, 'st_size': stat_result.st_size, 'st_atime': stat_result.st_atime, 'st_mtime': stat_result.st_mtime, 'st_ctime': stat_result.st_ctime } if is_windows(): stats_dict[ 'st_file_attributes'] = stat_result.st_file_attributes file_stats = json.dumps([path, stats_dict]) json_file.write(f'{file_stats}\n') if entry.is_dir() and entry.name != 'wallets': self.save_metadata(root_dir, entry.path, json_file)
def bitcoin_tx(): ''' Name of bitcoin-tx program. >>> bitcoin_tx() 'bitcoin-tx' ''' program = 'bitcoin-tx' if is_windows(): program += '.exe' return program
def bitcoind(): ''' Name of bitcoind program. >>> bitcoind() 'bitcoind' ''' program = 'bitcoind' if is_windows(): program += '.exe' return program
def bitcoin_cli(): ''' Name of bitcoin-cli program. >>> bitcoin_cli() 'bitcoin-cli' ''' program = 'bitcoin-cli' if is_windows(): program += '.exe' return program
def bitcoin_qt(): ''' Name of bitcoin-qt program. >>> bitcoin_qt() 'bitcoin-qt' ''' program = 'bitcoin-qt' if is_windows(): program += '.exe' return program
def config_time_zone(dirname): ''' Configure time zone if running on windows. >>> import shutil >>> CURRENT_DIR = os.path.abspath(os.path.dirname(__file__)) >>> parent_dir = os.path.dirname(os.path.dirname(CURRENT_DIR)) >>> dirname = '/tmp/blockchain_backup' >>> shutil.copy(os.path.join(parent_dir, 'denova', 'django_addons', 'settings_shared.py'), dirname) '/tmp/blockchain_backup' >>> config_time_zone('/tmp/blockchain_backup') ''' TIME_ZONE_PREFIX = 'TIME_ZONE = ' if is_windows(): filename = os.path.join(os.path.dirname(dirname), 'django_addons', 'settings_shared.py') if os.path.exists(filename): try: with open(filename, 'rt') as input_file: lines = input_file.readlines() with open(filename, 'wt') as output_file: for line in lines: if line.startswith(TIME_ZONE_PREFIX): tz = 'Atlantic/Reykjavik' line = f"{TIME_ZONE_PREFIX}'{tz}'\n" output_file.write(line) except Exception as e: log(e) raise else: log(f'{filename} not found')