Skip to content

Commit 96de74a

Browse files
committed
Pyserved 2.0.2 Color Update!
1 parent a289d33 commit 96de74a

File tree

11 files changed

+100
-44
lines changed

11 files changed

+100
-44
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
venv
2+
__pycache__
3+
.DS_Store

pyserved/LICENSE.txt renamed to LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 Shaurya Pratap Singh
3+
Copyright (c) 2021 SblipDev.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# PyServed v2.0.1
2-
Made with love by Shaurya Pratap Singh
1+
# PyServed v2.0.2
2+
A beautiful cli made with python which can send files with blazing speed.
33

4+
![pyserved in show](images/example.png)
45
## Installation
56

67
Using pip(for stable releases.) ->
@@ -18,23 +19,37 @@ $ python3 setup.py install
1819

1920
## Usage
2021

21-
Once installed, you can send files across computers.
22+
Once installed, you will be able to send files across computers with the package and python on it.
23+
If there is any problem you can file and issue on this repo.
2224

23-
To send files.
24-
It will ask the file path.
25+
### To listen for files
26+
27+
To send files, you will have to run the following command (The correct output is also shown):
2528

2629
```
27-
$ sndfile
30+
$ pdlisten
31+
32+
[SERVER]: Server is listening on 192.168.1.5:8080
33+
[SERVER]: Waiting for a connection for files...
2834
```
2935

30-
To get files.
36+
To change the default port(8080), add the '-port XXXX' argument to the command and try again.
37+
If someone else conects using the pyserved 'pdsnd' command. It will write the file to the current working directory
38+
39+
### To get files.
40+
41+
To send files, you will have to run the `pdsnd` command. It will prompt for the filepath of the file you want to send.
42+
If everything goes right, the file will be sent to the person listening in the same network.
43+
To change the default port(8080), add the '-port XXXX' argument to the command and try again.
3144

3245
```
33-
$ getfile
34-
```
46+
$ pdsnd
3547
36-
Thats it.
37-
Feel free to contribute.
38-
Have a nice day
48+
[SERVER] : Program Initialized at current directory './'
49+
[SERVER] : Filename:
50+
```
3951

4052

53+
## Thats it.
54+
Feel free to contribute to the package. I personally would really appreciate it.
55+
Have a nice day
File renamed without changes.
File renamed without changes.

images/example.png

66 KB
Loading

pyserved/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
MAJOR UPDATE
88
2.0 -> Bought back cli and added support for ALL codec files.
99
2.0.1 -> Fixed bug with codecs.
10+
2.0.2 -> Added colors! and error messages for when something goes wrong.
1011
1112
Shaurya Pratap Singh 2021
1213
"""
1314

14-
__version__ = '2.0.1'
15+
__version__ = '2.0.2'
1516
__author__ = 'Shaurya Pratap Singh'
16-
__message__ = 'Hail dogecoin! Hail hydra!'
17+
__message__ = "Your time is limited, so don't waste it living someone else's life. Don't be trapped by dogma – which is living with the results of other people's thinking. -Steve Jobs"

pyserved/client.py renamed to pyserved/pdlisten.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
import readline
1818
import os
1919

20-
HEADER = 64
21-
20+
from rich import print
2221

22+
HEADER = 64
2323
class Client:
2424
def __init__(self, server, port):
2525
self.SERVER_HOST = server
2626
self.SERVER_PORT = port
2727
self.BUFFER_SIZE = 1024 * 100000
28-
self.SEPARATOR = "<Order66>"
28+
self.SEPARATOR = "<[(^_^)]>"
2929
self.s = socket.socket()
3030
self.s.bind((self.SERVER_HOST, self.SERVER_PORT))
3131

@@ -78,6 +78,10 @@ def get_internal_ip():
7878
PORT = 8080
7979
ADDR = (SERVER, PORT)
8080

81+
def is_port_in_use() -> bool:
82+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
83+
return s.connect_ex((get_internal_ip(), PORT)) == 0
84+
8185
try:
8286
if sys.argv[1] is None:
8387
pass
@@ -90,19 +94,31 @@ def get_internal_ip():
9094
except IndexError:
9195
pass
9296

97+
if is_port_in_use() is True:
98+
print("[bold red]Port 8080 is already in use in your network. Choose another port instead using the '-port' parameter.[/]")
99+
exit()
100+
93101
try:
94102
client = Client(SERVER, PORT)
95-
print("[SERVER]: Server is running on {}:{}".format(SERVER, PORT))
96-
print("[SERVER]: Waiting for a connection...")
103+
print("[bold green][SERVER]:[/] Server is listening on {}:{}".format(SERVER, PORT))
104+
print("[bold green][SERVER]:[/] Waiting for a connection for files...")
97105
client.listen()
98106
_, address = client.accept()
99-
print("[SERVER] : Connection at {}:{}".format(address[0], address[1]))
100-
print("[SERVER] : Waiting for a file...")
101-
client.receive()
102-
print("[SERVER] : Received file {}.".format(client.filename))
107+
print("[bold green][SERVER]:[/] Connection from {}:{} accepted.".format(address[0], address[1]))
108+
print("[bold green][SERVER]:[/] Reading file data.....")
109+
try:
110+
client.receive()
111+
except ValueError:
112+
print("\n[bold red]An error occured. Please try again in few seconds....[/]")
113+
exit()
114+
print("[bold green][SERVER]:[/] Received file '[bold yellow]{}[/]', saving to current directory.".format(client.filename))
103115
client.write()
104-
print("[SERVER]: File transferred successfully. Closing connection...")
116+
print("[bold green][SERVER]:[/] File transferred successfully. Closing connection...")
105117
client.close()
106118
except KeyboardInterrupt:
107-
print("\n[SERVER]: Keyboard interrupt.")
108-
client.close()
119+
print("\n[bold red]KeyboardInterrupt[/]")
120+
exit()
121+
except:
122+
print("\n[bold red]Something went wrong. If the problem presists, contact the owner of the package at https://github.com/SblipDev/pyserved[/]")
123+
exit()
124+

pyserved/server.py renamed to pyserved/pdsnd.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
| |
44
| pyserved |
55
| |
6-
| Only works with utf-8 |
7-
| files. (for now.) |
8-
| |
96
| By: |
107
| Shaurya Pratap Singh |
118
| 2021 © |
@@ -20,14 +17,16 @@
2017

2118

2219
import socket
23-
import tqdm
2420
import os
25-
import argparse
21+
# import argparse
2622
import readline
2723
import sys
2824

29-
SEPARATOR = "<Order66>"
30-
BUFFER_SIZE = 1024 * 100000 # 4KB
25+
from rich import print
26+
from rich.prompt import Prompt
27+
28+
SEPARATOR = "<[(^_^)]>"
29+
BUFFER_SIZE = 1024 * 100000
3130

3231

3332
def send_file(filename, host, port):
@@ -78,12 +77,18 @@ def get_internal_ip():
7877
FORMAT = 'utf-8'
7978

8079
try:
81-
print("[INFO] : Program Initialized at current directory.")
82-
filename = input('[FILEPATH] : ')
80+
print("[bold green][SERVER][/] : Program Initialized at current directory '{}'".format(SAVE_DIR))
81+
filename = Prompt.ask("[bold green][SERVER][/] : Filename")
8382
send_file(filename, SERVER, PORT)
84-
print("[INFO] : Got file path successfully.")
85-
print(f"[INFO] : Sending {filename} to {SERVER}:{PORT}")
86-
print(f"[INFO] : Sent file. :)")
83+
print("[bold green][SERVER][/] : Got file path successfully.")
84+
print(f"[bold green][SERVER[/] : Sending [bold yellow]{filename}[/] to {SERVER}:{PORT}")
85+
print(f"[bold green][SERVER][/] : Sent file. :)")
8786
except KeyboardInterrupt:
88-
print("\n[QUIT] : Keyboard Interrupt.")
87+
print("\n[bold red]KeyboardInterrupt[/]")
88+
exit()
89+
except ConnectionRefusedError:
90+
print(f"\n[bold red]Connection Refused. Please check the server program.[/]")
91+
exit()
92+
except FileNotFoundError:
93+
print(f"\n[bold red]File '{filename}' does not exist. Please correct the file path and try again[/]")
8994
exit()

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
setup(
55
name="pyserved",
6-
version="2.0.1",
6+
version="2.0.2",
77
description="Share files with your friends (on the same network though)",
88
long_description_content_type="text/markdown",
9-
url="https://github.com/shaurya-blip/pyserved/",
9+
url="https://github.com/SblipDev/pyserved/",
1010
author="Shaurya Pratap Singh",
1111
author_email="shaurya.p.singh21@gmail.com",
1212
license="MIT",
1313
packages=["pyserved"],
14-
install_requires=['tqdm', 'netifaces'],
14+
install_requires=['netifaces', 'rich'],
1515
include_package_data=True,
16-
scripts=['bin/getfile', 'bin/sndfile'],
16+
scripts=['bin/pdlisten', 'bin/pdsnd'],
1717
)

0 commit comments

Comments
 (0)