Skip to content

a "sync" command for a give folder/project? #16

Description

@jdeltoft

I'm thinking of a feature where you have several files and can't recall all the ones you need to transfer to the device since the last time. This would require listing all the files and taking a md5 hash or something like that to know if the local version has changed since the last upload (timestamp may not be good if they haven't set the time etc). Also, that would get you the list of files to sync (assume any new file would need to be put onto the device manually the first time).

Activity

  1. zindy commented on Jan 29, 2019

    @zindy

    I'll leave this here for now. Not exactly a sync as such, but this is a mass copy function I'm working on which will (eventually) send complete folder trees of subfolders and files to the mcu.

    import os
    
    def masscopy(pc_path,mcu_path):
        ignore_dirs = []
        mcu_tree = []
        pc_path = os.path.normpath(pc_path)
        _,dest = os.path.split(pc_path)
        
        for root, dirs, files in os.walk(pc_path):
            skip = False
            for idir in ignore_dirs:
                if root.startswith(idir):
                    skip = True
                    break
            if skip:
                continue
            c_path = os.path.normpath('/'.join((mcu_path,dest,root.replace(pc_path,'')))).replace(os.sep,'/')
            for d in ['']+dirs:
                if d.startswith('.git') or d == '__pycache__' or d.startswith('.ipynb'):
                    ignore_dirs.append(os.path.join(root,d))
                    continue
                cc_path = os.path.normpath('/'.join((c_path,d))).replace(os.sep,'/')
                if cc_path in mcu_tree:
                    continue
                print('(d)',cc_path)
                mcu_tree.append(cc_path)
            for f in files:
                if f.startswith('.git') or f.endswith('~') or f.endswith('.bak') or f.endswith('.pyc') or f.endswith('.swp'):
                    continue
                cc_path = '/'.join((c_path,f))
                print('(f)',cc_path)
    
    pc_path = os.getcwd()
    mcu_path = '/tmp/'
    masscopy(pc_path,mcu_path)
    

    which gives the following output for uPyLoader (see below). The idea is that folders creation is only attempted once for each folder. os.walk() also has this interesting side effect that directories are visited from top to most inner, which means that at each subsequent step, folders can always be created because the folder parent has already been created. We can also get rid of some unnecessary folders and files while we're at it. In the following output, (d) stands for directory and (f) for file. Folders are always created first, then files are copied.

    (d) /tmp/uPyLoader
    (d) /tmp/uPyLoader/gui
    (d) /tmp/uPyLoader/icons
    (d) /tmp/uPyLoader/images
    (d) /tmp/uPyLoader/mcu
    (d) /tmp/uPyLoader/src
    (f) /tmp/uPyLoader/buildgui.py
    (f) /tmp/uPyLoader/config.json
    (f) /tmp/uPyLoader/flash.py
    (f) /tmp/uPyLoader/hotswap.py
    (f) /tmp/uPyLoader/install_osx_dependencies.sh
    (f) /tmp/uPyLoader/LICENSE
    (f) /tmp/uPyLoader/main.py
    (f) /tmp/uPyLoader/main.spec
    (f) /tmp/uPyLoader/README.md
    (f) /tmp/uPyLoader/Untitled.ipynb
    (d) /tmp/uPyLoader/gui/qt
    (f) /tmp/uPyLoader/gui/about_dialog.py
    (f) /tmp/uPyLoader/gui/code_edit.py
    (f) /tmp/uPyLoader/gui/file_transfer.py
    (f) /tmp/uPyLoader/gui/flash_dialog.py
    (f) /tmp/uPyLoader/gui/mainwindow.py
    (f) /tmp/uPyLoader/gui/settings.py
    (f) /tmp/uPyLoader/gui/terminal.py
    (f) /tmp/uPyLoader/gui/wifi_preset.py
    (f) /tmp/uPyLoader/gui/__init__.py
    (d) /tmp/uPyLoader/gui/qt/icons
    (f) /tmp/uPyLoader/gui/qt/about_dialog.ui
    (f) /tmp/uPyLoader/gui/qt/code_edit.ui
    (f) /tmp/uPyLoader/gui/qt/file_transfer.ui
    (f) /tmp/uPyLoader/gui/qt/flash_dialog.ui
    (f) /tmp/uPyLoader/gui/qt/mainwindow.ui
    (f) /tmp/uPyLoader/gui/qt/settings.ui
    (f) /tmp/uPyLoader/gui/qt/terminal.ui
    (f) /tmp/uPyLoader/gui/qt/wifi_preset.ui
    (f) /tmp/uPyLoader/gui/qt/icons/floppy_disk_1-64x64.png
    (f) /tmp/uPyLoader/gui/qt/icons/main-512.png
    (f) /tmp/uPyLoader/gui/qt/icons/refresh-64x64.png
    (f) /tmp/uPyLoader/gui/qt/icons/run.png
    (f) /tmp/uPyLoader/icons/floppy.png
    (f) /tmp/uPyLoader/icons/LICENSE
    (f) /tmp/uPyLoader/icons/main-512.icns
    (f) /tmp/uPyLoader/icons/main-512.png
    (f) /tmp/uPyLoader/icons/main.icns
    (f) /tmp/uPyLoader/icons/main.ico
    (f) /tmp/uPyLoader/icons/main.png
    (f) /tmp/uPyLoader/icons/main.svg
    (f) /tmp/uPyLoader/icons/refresh.png
    (f) /tmp/uPyLoader/icons/root_folder.png
    (f) /tmp/uPyLoader/icons/run.png
    (f) /tmp/uPyLoader/icons/run.svg
    (f) /tmp/uPyLoader/icons/tree_file.png
    (f) /tmp/uPyLoader/icons/tree_folder.png
    (f) /tmp/uPyLoader/icons/tree_python.png
    (f) /tmp/uPyLoader/images/editor.png
    (f) /tmp/uPyLoader/images/main.png
    (f) /tmp/uPyLoader/images/settings.png
    (f) /tmp/uPyLoader/images/term.png
    (f) /tmp/uPyLoader/mcu/download.py
    (f) /tmp/uPyLoader/mcu/upload.py
    (d) /tmp/uPyLoader/src/connection
    (d) /tmp/uPyLoader/src/gui
    (d) /tmp/uPyLoader/src/helpers
    (d) /tmp/uPyLoader/src/logic
    (d) /tmp/uPyLoader/src/utility
    (f) /tmp/uPyLoader/src/__init__.py
    (f) /tmp/uPyLoader/src/connection/baud_options.py
    (f) /tmp/uPyLoader/src/connection/connection.py
    (f) /tmp/uPyLoader/src/connection/connection_new.py
    (f) /tmp/uPyLoader/src/connection/connection_scanner.py
    (f) /tmp/uPyLoader/src/connection/serial_connection.py
    (f) /tmp/uPyLoader/src/connection/terminal.py
    (f) /tmp/uPyLoader/src/connection/websocket.py
    (f) /tmp/uPyLoader/src/connection/wifi_connection.py
    (f) /tmp/uPyLoader/src/connection/__init__.py
    (d) /tmp/uPyLoader/src/gui/controls
    (f) /tmp/uPyLoader/src/gui/about_dialog.py
    (f) /tmp/uPyLoader/src/gui/code_edit_dialog.py
    (f) /tmp/uPyLoader/src/gui/file_transfer_dialog.py
    (f) /tmp/uPyLoader/src/gui/flash_dialog.py
    (f) /tmp/uPyLoader/src/gui/icons.py
    (f) /tmp/uPyLoader/src/gui/main_window.py
    (f) /tmp/uPyLoader/src/gui/settings_dialog.py
    (f) /tmp/uPyLoader/src/gui/terminal_dialog.py
    (f) /tmp/uPyLoader/src/gui/wifi_preset_dialog.py
    (f) /tmp/uPyLoader/src/gui/__init__.py
    (f) /tmp/uPyLoader/src/gui/controls/transfer_tree_view.py
    (f) /tmp/uPyLoader/src/gui/controls/__init__.py
    (f) /tmp/uPyLoader/src/helpers/ip_helper.py
    (f) /tmp/uPyLoader/src/helpers/pyinstaller_helper.py
    (f) /tmp/uPyLoader/src/helpers/qt_helper.py
    (f) /tmp/uPyLoader/src/helpers/websocket_helper.py
    (f) /tmp/uPyLoader/src/helpers/__init__.py
    (f) /tmp/uPyLoader/src/logic/file_transfer.py
    (f) /tmp/uPyLoader/src/logic/remote_file_system_model.py
    (f) /tmp/uPyLoader/src/logic/__init__.py
    (f) /tmp/uPyLoader/src/utility/build_info.py
    (f) /tmp/uPyLoader/src/utility/exceptions.py
    (f) /tmp/uPyLoader/src/utility/file_info.py
    (f) /tmp/uPyLoader/src/utility/logger.py
    (f) /tmp/uPyLoader/src/utility/relative_path_resolver.py
    (f) /tmp/uPyLoader/src/utility/settings.py
    (f) /tmp/uPyLoader/src/utility/signal_interface.py
    (f) /tmp/uPyLoader/src/utility/singleton.py
    (f) /tmp/uPyLoader/src/utility/versioning.py
    (f) /tmp/uPyLoader/src/utility/__init__.py
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions