Skip to content

Instantly share code, notes, and snippets.

@gcmurphy
Created August 23, 2016 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gcmurphy/0dd7381a4650b4329747f07c0332047e to your computer and use it in GitHub Desktop.
Save gcmurphy/0dd7381a4650b4329747f07c0332047e to your computer and use it in GitHub Desktop.
dotfile grabber
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