Created
August 23, 2016 18:49
-
-
Save gcmurphy/0dd7381a4650b4329747f07c0332047e to your computer and use it in GitHub Desktop.
dotfile grabber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import tarfile | |
__MAX_SIZE_THRESHOLD = 10240000 # ~10MB | |
def is_dotfile(path): | |
return (os.path.isfile(path) and | |
os.path.basename(path).startswith('.') and | |
os.stat(path).st_size < __MAX_SIZE_THRESHOLD) | |
def main(): | |
output = 'dotfiles.tgz' | |
homedir = os.environ.get('HOME', os.getcwd()) | |
with tarfile.open(output, 'w:gz') as archive: | |
for path in os.listdir(homedir): | |
if is_dotfile(path): | |
print("adding: {}, {} bytes.".format(path, os.stat(path).st_size)) | |
archive.add(path) | |
print("Done - {}, {} bytes written.".format(output, os.stat(output).st_size)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment