예제 #1
0
파일: diff.py 프로젝트: Naveengnn/one
def diff(filename, mf_path=''):
    '''Use hashlib library to compare sha256 hash of
  current file to the sha256 hash stored on MediaFire'''

    full_expansion = get_path_expansion(filename)
    if (mf_path == '' or not mf_path):
        if ('/' in filename):
            mf_path = os.path.basename(filename)
        else:
            mf_path = filename

    if (os.path.isfile(full_expansion)):
        in_file = open(filename, 'r')
        mf_path = sanitize_path(mf_path)
        file_contents = in_file.read().encode('utf-8')
        new_hash = hashlib.sha256(file_contents).hexdigest()
        media_hash = get_hash(mf_path)
        try:
            old_hash = xattr.getxattr(full_expansion, 'hash').decode('ascii')
        except OSError:
            old_hash = ''

        if (media_hash == ''):
            logger.die('No file path "' + mf_path + '/' +
                       os.path.basename(filename) + '" in MediaFire')
        else:
            figure_time_scale(media_hash, old_hash, new_hash,
                              os.path.basename(full_expansion))
    else:
        logger.die('No local file "' + os.path.basename(full_expansion) +
                   '" found')
예제 #2
0
파일: diff.py 프로젝트: cdpetty/one
def diff(filename, mf_path=''):
  '''Use hashlib library to compare sha256 hash of
  current file to the sha256 hash stored on MediaFire'''

  full_expansion = get_path_expansion(filename)
  if(mf_path == '' or not mf_path):
    if ('/' in filename):
      mf_path = os.path.basename(filename)
    else:
      mf_path = filename

  if (os.path.isfile(full_expansion)):
    in_file = open(filename, 'r')
    mf_path = sanitize_path(mf_path)
    file_contents = in_file.read().encode('utf-8')
    new_hash = hashlib.sha256(file_contents).hexdigest()
    media_hash = get_hash(mf_path)
    try:
      old_hash = xattr.getxattr(full_expansion, 'hash').decode('ascii')
    except OSError:
      old_hash = '' 

    if (media_hash == ''):
      logger.die('No file path "' + mf_path + '/' + os.path.basename(filename) + '" in MediaFire')
    else:
      figure_time_scale(media_hash, old_hash, new_hash, os.path.basename(full_expansion))
  else:
    logger.die('No local file "' + os.path.basename(full_expansion) + '" found')
예제 #3
0
파일: user.py 프로젝트: Naveengnn/one
def sign_in():
  is_old = input('Do you already have a MediaFire account? [y/n] ')
  if (is_old[0].lower() == 'y'):
    email = input('What is your email: ').lower()
    password = getpass.getpass('What is your password: '******'w')
      ofstream.write(email + '\n') 
      ofstream.write(password)
      ofstream.close()
      client = existance[1]
      if (not check_one_existance(client)):
        try:
          client.create_folder('mf:/one_storage/')     
        except requests.exceptions.RequestException:
          logger.die('Network error, please check network status and try again')
      logger.end('You are signed in!')
    else:
      logger.die('Either your credentials are incorrect or your account does not exist.\nPlease try again or see MediaFire.com')
  elif (is_old[0].lower() == 'n'):
      logger.end('Please go to MediaFire.com and create an account.') 
  else:
    logger.log('Please answer with a a "n" or "y"')
    sign_in()
예제 #4
0
파일: user.py 프로젝트: Naveengnn/one
def check_existance(email, password):
  try:
    client = c.get_client(email, password) 
    return (True, client)
  except (MediaFire.api.MediaFireApiError):
    return (False, None)
  except requests.exceptions.RequestException:
    logger.die('Network error, please check network status and try again')
예제 #5
0
파일: share.py 프로젝트: Naveengnn/one
def share(filename):
    exist = get_existance(filename)
    if (exist[1]):
        f = exist[1]
        mail(f['links']['normal_download'])
        logger.end(f['links']['normal_download'])
    else:
        logger.die('File "' + filename + '" does not exist')
예제 #6
0
파일: share.py 프로젝트: cdpetty/one
def share(filename):
  exist = get_existance(filename)
  if (exist[1]):
    f = exist[1]
    mail(f['links']['normal_download'])
    logger.end(f['links']['normal_download'])
  else:
    logger.die('File "' + filename + '" does not exist')
예제 #7
0
파일: list.py 프로젝트: cdpetty/one
def get_files(path):
  try:
    client = c.get_client()
    contents = client.get_folder_contents_iter('mf:' + path)
    return list(contents)
  except ResourceNotFoundError:
    logger.die('Path: "' + path + '" does not exist')
  except requests.exceptions.RequestException:
    logger.die('Network error, please check network status and try again')
예제 #8
0
def get_files(path):
    try:
        client = c.get_client()
        contents = client.get_folder_contents_iter('mf:' + path)
        return list(contents)
    except ResourceNotFoundError:
        logger.die('Path: "' + path + '" does not exist')
    except requests.exceptions.RequestException:
        logger.die('Network error, please check network status and try again')
예제 #9
0
파일: user.py 프로젝트: Naveengnn/one
def check_one_existance(client):
  try:
    users = client.get_folder_contents_iter("mf:/")
    for name in users:
      if type(name) is Folder:
        if name['name'] == 'one_storage':
          return True
    return False
  except requests.exceptions.RequestException:
    logger.die('Network error, please check network status and try again')
예제 #10
0
파일: share.py 프로젝트: cdpetty/one
def get_existance(filename):
  client = c.get_client()
  try:
    contents = client.get_folder_contents_iter('mf:/one_storage/')
    for item in contents:
      if type(item) is File:
        if item['filename'] == filename:
          return (True, item)
    return (False, None)
  except requests.exceptions.RequestException:
    logger.die('Network error, please check network status and try again')
예제 #11
0
파일: share.py 프로젝트: Naveengnn/one
def get_existance(filename):
    client = c.get_client()
    try:
        contents = client.get_folder_contents_iter('mf:/one_storage/')
        for item in contents:
            if type(item) is File:
                if item['filename'] == filename:
                    return (True, item)
        return (False, None)
    except requests.exceptions.RequestException:
        logger.die('Network error, please check network status and try again')
예제 #12
0
def main():
    parser = build_arg_parser()

    args = parser.parse_args()
    if (args.sub_command == 'push'):
        if (len(args.files) == 0):
            logger.die('Must include at least one file')
        else:
            for f in args.files:
                upload.upload(f, args.MediaFire_Path)
    elif (args.sub_command == 'pull'):
        if (len(args.files) == 0):
            logger.die('Must include at least one file')
        else:
            for f in args.files:
                download.download(f)
    elif (args.sub_command == 'del'):
        if (len(args.files) == 0):
            logger.die('Must include at least one file')
        else:
            for f in args.files:
                delete.delete(f)
    elif (args.sub_command == 'init'):
        if (user.is_user_signed_in()):
            logger.end('User is already initialized')
        else:
            user.get_auth()
    elif (args.sub_command == 'list'):
        if (len(args.files) == 0):
            lister.list_files('')
        else:
            for f in args.files:
                lister.list_files(f)
    elif (args.sub_command == 'diff'):
        if (len(args.files) == 0):
            logger.die('Must include at least one file')
        else:
            for f in args.files:
                diff.diff(f, args.MediaFire_Path)

    elif (args.sub_command == 'out'):
        user.log_out()
    elif (args.sub_command == 'change'):
        user.change_user()
    elif (args.sub_command == 'share'):
        if (len(args.files) == 0):
            logger.die('Must include at least on file')
        else:
            for f in args.files:
                share.share(f)
예제 #13
0
파일: upload.py 프로젝트: Naveengnn/one
def upload(path, remote_path=''):
  '''upload a file with the directory path "path"'''
  if (user.is_user_signed_in()):
    remote_path = sanitize_path(remote_path)
    full_path_expansion = get_path_expansion(path)
    file_name = os.path.basename(full_path_expansion)
    if (os.path.isfile(full_path_expansion)):
        
      client = c.get_client() 
      if (check_existance(file_name, remote_path, client)):
        logger.die('File with name "' + file_name + '" already exists')
      else:
        try:
          client.upload_file(full_path_expansion, 'mf:' + remote_path + '/')
          #updated_hash = get_hash(full_path_expansion, client)
          #xattr.setxattr(f, 'hash', binascii.a2b_qp(updated_hash))
          logger.log('File "' + file_name + '" has been succesfully uploaded.')
        except ResourceNotFoundError:
          Logger.die('Path "' + remote_path + '" not found.')
        except requests.exceptions.RequestException:
          logger.die('Network error, please check network status and try again')

    elif (os.path.isdir(full_path_expansion)):
      logger.die('File, "' + full_path_expansion + '", is a directory')
    else:
      logger.die('No such file or directory')
  else:
    user.get_auth()
예제 #14
0
파일: download.py 프로젝트: cdpetty/one
def download(file_path):
  '''Download the file by name of "file_path"'''
  if (user.is_user_signed_in()):
    client = c.get_client()
    filename = os.path.basename(file_path)
    file_path = sanitize_path(file_path)
    if (os.path.isfile(filename) or os.path.isdir(filename)):
      logger.die('File or dir with name "' + filename + '" in current directory')
    else:
      existance = check_existance(file_path, client)
      if (existance[0]):
        try:
          client.download_file("mf:" + file_path , '.')
          file_info = existance[1]
          xattr.setxattr(filename, 'hash', binascii.a2b_qp(file_info['hash']))
          logger.log('File "' + filename + '" downloaded successfully.')
        except NotAFolderError:
          logger.die('Path "' + remote_path + '" not found on MediaFire')
        except ResourceNotFoundError:
          logger.die('Path "' + remote_path + '" not found on MediaFire.')
        except requests.exceptions.RequestException:
          logger.die('Network error, please check network status and try again')

      else:
        logger.log('File path and name "' + file_path + '" does not exist.')
  else:
    user.get_auth()
예제 #15
0
파일: one.py 프로젝트: cdpetty/one
def main():
  parser = build_arg_parser()

  args = parser.parse_args()
  if (args.sub_command == 'push'):
    if (len(args.files) == 0):
      logger.die('Must include at least one file')
    else:
      for f in args.files:
        upload.upload(f, args.MediaFire_Path) 
  elif (args.sub_command == 'pull'):
    if (len(args.files) == 0):
      logger.die('Must include at least one file')
    else:
      for f in args.files:
        download.download(f)
  elif (args.sub_command == 'del'):
    if (len(args.files) == 0):
      logger.die('Must include at least one file')
    else:
      for f in args.files:
          delete.delete(f)
  elif (args.sub_command == 'init'):
    if (user.is_user_signed_in()):
      logger.end('User is already initialized')
    else:
      user.get_auth()
  elif (args.sub_command == 'list'):
    if (len(args.files) == 0):
      lister.list_files('')
    else:
      for f in args.files:
        lister.list_files(f)
  elif (args.sub_command == 'diff'):
    if (len(args.files) == 0):
      logger.die('Must include at least one file')
    else:
        for f in args.files:
          diff.diff(f, args.MediaFire_Path)
        
  elif (args.sub_command == 'out'):
    user.log_out()
  elif (args.sub_command == 'change'):
    user.change_user()
  elif (args.sub_command == 'share'):
    if (len(args.files) == 0):
      logger.die('Must include at least on file')
    else:
      for f in args.files:
        share.share(f)
예제 #16
0
파일: diff.py 프로젝트: Naveengnn/one
def get_hash(mf_path):
    try:
        client = c.get_client()
        path = os.path.dirname(mf_path)
        if path == '/':
            path = ''
        contents = client.get_folder_contents_iter('mf:' + path + '/')
        for item in contents:
            if type(item) is File:
                if (item['filename'] == os.path.basename(mf_path)):
                    return item['hash']
        return ''
    except requests.exceptions.RequestException:
        logger.die('Network error, please check network status and try again')
예제 #17
0
def download(file_path):
    '''Download the file by name of "file_path"'''
    if (user.is_user_signed_in()):
        client = c.get_client()
        filename = os.path.basename(file_path)
        file_path = sanitize_path(file_path)
        if (os.path.isfile(filename) or os.path.isdir(filename)):
            logger.die('File or dir with name "' + filename +
                       '" in current directory')
        else:
            existance = check_existance(file_path, client)
            if (existance[0]):
                try:
                    client.download_file("mf:" + file_path, '.')
                    file_info = existance[1]
                    xattr.setxattr(filename, 'hash',
                                   binascii.a2b_qp(file_info['hash']))
                    logger.log('File "' + filename +
                               '" downloaded successfully.')
                except NotAFolderError:
                    logger.die('Path "' + remote_path +
                               '" not found on MediaFire')
                except ResourceNotFoundError:
                    logger.die('Path "' + remote_path +
                               '" not found on MediaFire.')
                except requests.exceptions.RequestException:
                    logger.die(
                        'Network error, please check network status and try again'
                    )

            else:
                logger.log('File path and name "' + file_path +
                           '" does not exist.')
    else:
        user.get_auth()
예제 #18
0
파일: diff.py 프로젝트: cdpetty/one
def get_hash(mf_path):
  try:
    client = c.get_client()  
    path = os.path.dirname(mf_path)
    if path == '/':
      path = ''
    contents = client.get_folder_contents_iter('mf:' + path + '/')
    for item in contents:
      if type(item) is File:
        if (item['filename'] == os.path.basename(mf_path)):
          return item['hash']
    return ''
  except requests.exceptions.RequestException:
    logger.die('Network error, please check network status and try again')
예제 #19
0
파일: delete.py 프로젝트: cdpetty/one
def delete(file_path):
  '''Deletes file with name "filename" from
  MediaFire account.'''
  if (user.is_user_signed_in()):
    client = c.get_client()
    file_path = sanitize_path(file_path)
    if (check_existance(file_path, client)):
      try: 
        client.delete_file('mf:' + file_path)
        logger.log('File "' + os.path.basename(file_path) + '" successfully deleted.')
      except requests.exceptions.RequestException:
        logger.die('Network error, please check network status and try again')
    else:
      logger.die('File with path and name "' + file_path + '" does not exist.')
  else:
    user.get_auth()
예제 #20
0
파일: delete.py 프로젝트: Naveengnn/one
def delete(file_path):
    '''Deletes file with name "filename" from
  MediaFire account.'''
    if (user.is_user_signed_in()):
        client = c.get_client()
        file_path = sanitize_path(file_path)
        if (check_existance(file_path, client)):
            try:
                client.delete_file('mf:' + file_path)
                logger.log('File "' + os.path.basename(file_path) +
                           '" successfully deleted.')
            except requests.exceptions.RequestException:
                logger.die(
                    'Network error, please check network status and try again')
        else:
            logger.die('File with path and name "' + file_path +
                       '" does not exist.')
    else:
        user.get_auth()
예제 #21
0
파일: client.py 프로젝트: Naveengnn/one
def get_client(*info):
    ''' returns a mediafireapi.client object
  @email as first parameter
  @password as second parameter
  if no params are passed, then get_client
  pulls the account information from the user's
  saved credentials with the user file'''

    # Create Mediafire client
    try:
        client = MediaFireClient()
    except requests.exceptions.RequestException:
        logger.die('Network error, please check network status and try again')
    if (len(info) == 2):
        try:
            client.login(email=info[0],
                         password=info[1],
                         app_id=APP_ID,
                         api_key=API_KEY)
        except requests.exceptions.RequestException:
            logger.die(
                'Network error, please check network status and try again')
    else:
        try:
            auth = user.get_auth()
            client.login(email=auth[0],
                         password=auth[1],
                         app_id=APP_ID,
                         api_key=API_KEY)
        except requests.exceptions.RequestException:
            logger.die(
                'Network error, please check network status and try again')
    return client
예제 #22
0
파일: client.py 프로젝트: cdpetty/one
def get_client(*info):
  ''' returns a mediafireapi.client object
  @email as first parameter
  @password as second parameter
  if no params are passed, then get_client
  pulls the account information from the user's
  saved credentials with the user file'''

  # Create Mediafire client
  try:
    client = MediaFireClient()
  except requests.exceptions.RequestException:
    logger.die('Network error, please check network status and try again')
  if (len(info) == 2):
    try:
      client.login(email=info[0],
          password=info[1],
          app_id=APP_ID,
          api_key=API_KEY)
    except requests.exceptions.RequestException:
     logger.die('Network error, please check network status and try again') 
  else:
    try:
      auth = user.get_auth()
      client.login(email=auth[0],
          password=auth[1],
          app_id=APP_ID,
          api_key=API_KEY)
    except requests.exceptions.RequestException:
      logger.die('Network error, please check network status and try again')
  return client
예제 #23
0
파일: delete.py 프로젝트: cdpetty/one
def check_existance(file_path, client):
  try:
    contents = client.get_folder_contents_iter('mf:' + os.path.dirname(file_path) + '/')
    for item in contents:
      if type(item) is File:
        if item['filename'] == os.path.basename(file_path):
          return True
    return False
  except requests.exceptions.RequestException:
    logger.die('Network error, please check network status and try again')
  except NotAFolderError:
    logger.die('Path "' + file_path + '" not found on MediaFire')
  except ResourceNotFoundError:
    logger.die('Path "' + file_path + '" not found on MediaFire.')
예제 #24
0
파일: upload.py 프로젝트: Naveengnn/one
def check_existance(filename, remote_path, client):
  try:
    contents = client.get_folder_contents_iter('mf:' + remote_path)
    for item in contents:
      if type(item) is File:
        if item['filename'] == filename:
          return True
    return False
  except requests.exceptions.RequestException:
    logger.die('Network error, please check network status and try again')
  except NotAFolderError:
    logger.die('Path "' + remote_path + '" not found on MediaFire')
  except ResourceNotFoundError:
    logger.die('Path "' + remote_path + '" not found on MediaFire.')
예제 #25
0
def check_existance(file_path, client):
    try:
        contents = client.get_folder_contents_iter('mf:' +
                                                   os.path.dirname(file_path) +
                                                   '/')
        for item in contents:
            if type(item) is File:
                if item['filename'] == os.path.basename(file_path):
                    return (True, item)
        return (False, None)

    except requests.exceptions.RequestException:
        logger.die('Network error, please check network status and try again')
    except NotAFolderError:
        logger.die('Path "' + file_path + '" not found on MediaFire')
    except ResourceNotFoundError:
        logger.die('Path "' + file_path + '" not found on MediaFire.')