Beispiel #1
0
def link_file(sub_dir: Path, card_dir: Path, file: Path, max_backup: int = 1):
    """Link one file from `sub_dir` into `base_dir` / `card_slot`.
    If `card_slot` doesn't exist, create it.

    Due to requiring `sub_dir` and `base_dir` for processing,
    `link_file` cannot be used in batch.

    Will automatically call `backup.backup()` per file.

    Args:
        sub_dir (str): the sub dir containing your saves elsewhere
        card_dir (Path): base_dir / 'GC' / region / card_slot
        file (Path): the file
        max_backup (int, optional): maximum circular backup count;
            defaults to 1; should always be >= 1

    Returns:
        bool: True if successful

    """
    linked = card_dir / file.name
    linked.symlink_to(save_file)
    print(f'Linked {save_file.name}!')
    backup.backup(save_file, max_backup=max_backup)

    return True
Beispiel #2
0
 def __init__(self):
     tk.Tk.__init__(self)
     if not config.get_db_path():
         config.set_db_path()
     if not config.get_backup_path():
         config.set_backup_path()
     if not config.get_session_path():
         config.set_session_path()
     db_type = config.get_db_type()
     if db_type == 'standard':
         db = Databases.StandardDatabase()
     else:
         db = Databases.TranslationDatabase(config.get_lang1(),
                                            config.get_lang2())
     config.active_objects['db'] = db
     config.active_objects[
         'root'] = self  #Allows access outside creation module
     backup.backup()
     self.option_add('*Font',
                     'TkDefaultFont')  #All widgets use default font
     if db_type == 'standard':
         self.main_frame = StandardMainFrame(self)
     else:
         self.main_frame = TranslationMainFrame(self)
     self.menu_bar = MenuBar(self)
     self['menu'] = self.menu_bar
     self.title(config.get_language_dict()['title'])  #Application name
     icon = Image.open('icons/30101621.png')
     icon = ImageTk.PhotoImage(icon)
     self.iconphoto(True, icon)
     self.set_geometry()
     self.bind_events()
Beispiel #3
0
def default_dir_force():
    old_time = os.stat(os.path.join(from_dir, '1.txt')).st_mtime
    write_file('1.txt', '2')
    os.utime(os.path.join(from_dir, '1.txt'), (old_time, old_time))
    backup.backup(from_dir, to_dir, compress=False, force=True)
    return os.path.exists(os.path.join(to_dir,
                                       '1.txt')) and read_file('1.txt') == '2'
Beispiel #4
0
def clean_tx(file_path):
    u = dict()
    rs = ''
    date_ok = True
    if not file_path.split('/')[-1].startswith('2018'):
        return
    with open(file_path, 'r') as f:
        print(f"Cleaning {file_path}")
        while True:
            line = f.readline()
            if not line:
                break
            if '0x' not in line:
                continue
            line = clean_date(line)
            h = line.split("Hash=")[1].split(
                ", ")[0] if "Hash=" in line else line.split(' ')[-1].strip(
                    '\n')
            if h not in u:
                date_ok = date_ok & try_parse_date(line)
                u[h] = 1
                rs += line
            else:
                continue
    if not date_ok:
        return
    with open(
            f"{file_path.split('/txs/')[0]}/txs/cleaned/{file_path.split('/txs/')[1]}",
            'w') as f:
        f.write(rs)
    backup(
        file_path,
        f"{file_path.split('/txs/')[0]}/txs/backup/{file_path.split('/txs/')[1]}"
    )
def clean_tx(file_path):
    u = dict()
    rs = ''
    date_ok = True
    filename = file_path.split('/')[-1]
    last_date = f'[{filename.split("_")[0]} {filename.split("_")[1].split(".")[0]}:00:00.015303602 +0000 UTC m=+196751.022868978]'
    with open(file_path, 'r') as f:
        print(f"Cleaning {file_path}")
        while True:
            line = f.readline()
            if not line:
                break
            if '0x' not in line:
                continue
            h = line.split("Hash=")[1].split(
                ", ")[0] if "Hash=" in line else line.split(' ')[-1].strip(
                    '\n')
            if h not in u:
                this_date_ok, line, last_date = try_parse_date(line, last_date)
                date_ok = date_ok & this_date_ok
                u[h] = 1
                rs += line
            else:
                continue
    if not date_ok:
        return
    with open(
            f"{file_path.split('/txs/')[0]}/txs/cleaned/{file_path.split('/txs/')[1]}",
            'w') as f:
        f.write(rs)
    backup(
        file_path,
        f"{file_path.split('/txs/')[0]}/txs/backup/{file_path.split('/txs/')[1]}"
    )
Beispiel #6
0
def main():
    stopstart.stop()
    time.sleep(stop_buffer)
    try:
        backup.backup()
    finally:
        stopstart.start()
Beispiel #7
0
def default_file_compress():
    write_file('a.txt', 'c')
    backup.backup(os.path.join(from_dir, 'a.txt'), to_dir, compress=True)
    members = get_tar_members('a.tgz')
    return os.path.exists(os.path.join(to_dir, 'a.tgz')) and \
        os.stat(os.path.join(from_dir, 'a.txt')).st_mtime == os.stat(os.path.join(to_dir, 'a.tgz')).st_mtime and \
        'a.txt' in members and len(members) == 1
Beispiel #8
0
def default_dir_exclude():
    backup.backup(from_dir,
                  to_dir,
                  exclude=['folder'],
                  compress=False,
                  compare_trees=True)
    return os.path.exists(os.path.join(to_dir, '1.txt')) and \
        len(os.listdir(to_dir)) == 1
Beispiel #9
0
def default_dir_compress():
    backup.backup(from_dir, to_dir, compress=True)
    members = get_tar_members(dir_name + '.tgz')
    return os.path.exists(os.path.join(to_dir, dir_name + '.tgz')) and \
        '1.txt' in members and \
        'folder' in members and \
        'folder/a.txt' in members and \
        len(members) == 3
 def on_new_backup(self):
     new_backup_name = dlg_get_text(_("New backup:"), _("New backup name"),
                                    "add_backup")
     new_backup_name = new_backup_name.ret
     if new_backup_name != None:
         new_backup = os.path.join(self.dialog.viewer.path, new_backup_name)
         backup(new_backup, get_sim_path())
         self.dialog.viewer.fill_store()
Beispiel #11
0
def run_backup(uuid, path):
  host = backup.get_hostname()
  if backup.test_backup_assertions(uuid, host, path):
    print '---=== starting backup:', uuid, path, '===---'
    try: backup.backup(uuid, host, path)
    except: traceback.print_exc()
  else:
    print '---=== skipped backup:', uuid, path, '===---'
 def test_backup_print_statement(self, mock_output):
     with open('random_file.txt', 'w') as f_obj:
         f_obj.write('random text')
     backup('random_file.txt')
     expected = 'generated random_file.bak\n'
     actual = mock_output.getvalue()
     self.assertEqual(expected, actual)
     os.remove('random_file.txt')
     os.remove('random_file.bak')
Beispiel #13
0
def default_file_existing():
    old_time = os.stat(os.path.join(from_dir, 'a.txt')).st_mtime
    backup.backup(os.path.join(from_dir, 'a.txt'), to_dir, compress=False)
    b1_time = os.stat(os.path.join(from_dir, 'a.txt')).st_mtime
    tick()
    write_file('a.txt', 'b')
    backup.backup(os.path.join(from_dir, 'a.txt'), to_dir, compress=False)
    b2_time = os.stat(os.path.join(from_dir, 'a.txt')).st_mtime
    return os.path.exists(os.path.join(from_dir, 'a.txt')) and \
        b1_time == old_time and b2_time > old_time
 def test_backup(self):
     with open('random_file.txt', 'w') as f_obj:
         f_obj.write('random text')
     backup('random_file.txt')
     with open('random_file.bak', 'r') as f_obj:
         actual = f_obj.read()
     expected = 'random text'
     self.assertEqual(expected, actual)
     os.remove('random_file.txt')
     os.remove('random_file.bak')
Beispiel #15
0
def process(transformation):
    while len(transformation):
        try:
            transformation.transform()
            backup(transformation)
            time.sleep(1)
        except Exception as e:
            exit(f"Une erreur est survenue désolé bro : {e}")
    os.remove("./temp/backup.bcp")
    return transformation
Beispiel #16
0
def run_backup(uuid, path):
    host = backup.get_hostname()
    if backup.test_backup_assertions(uuid, host, path):
        print '---=== starting backup:', uuid, path, '===---'
        try:
            backup.backup(uuid, host, path)
        except:
            traceback.print_exc()
    else:
        print '---=== skipped backup:', uuid, path, '===---'
Beispiel #17
0
def default_dir_exclude_compressed():
    backup.backup(from_dir,
                  to_dir,
                  exclude=['folder'],
                  compress=True,
                  force=True)
    members = get_tar_members(dir_name + '.tgz')
    return os.path.exists(os.path.join(to_dir, dir_name + '.tgz')) and \
        '1.txt' in members and \
        len(members) == 1
Beispiel #18
0
def run_all_backups():
  for t in backup.get_known_backups():
    uuid = t['uuid']
    host = t['host']
    path = t['path']
    if backup.test_backup_assertions(uuid, host, path):
      print '---=== starting backup:', uuid, path, '===---'
      try: backup.backup(uuid, host, path)
      except: traceback.print_exc()
    else:
      print '---=== skipped backup:', uuid, path, '===---'
Beispiel #19
0
def default_file_force():
    old_time = os.stat(os.path.join(from_dir, 'a.txt')).st_mtime
    write_file('a.txt', 'd')
    os.utime(os.path.join(from_dir, 'a.txt'), (old_time, old_time))
    backup.backup(os.path.join(from_dir, 'a.txt'),
                  to_dir,
                  compress=False,
                  force=True)
    return os.path.exists(os.path.join(to_dir, 'a.txt')) and \
        read_file('a.txt') == 'd' and \
        os.stat(os.path.join(from_dir, 'a.txt')).st_mtime == os.stat(os.path.join(to_dir, 'a.tgz')).st_mtime
Beispiel #20
0
def default_dir_new():
    os.mkdir(from_dir)
    write_file('1.txt', '1')
    mkdir('folder')
    write_file(os.path.join('folder', 'a.txt'), 'a')
    backup.backup(from_dir, to_dir, compress=False)
    return os.path.exists(to_dir) and \
        os.path.exists(os.path.join(to_dir, '1.txt')) and \
        os.path.exists(os.path.join(to_dir, 'folder')) and \
        os.path.exists(os.path.join(to_dir, 'folder', 'a.txt')) and \
        os.stat(os.path.join(to_dir, '1.txt')).st_mtime == os.stat(os.path.join(from_dir, '1.txt')).st_mtime and \
        os.stat(os.path.join(to_dir, 'folder')).st_mtime == os.stat(os.path.join(from_dir, 'folder')).st_mtime and \
        os.stat(os.path.join(to_dir, 'folder', 'a.txt')).st_mtime == os.stat(os.path.join(from_dir, 'folder', 'a.txt')).st_mtime
Beispiel #21
0
def run_all_backups():
    for t in backup.get_known_backups():
        uuid = t['uuid']
        host = t['host']
        path = t['path']
        if backup.test_backup_assertions(uuid, host, path):
            print '---=== starting backup:', uuid, path, '===---'
            try:
                backup.backup(uuid, host, path)
            except:
                traceback.print_exc()
        else:
            print '---=== skipped backup:', uuid, path, '===---'
Beispiel #22
0
    def create_backup(self):
        ''' Creates backup zip file ./watcher.zip

        Returns dict ajax-style response
        '''

        logging.info('Creating backup of Watcher as {}'.format(os.path.join(core.PROG_PATH, 'watcher.zip')))

        try:
            backup.backup(require_confirm=False)
        except Exception as e:
            logging.error('Unable to create backup.', exc_info=True)
            return {'response': False, 'error': str(e)}

        return {'response': True, 'message': _('Backup created as {}').format(os.path.join(core.PROG_PATH, 'watcher.zip'))}
Beispiel #23
0
    def __init__(self):

        #OBJETO DE BANCO DE DADOS
        self.bancoDados = bd()
        self.backup = backup()

        #OBEJTO DE CRIAÇÃO DE GRAFICOS
        self.graph = plotGraphs()

        #DEFAULT
        self.verdeClaro = 'Green'
        self.fontStyleUpper = 'Courier 20 bold'
        self.tomato = 'Tomato'
        self.gold = 'PaleGoldenrod'
        self.azulClaro = 'PowderBlue'
        self.fontDefault = 'Courier 12'
        self.fontTad = 'Coureir 12 bold'

        #MENU
        self.bgMenu = 'white'
        self.colorTaps = 'Red'
        self.colorBox = 'Green'
        self.colorInvestments = 'DarkCyan'

        #DATA ATUAL
        self.day = date.today().day
        self.month = date.today().month
        self.year = date.today().year

        #MES CORRENTE PARA PESQUISAS
        self.currentMonth = self.month
        self.currentYear = date.today().year

        #CALL WINDOW MAIN
        self.windowSpending()
Beispiel #24
0
 def saveDocument(self, doc):
     """ Saves the document, asking for a name if necessary.
     
     Returns True if saving succeeded.
     
     """
     if doc.url().isEmpty():
         return self.saveDocumentAs(doc)
     filename = dest = doc.url().toLocalFile()
     if not filename:
         dest = doc.url().toString()
     if not util.iswritable(filename):
         QMessageBox.warning(self, app.caption(_("Error")),
             _("Can't write to destination:\n\n{url}").format(url=dest))
         return False
     if QSettings().value("strip_trailing_whitespace", False, bool):
         import reformat
         reformat.remove_trailing_whitespace(QTextCursor(doc))
     b = backup.backup(filename)
     success = doc.save()
     if not success:
         QMessageBox.warning(self, app.caption(_("Error")),
             _("Can't write to destination:\n\n{url}").format(url=filename))
     elif b:
         backup.removeBackup(filename)
     return success
Beispiel #25
0
 def saveDocument(self, doc):
     """ Saves the document, asking for a name if necessary.
     
     Returns True if saving succeeded.
     
     """
     if doc.url().isEmpty():
         return self.saveDocumentAs(doc)
     filename = dest = doc.url().toLocalFile()
     if not filename:
         dest = doc.url().toString()
     if not util.iswritable(filename):
         QMessageBox.warning(
             self, app.caption(_("Error")),
             _("Can't write to destination:\n\n{url}").format(url=dest))
         return False
     if QSettings().value("strip_trailing_whitespace", False, bool):
         import reformat
         reformat.remove_trailing_whitespace(QTextCursor(doc))
     b = backup.backup(filename)
     success = doc.save()
     if not success:
         QMessageBox.warning(
             self, app.caption(_("Error")),
             _("Can't write to destination:\n\n{url}").format(url=filename))
     elif b:
         backup.removeBackup(filename)
     return success
Beispiel #26
0
 def saveDocument(self, doc):
     """ Saves the document, asking for a name if necessary.
     
     Returns True if saving succeeded.
     
     """
     if doc.url().isEmpty():
         return self.saveDocumentAs(doc)
     filename = dest = doc.url().toLocalFile()
     if not filename:
         dest = doc.url().toString()
     if not util.iswritable(filename):
         QMessageBox.warning(
             self, app.caption(_("Error")), _("Can't write to destination:\n\n{url}").format(url=dest)
         )
         return False
     b = backup.backup(filename)
     success = doc.save()
     if not success:
         QMessageBox.warning(
             self, app.caption(_("Error")), _("Can't write to destination:\n\n{url}").format(url=filename)
         )
     elif b:
         backup.removeBackup(filename)
     return success
Beispiel #27
0
def take_backup():
    # write logic to send email to him-self with 3 attachments
    # (all 3 files should be mailed..)

    i = 0
    while i < 20:
        print('_', end='')
        time.sleep(0.2)
        i = i + 1
        if i == 19:
            backup.backup()
            print('_', end='')
            time.sleep(0.2)
            print('_', end='')
            time.sleep(0.2)
    print(' Backup successfull........!!!!!!')
    time.sleep(3)
Beispiel #28
0
def backup():
    networklist = []
    namelist =[]
    n = 0
    for network in dashboard.organizations.getOrganizationNetworks(org_id):
        networklist.append(network)
        n += 1
    if request.method == 'GET':
        return render_template('backup.html', title='Backup', tab=1, netdata=networklist, status="Waiting for job")
    elif request.method == 'POST':
        netslist = request.form.getlist('nets')
        for network in netslist:
            bk.backup(network)
        for network in netslist:
            namelist.append(dashboard.networks.getNetwork(network)['name'])
        return render_template('backup.html', title='Backup', tab=1, netdata=networklist, status="Finished Backup",
                               netslist=namelist)
Beispiel #29
0
def add(json_lst, workspace_guid):
    try:
        # Index documents
        update_node_list = index_docs(json_lst, 'add', workspace_guid)

        backup(workspace_guid)
        return {
                'message': 'index-success',
                'workspace_guid': workspace_guid,
                'source_update_nodes': update_node_list
                }
    except Exception as e:
        restore_from_backup(workspace_guid)
        return {
                'message': 'index-failure',
                'workspace_guid': workspace_guid,
                'error': str(traceback.format_exc())
                }
Beispiel #30
0
def delete(json_lst, workspace_guid):
    '''
    Called whenever a user modifies a web page
    e.g. renaming, accessing, etc.
    '''
    try:
        index_docs(json_lst, 'delete', workspace_guid)

        backup(workspace_guid)
        return {
                'message': 'delete-success',
                'workspace_guid': workspace_guid
                }
    except Exception as e:
        restore_from_backup(workspace_guid)
        return {
                'message': 'delete-failure',
                'workspace_guid': workspace_guid,
                'error': str(traceback.format_exc())
                }
Beispiel #31
0
def main(outputHandler=None):
    backup.backup(funcs.FOUT)
    workbook = openpyxl.load_workbook(filename=funcs.FOUT, data_only=True)
    sheet = funcs.fetch_sheet(workbook)
    sheet_data = funcs.parse_sheet(sheet)
    workbook.close()
    st = ''
    tbl = PrettyTable()
    tbl.field_names = ['Item', 'USD']
    st += f"Total\t:{sheet_data['total_cash']}\n"
    tbl.add_row(['$', round(sheet_data['total_cash'], 2)])
    for _, val in sheet_data['column_attributes'].items():
        st += f"{val['name']}\t:{val['current']}\n"
        tbl.add_row([val['name'], round(val['current'], 2)])
    st = st.strip()
    if outputHandler != None:
        # outputHandler.output(st)
        outputHandler.output(str(tbl))
    else:
        # print(st)
        print(tbl)
Beispiel #32
0
 def run(self):
     """
     Runs a new `Job` from that `Task`.
     Called from `RunTasks()` method if it is possible to start a new task -
     the maximum number of simultaneously running `Jobs` is limited.  
     """
     iter_and_path = backup_fs.WalkByID(self.pathID)
     if iter_and_path is None:
         dhnio.Dprint(4, 'backup_control.Task.run ERROR %s not found in the index' % self.pathID)
         # self.defer.callback('error', self.pathID)
         return
     itemInfo, sourcePath = iter_and_path
     if isinstance(itemInfo, dict):
         try:
             itemInfo = itemInfo[backup_fs.INFO_KEY]
         except:
             dhnio.DprintException()
             return
     if not backup_fs.pathExist(sourcePath):
         dhnio.Dprint(4, 'backup_control.Task.run WARNING path not exist: %s' % sourcePath)
         reactor.callLater(0, OnTaskFailed, self.pathID, 'not exist')
         return
     dataID = misc.NewBackupID()
     if itemInfo.has_version(dataID):
         # ups - we already have same version
         # let's add 1,2,3... to the end to make absolutely unique version ID
         i = 1
         while itemInfo.has_version(dataID+str(i)):
             i += 1
         dataID += str(i)
     backupID = self.pathID + '/' + dataID
     try:
         backupPath = backup_fs.MakeLocalDir(settings.getLocalBackupsDir(), backupID)
     except:
         dhnio.DprintException()
         dhnio.Dprint(4, 'backup_control.Task.run ERROR creating destination folder for %s' % self.pathID)
         # self.defer.callback('error', self.pathID)
         return 
     if backup_fs.pathIsDir(sourcePath):
         backupPipe = backup_tar.backuptar(sourcePath, compress='gz')
     else:    
         backupPipe = backup_tar.backuptarfile(sourcePath, compress='gz')
     backupPipe.make_nonblocking()
     resultDefer = Deferred()
     blockSize = settings.getBackupBlockSize()
     job = backup.backup(backupID, backupPipe, OnJobDone, OnBackupBlockReport, settings.getBackupBlockSize())
     jobs()[backupID] = job
     itemInfo.add_version(dataID)
     if itemInfo.type in [ backup_fs.PARENT, backup_fs.DIR ]:
         dirsize.ask(sourcePath, FoundFolderSize, (self.pathID, dataID))
     # self.defer.callback('started', backupID)
     reactor.callLater(0, FireTaskStartedCallbacks, self.pathID, dataID)
     dhnio.Dprint(4, 'backup_control.Task.run %s [%s], size=%d' % (self.pathID, dataID, itemInfo.size))
Beispiel #33
0
    def saveDocument(self, doc, save_as=False):
        """ Saves the document, asking for a name if necessary.

        If save_as is True, a name is always asked.
        Returns True if saving succeeded.

        """
        if save_as or doc.url().isEmpty():
            filename = doc.url().toLocalFile()
            if filename:
                filetypes = app.filetypes(os.path.splitext(filename)[1])
            else:
                # find a suitable directory to save to
                for d in self.historyManager.documents()[1::]:
                    if d.url().toLocalFile():
                        directory = os.path.dirname(d.url().toLocalFile())
                        break
                else:
                    directory = app.basedir() # default directory to save to
                
                import documentinfo
                import ly.lex
                filename = os.path.join(directory, documentinfo.defaultfilename(doc))
                filetypes = app.filetypes(ly.lex.extensions[documentinfo.mode(doc)])
            caption = app.caption(_("dialog title", "Save File"))
            filename = QFileDialog.getSaveFileName(self, caption, filename, filetypes)[0]
            if not filename:
                return False # cancelled
            url = QUrl.fromLocalFile(filename)
        else:
            url = doc.url()

        if QSettings().value("strip_trailing_whitespace", False, bool):
            import reformat
            reformat.remove_trailing_whitespace(QTextCursor(doc))

        # we only support local files for now
        filename = url.toLocalFile()
        b = backup.backup(filename)
        try:
            doc.save(url)
        except IOError as e:
            msg = _("{message}\n\n{strerror} ({errno})").format(
                message = _("Could not write to: {url}").format(url=filename),
                strerror = e.strerror,
                errno = e.errno)
            QMessageBox.critical(self, app.caption(_("Error")), msg)
            return False
        else:
            if b:
                backup.removeBackup(filename)
            recentfiles.add(doc.url())
        return True
Beispiel #34
0
    def __init__(self,
                 path,
                 filepath,
                 executable,
                 fuzzer,
                 use_default=True,
                 prototype=''):
        """
        path => Path to the root directory of source to be fuzzed
        filepath => Relative path of file containing main from root directory
                of source
        executable => Name of final executable generated
        fuzzer => Relative path to fuzzer from root directory of source
        use_default => Flag indicating whether to fuzz a particular function or
                       start fuzzing from main
        prototype => prototype of function to be fuzzed. Will only be
                     considered if use_default is True
        """
        self.template = open('template.cpp', 'r').read()
        self.path = path
        self.filename = filepath.split('/')[-1]
        self.executable = executable
        self.sourcepath = ''.join(x for x in filepath.split('/')[:-1])
        self.libpath = self.path + '/' + self.sourcepath

        print "[-] Intializing"
        initializeObject = initialize(self.path)
        print "[+] Done"
        chdir(self.sourcepath)
        open('test.cpp', 'w').write(self.template)

        print "[-] Modifying main to runner"
        backupObject = backup(self.filename, initializeObject.getOutput())
        print "[+] Done"

        print "[-] Building shared object"
        libraryObject = makeObject(initializeObject.getOutput(),
                                   self.executable)
        print "[+] Done"

        if use_default is False and prototype is not '':
            print "[-] Creating fuzzer targeting arbitrary function"
            customObject = makeFuzzer(prototype)
            print "[+] Done"

        print "[-] Compiling fuzzer"
        compilefuzzer(libraryObject.getLibFlags(), '../' + fuzzer)
        print "[+] Done"

        print "[-] Starting fuzzing"
        call('./test', env=dict(environ, LD_LIBRARY_PATH=self.libpath))
Beispiel #35
0
def main():

    logger = Logger.Logger()

    for file in os.listdir():
        if file.endswith('.pdf'):
            try:
                os.remove('%s' % file)
            except:
                logger.log("Couldn't remove %s, file is already in use." % (file))

    backup()

    root = MainGUI.MainGUI()

    #menu = Menu(root)
    #root.config(menu=menu)

    #subMenu = Menu(menu)
    #menu.add_cascade(label="File", menu=subMenu)
    #
    # subMenu.add_command(label="Start", command=doNothing)

    #editMent = Menu(menu)
    #menu.add_cascade(label="Edit", menu=editMent)
    #editMent.add_command(label="Uppdatera lösenord", command=doNothing)

    default_font = tkinter.font.nametofont("TkDefaultFont")
    default_font.configure(size=15)
    root.option_add("*Font", default_font)

    w, h = root.winfo_screenwidth(), root.winfo_screenheight()
    #root.overrideredirect(1)
    #root.geometry("%dx%d+0+0" % (w, h))

    root.geometry("%dx%d" % (w, h-100))
    root.mainloop()
Beispiel #36
0
def backupNow():
    #Check to see if the bags table exists
    cursor.execute(
        "SELECT name FROM sqlite_master WHERE type='table' AND name='backupPaths'"
    )
    fetchall = cursor.fetchall()
    length = len(fetchall)
    if length == 0:
        print('creating table...')
        #Create the table if it does not exist
        cursor.execute('''CREATE TABLE backupPaths (path)''')
    backup.writeLog()
    path = backup.backup()
    cursor.execute("INSERT INTO backupPaths VALUES (?)", [str(path)])
    connection.commit()
Beispiel #37
0
    def saveDocument(self, doc, save_as=False):
        """ Saves the document, asking for a name if necessary.
        
        If save_as is True, a name is always asked.
        Returns True if saving succeeded.
        
        """
        if save_as or doc.url().isEmpty():
            filename = doc.url().toLocalFile()
            if filename:
                filetypes = app.filetypes(os.path.splitext(filename)[1])
            else:
                directory = app.basedir() # default directory to save to
                import documentinfo
                import ly.lex
                filename = os.path.join(directory, documentinfo.defaultfilename(doc))
                filetypes = app.filetypes(ly.lex.extensions[documentinfo.mode(doc)])
            caption = app.caption(_("dialog title", "Save File"))
            filename = QFileDialog.getSaveFileName(self, caption, filename, filetypes)
            if not filename:
                return False # cancelled
            url = QUrl.fromLocalFile(filename)
        else:
            url = doc.url()
        
        if QSettings().value("strip_trailing_whitespace", False, bool):
            import reformat
            reformat.remove_trailing_whitespace(QTextCursor(doc))

        # we only support local files for now
        filename = url.toLocalFile()
        b = backup.backup(filename)
        try:
            doc.save(url)
        except IOError as e:
            msg = _("{message}\n\n{strerror} ({errno})").format(
                message = _("Could not write to: {url}").format(url=filename),
                strerror = e.strerror,
                errno = e.errno)
            QMessageBox.critical(self, app.caption(_("Error")), msg)
            return False
        else:
            if b:
                backup.removeBackup(filename)
            recentfiles.add(doc.url())
        return True
Beispiel #38
0
entryType = "Papers"
listStart = 0
showFinished = False
listSearch = ""

def reset():
    global listStart, showFinished, listSearch
    listStart = 0
    showFinished = False
    listSearch = ""

fullBreak = False
clearString = ""

while not fullBreak:
    backup.backup()

    with lite.connect('tasks.db') as con:
        cur = con.cursor()

        while True:
            stdscr.clear()
            addstr(clearString)
            clearString = ""

            if state[-1] == main:

                options = ['`','1','2','3','4','5','6','7','8','9','0','-','=']
                optionNames = ["Paper","Book","Research","Writing & Presentations","Teaching","Outreach","Quick"]

                addstr("Active:\n")
Beispiel #39
0
import sys
from backup import backup
from restore import restore
  
def printError():
  print("ERROR: Invalid Format for command","","  python gitRecloner [backup|restore]",sep="\n")

bkpFile = "backup.txt"
  
if len(sys.argv) == 2:
  if sys.argv[1] == "backup":
    backup(bkpFile)
  elif sys.argv[1] == "restore":
    restore(bkpFile)
  else:
    printError()
else:
  printError()
  
	def backup_button_clicked(self, widget):
		global num_files
		#Build our widgets
		self.server = self.wTree.get_widget("server_field_backup")
		self.name = self.wTree.get_widget("username_field_backup")
		self.pswrd = self.wTree.get_widget("password_field_backup")
		self.ap = self.wTree.get_widget("ap_field_backup")
		#Get our field text
		self.SERVER = self.server.get_text()
		un = self.name.get_text()
		ps = self.pswrd.get_text()
		an = self.ap.get_text()

		#If user selected a local rsync, check they selected an external device
		if self.LOCAL == True:
			appointment_number = an
			username = un
			#Check the external drive
			external_drive_backup = self.check_input(self.external_name_backup,'.','Invalid External HD!','External Device')
			if self.FOLDERS == True:
				for folder in self.folders_selected_backup:
					#Check all folders selected
					current_folder = self.check_input(folder,'.','Invalid Folders','Folder(s)')
			else:
				#Otherwise check the hard drive
				hard_drive_backup = self.check_input(self.hd_name_backup,'.','Invalid HD!','Hard Drive')
				
			
			#Ensure an external drive is selected
			if (external_drive_backup != None):

				#Make sure a folder has been selected
				if (self.FOLDERS == True and current_folder == None):
					return
				#Or that a hard drive has been selected
				if (self.FOLDERS == False and hard_drive_backup == None):
					return
				else:
					#Set appropriate names
					appointment_number = "HR" + appointment_number
					external_drive_backup = '/media/' + external_drive_backup + '/'
					if self.FOLDERS:
						#Change the gui tab to output
						self.notebook.set_current_page(2)
						
						#Create new appointment
						appointment = backup(
												appointment_number=appointment_number,
												paths_to_backup=self.folders_selected_backup,
												username=username,
												use_filter=self.FILTER,
												remote_path_arg=external_drive_backup,
												gui_enabled=True
											)
											
						self.grab_set_coords(appointment)
						appointment.set_log_window(self.textview2)
						appointment.run()
																			
						#After backup is complete, reset selected drives
						external_drive_backup = ""
						#Clear labels and Output
						self.label11.set_text("")
						self.logwindow.set_text("")
						self.textview2.set_buffer(self.logwindow)
					else:
						hard_drive_backup = '/media/' + hard_drive_backup + '/'
						#Change the gui tab to output
						self.notebook.set_current_page(2)
						
						#Create a new appointment
						appointment = backup(
												appointment_number=appointment_number,
												paths_to_backup=hard_drive_backup,
												username=username,
												use_filter=self.FILTER,
												remote_path_arg=external_drive_backup,
												gui_enabled=True
											)
						self.grab_set_coords(appointment)
						appointment.set_log_window(self.textview2)
						appointment.run()
																			
						#After backup is complete, reset selected drives
						self.hd_name_backup = self.external_name_backup = ""
						#Clear labels and output
						self.label11.set_text("")
						self.logwindow.set_text("")
						self.textview2.set_buffer(self.logwindow)
				
		#If the rsync is to the server
		else:
			#Check all credentials to make sure they're valid inputs
			username = self.check_input(un,'^[a-zA-Z0-9]{1,40}$', 'Username must be 1-40 characters and lower/upper case letters, or numbers.', 
			'username')
			appointment_number = self.check_input(an, '^\d{6}$', 'Invalid appointment number.','appointment number')
			password = self.check_input(ps,'.','Invalid password!!','password')
			
			if self.FOLDERS == True:
				#Check folders
				for folder in self.folders_selected_backup:
					current_folder = self.check_input(folder,'.','Invalid Folders','Folder(s)')
			else:
				#Otherwise check hard drive
				hard_drive_backup = self.check_input(self.hd_name_backup,'.','Invalid HD! Impossible, see Jake!','Hard Drive')
		
			#Check that all inputs are valid then backup
			if (username and appointment_number and password)!=None:
				if (self.FOLDERS == True and current_folder == None):
					return
				if (self.FOLDERS == False and hard_drive_backup == None):
					return
				else:
					#Set appropriate names
					appointment_number = "HR" + appointment_number
					
					if self.FOLDERS:
						#Change the gui tab to output
						self.notebook.set_current_page(2)
						
						appointment = backup(
												appointment_number=appointment_number,
												username=username,
												password=password,
												paths_to_backup=self.folders_selected_backup,
												use_filter=self.FILTER,
												backup_server=self.SERVER,
												gui_enabled=True
											)
						self.grab_set_coords(appointment)
						appointment.set_log_window(self.textview2)
						appointment.run()
												
						#Clears label and output
						self.label11.set_text("")
						self.logwindow.set_text("")
						self.textview2.set_buffer(self.logwindow)
						self.FOLDERS = None
					else:
						hard_drive_backup = '/media/' + hard_drive_backup + '/'
						#Change the gui tab to output
						self.notebook.set_current_page(2)
						
						appointment = backup(
												appointment_number=appointment_number,
												username=username,
												password=password,
												paths_to_backup=hard_drive_backup,
												use_filter=self.FILTER,
												backup_server=self.SERVER,
												gui_enabled=True
											)
						self.grab_set_coords(appointment)
						appointment.set_log_window(self.textview2)
						appointment.run()
												
						#After backup is complete, reset selected drives
						self.hd_name_backup = ""
						#Clears label and output
						self.label11.set_text("")
						self.logwindow.set_text("")
						self.textview2.set_buffer(self.logwindow)
Beispiel #41
0
 def test_missing_prof_argument(self):
     "Check that an error is raised if profile_name is missing"
     with self.assertRaises(RuntimeError) as cm:
         backup.backup()
     self.assertEquals(cm.exception.message,
                 u'Missing profile_name argument')
Beispiel #42
0
 def test_non_existing_profile(self):
     "Check that an error is raised if profile missing from settings"
     with self.assertRaises(RuntimeError) as cm:
         backup.backup(profile_name=u'no-such-profile')
     self.assertEquals(cm.exception.message,
                 u'No such profile "no-such-profile"')
Beispiel #43
0
def main():
    """
    Main routine
    """
    parser = argparse.ArgumentParser(description='Backup/Restore')

    subparsers = parser.add_subparsers(dest='cmd')

    backup_parser = subparsers.add_parser('backup', help='do backup')
    backup_parser.add_argument('-c', nargs=1, required=True,
        metavar='config_file')


    restore_parser = subparsers.add_parser('restore', help='do restore')
    restore_parser.add_argument('-d', nargs=1, required=True,
        metavar='dropbox directory')
    restore_parser.add_argument('-r', nargs=1, required=True,
        metavar='directory for database restoral')
    restore_parser.add_argument('-o', nargs=1, metavar='override the root of ' +
        ' directories')

    consitency_parser = subparsers.add_parser('consistency',
        help='do consistency')
    consitency_parser.add_argument('-c', nargs=1, required=True,
        metavar='config_file')

    dump_parser = subparsers.add_parser('dump', help='do dump')
    dump_parser.add_argument('-c', nargs=1, required=True,
        metavar='config_file')
    dump_parser.add_argument('-f', nargs=1, required=True,
        metavar='output_file')


    args = parser.parse_args()

    setup_logging()

    try:
        if args.cmd == 'backup':
            res = setup_config(args.c[0])
            backup(res.config, res.database)
            backup_meta(res.config_path)
        elif args.cmd == 'restore':
            override = ''
            if args.o:
                override = args.o[0]
            restore(args.d[0], args.r[0], override)
        elif args.cmd == 'consistency':
            logger = logging.getLogger('mylog')
            res = setup_config(args.c[0])
            res = consistency_check(res.config, res.database, True)
            if res is True:
                logger.info('Consistency check completed successfully')
            else:
                logger.info('Consistency check has found some problems.' +
                    ' Rerun to check if they were fixed.')
        elif args.cmd == 'dump':
            res = setup_config(args.c[0])
            dump_database(res.database, args.f[0])

    except KeyError:
        print 'Key not found!'
    except SystemExit:
        print 'Exiting...'
	def start(self):
		#Check the username from input
		username = self.options.username
		self.logger.debug("Checking username input.")
		if username == '' or username == None:
			print "You must enter a username!"

		username = self.check_input( username, 
								'^[a-zA-Z0-9]{1,40}$', 
								'Username must be 1-40 characters and lower/upper case letters, or numbers.', 
								'username', 
								'Using the following as your username: '******'Please enter your username (i.e. for the Mac Workstations):',
								False)
		
		#Check the appointment number from input
		appointment_number = self.options.appointment_number
		self.logger.debug("Checking appointment number input.")
		if appointment_number == '' or appointment_number == None:
			print "You must enter an appointment number!"
		
		appointment_number = 'HR' + self.check_input(	appointment_number,
													'^\d{6}$',
													'Invalid appointment number.',
													'appointment number',
													'The appointment will be labeled as: HR',
													'Please enter the help request number (e.g. 001234): HR',
													True)
		
		#Let the user mount/unmount partitions if necessary
		if self.options.mount:
			self.logger.debug("Trying to load 'mounter' for manual mounting.")
			try:
				import mounter
				print "Please select the partition to be mounted and backed up."
				m = mounter()
				m.start()
			except:
				print "Could not load 'mounter' - skipping."
		
		#Checking paths to backup from input
		self.logger.debug("Checking backup paths from input.")
		if not self.options.restore:
			self.logger.debug("This is a BACKUP.")
			paths_to_backup = self.check_paths(self.args)
		else:
			self.logger.debug("This is a RESTORE.")
			path_to_restore_to = self.check_paths(self.args)
		
		#Change in server
		if self.options.server != '' and self.options.server != None:
			self.logger.debug("Changing server setting.")
			self.SERVER = self.options.server
			print "New Server:" + self.SERVER
		
		#Check remote path
		remote_path_available = False
		external_path = self.options.external_path
		self.logger.debug("Checking remote path.")
		if external_path != '' and external_path != None:
			external_path = ''.join(self.check_paths(external_path))
			remote_path_available = True
		
		#Now we'll create an appointment object. We'll use it as the object through which we perform backups.
		self.logger.debug("Creating appointment object (backup or restore) to perform backups/restores.")
		if not self.options.restore:
			self.logger.debug("Using a backup object....")
			if remote_path_available:
				self.logger.debug("Creating local backup object.")
				appointment = backup(
										appointment_number=appointment_number,
										username=username,
										paths_to_backup=paths_to_backup,
										use_filter=self.options.use_filter,
										remote_path_arg=external_path
									)
			else:
				self.logger.debug("Creating remote backup object (after getting password).")
				#We need a password
				password = getpass()
				appointment = backup(
										appointment_number=appointment_number,
										username=username,
										password=password,
										paths_to_backup=paths_to_backup,
										backup_server=self.SERVER,
										use_filter=self.options.use_filter
									)
			#Start the backup
			self.logger.debug("Starting the backup job.")
			appointment.run()
		else:
			self.logger.debug("Using a restore object.....")
			if type(path_to_restore_to).__name__ == "list":
				self.logging.info("Multiple paths to restore to, so using the first one.")
				path_to_restore_to = path_to_restore_to[0]
				print
				print "Using first argument ("+path_to_restore_to+") as the path to restore to."
				print
			if remote_path_available:
				self.logger.debug("Creating local restore object.")
				#do restore from remote path
				restoration = restore(
										appointment_number=appointment_number,
										username=username,
										path_to_restore_to=path_to_restore_to,
										remote_path_arg=external_path
									)
			else:
				self.logger.debug("Creating remote restore object.")
				#do default restore from backup server
				#We need a password
				password = getpass()			
				restoration = restore(
										appointment_number=appointment_number,
										username=username,
										password=password,
										path_to_restore_to=path_to_restore_to,
										backup_server=self.SERVER
									)
			#Start the restore
			self.logger.debug("Starting the restore job.")
			restoration.run()
