Commits

Cliff Dyer committed b6ec5e7

Working on phone sync.

Comments (0)

Files changed (2)

         self.format = self.get_format()
 
     def exists(self):
-	return os.path.exists(self.filename)
+        return os.path.exists(self.filename)
 
     def delete(self):
-        if self.exists()
+        if self.exists():
             os.unlink(self.filename)
 
     def get_format(self):

bin/phone_sync.py

 phonedir = '/media/9AC7-12DF/Music'
 
 def get_music_files(rootdir):
-    for dirpath, dirs, files in os.walk(rootdir):
+    if os.path.isdir(rootdir):
+        walk = os.walk(rootdir)
+    elif os.path.isfile(rootdir):
+        walk = [(os.path.dirname(rootdir), [], os.path.basename(rootdir))]
+    else:
+        walk = []
+    print(repr(list(walk)))
+    for dirpath, dirs, files in walk:
         for filename in files:
             extension = filename.lower().rsplit('.', 1)[-1]
             filepath = os.path.join(dirpath, filename)
+	    print(filepath, extension)
             if extension in music_file_extensions:
                 yield audiotools.AudioFile(filepath)
             elif extension in playlist_extensions:
     return args
 
 def prep_file(audiofile):
+    print(audiofile.filename)
     relative_path = get_relative_path(audiofile)
 
     if audiofile.format.extension in supported_file_extensions:
         outpath = relative_path
     else:
         outpath = '{}.ogg'.format(relative_path.rsplit('.', 1)[0])
-    
     temp_target = AudioFile(os.path.join(tempdir, outpath))
     final_target = AudioFile(os.path.join(phonedir, outpath))
 
-    if not any(target.exists() for target in (temp_target, final_target):
+    if not any(target.exists() for target in (temp_target, final_target)):
         os.makedirs(os.path.dirname(temp_target.filename), exist_ok=True)
         if outpath == relative_path:
             shutil.copy(audiofile.filename, temp_target.filename)
 def main():
     arguments = parse_arguments(sys.argv[1:])
     for argument in arguments:
-        if os.path.isdir(argument):
+        print(argument)
+        if os.path.exists(argument):
+            print('exists')
             for audiofile in get_music_files(argument):
+                print(audiofile.filename)
                 prep_file(audiofile)
+            
+        else:
+            print("File or directory not found: {}".format(argument))
     sync_all()               
 
 if __name__ == '__main__':