Beispiel #45
0
 def run(self):
   backup.backup(gui.uuid, gui.host, gui.path)
   gtk.gdk.threads_enter()
   gui.update_revisions()
   running_tasks_model.remove(i)
   gtk.gdk.threads_leave()
Beispiel #46
0
def start():
	log.log("Starting audit...",0)
	audit.audit()
	log.log("Starting backup...",0)
	backup.backup()
    def run(self):
        """
        Runs a new ``Job`` from that ``Task``.

        Called from ``RunTasks()`` method if it is possible to start a
        new task - the maximum number of simultaneously running ``Jobs``
        is limited.
        """
        import backup_tar
        import backup
        iter_and_path = backup_fs.WalkByID(self.pathID)
        if iter_and_path is None:
            lg.out(4, 'backup_control.Task.run ERROR %s not found in the index' % self.pathID)
            # self.defer.callback('error', self.pathID)
            return
        itemInfo, sourcePath = iter_and_path
        if isinstance(itemInfo, dict):
            try:
                itemInfo = itemInfo[backup_fs.INFO_KEY]
            except:
                lg.exc()
                return
        if self.localPath and self.localPath != sourcePath:
            lg.warn('local path were changed: %s -> %s' % (self.localPath, sourcePath))
        self.localPath = sourcePath
        if not bpio.pathExist(sourcePath):
            lg.warn('path not exist: %s' % sourcePath)
            reactor.callLater(0, OnTaskFailed, self.pathID, 'not exist')
            return
        dataID = misc.NewBackupID()
        if itemInfo.has_version(dataID):
            # ups - we already have same version
            # let's add 1,2,3... to the end to make absolutely unique version ID
            i = 1
            while itemInfo.has_version(dataID + str(i)):
                i += 1
            dataID += str(i)
        backupID = self.pathID + '/' + dataID
        try:
            backup_fs.MakeLocalDir(settings.getLocalBackupsDir(), backupID)
        except:
            lg.exc()
            lg.out(4, 'backup_control.Task.run ERROR creating destination folder for %s' % self.pathID)
            # self.defer.callback('error', self.pathID)
            return
        compress_mode = 'bz2'  # 'none' # 'gz'
        if bpio.pathIsDir(sourcePath):
            backupPipe = backup_tar.backuptar(sourcePath, compress=compress_mode)
        else:
            backupPipe = backup_tar.backuptarfile(sourcePath, compress=compress_mode)
        backupPipe.make_nonblocking()
        job = backup.backup(
            backupID, backupPipe,
            OnJobDone, OnBackupBlockReport,
            settings.getBackupBlockSize(),
            sourcePath)
        jobs()[backupID] = job
        itemInfo.add_version(dataID)
        if itemInfo.type in [backup_fs.PARENT, backup_fs.DIR]:
            dirsize.ask(sourcePath, OnFoundFolderSize, (self.pathID, dataID))
        else:
            jobs()[backupID].totalSize = os.path.getsize(sourcePath)
        jobs()[backupID].automat('start')
        reactor.callLater(0, FireTaskStartedCallbacks, self.pathID, dataID)
        lg.out(4, 'backup_control.Task-%d.run [%s/%s], size=%d, %s' % (
            self.number, self.pathID, dataID, itemInfo.size, sourcePath))